grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Add a caching layer to the hgweb portion. This should take some strain off of mercurial anf our cpu quota
2020-04-15, Gary Kramlich
410414a1fbe7
Add a caching layer to the hgweb portion. This should take some strain off of mercurial anf our cpu quota
package
commands
import
(
"fmt"
"github.com/alecthomas/kong"
"github.com/gliderlabs/ssh"
"github.com/kballard/go-shellquote"
)
type
cli
struct
{
Hg
struct
{
Repo
string
`kong:"flag,short='R'"`
Serve
struct
{
Stdio
bool
`kong:"flag,name='stdio'"`
}
`kong:"cmd"`
Init
struct
{
Repo
string
`kong:"arg"`
}
`kong:"cmd"`
}
`kong:"cmd"`
}
type
Command
interface
{
Run
(
session
ssh
.
Session
,
username
string
)
error
}
func
parse
(
cmd
string
)
(
cli
,
string
,
error
)
{
values
:=
cli
{}
args
,
err
:=
shellquote
.
Split
(
cmd
)
if
err
!=
nil
{
return
values
,
""
,
err
}
parser
:=
kong
.
Must
(
&
values
)
ctx
,
err
:=
parser
.
Parse
(
args
)
if
err
!=
nil
{
return
values
,
""
,
err
}
return
values
,
ctx
.
Command
(),
nil
}
func
Find
(
cmd
,
reposPath
string
)
(
Command
,
error
)
{
values
,
pcmd
,
err
:=
parse
(
cmd
)
if
err
!=
nil
{
return
nil
,
err
}
switch
pcmd
{
case
"hg serve"
:
return
NewServe
(
reposPath
,
values
.
Hg
.
Repo
),
nil
case
"hg init <repo>"
:
return
NewInit
(
reposPath
,
values
.
Hg
.
Init
.
Repo
),
nil
default
:
return
nil
,
fmt
.
Errorf
(
"unknown command %s"
,
cmd
)
}
}