Files
kong/_examples/shell/main.go
T
Alec Thomas fdc7230e22 Separate validation into a distinct step.
This allows help to be called even when the parse trace is invalid.
Without this, the command-line would have to be valid in order to use
help at all, which defeats the purpose.
2018-05-31 15:20:45 +10:00

35 lines
770 B
Go

package main
import (
"encoding/json"
"fmt"
"os"
"github.com/alecthomas/kong"
)
var CLI struct {
Debug bool `kong:"help='Debug mode.'"`
Output string `kong:"help='File to output to.',placeholder='FILE'"`
Rm struct {
Force bool `kong:"help='Force removal.'"`
Recursive bool `kong:"help='Recursively remove files.'"`
Paths []string `kong:"arg,help='Paths to remove.',type='path'"`
} `kong:"cmd,help='Remove files.'"`
Ls struct {
Paths []string `kong:"help='Paths to list.',type='path'"`
} `kong:"cmd,help='List paths.'"`
}
func main() {
app := kong.Must(&CLI, kong.Description("A shell-like example app."))
cmd, err := app.Parse(os.Args[1:])
app.FatalIfErrorf(err)
s, _ := json.Marshal(&CLI)
fmt.Println(cmd)
fmt.Println(string(s))
}