grim/hgkeeper
Clone
Summary
Browse
Changes
Graph
Convert hgweb from esc to the stdlib embed package
2022-03-07, Gary Kramlich
285592accfa6
Convert hgweb from esc to the stdlib embed package
package
hg
import
(
"github.com/alecthomas/kong"
"github.com/kballard/go-shellquote"
)
type
CommandArguments
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"`
}
func
ParseCommandArguments
(
cmd
string
)
(
string
,
CommandArguments
,
error
)
{
values
:=
CommandArguments
{}
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
ctx
.
Command
(),
values
,
nil
}