Add hook support.
This commit is contained in:
committed by
Gerald Kaszuba
parent
f60fe01f08
commit
cf89213e1e
@@ -3,25 +3,29 @@ package main
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/alecthomas/kong"
|
||||
)
|
||||
|
||||
var CLI struct {
|
||||
Rm struct {
|
||||
Help bool `kong:"help='Display help.'"`
|
||||
Rm struct {
|
||||
Force bool `kong:"help='Force removal.'"`
|
||||
Recursive bool `kong:"help='Recursively remove files.'"`
|
||||
|
||||
Paths []string `kong:"help='Paths to remove.',type='path'"`
|
||||
} `kong:"help='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:"help='List paths.'"`
|
||||
} `kong:"cmd,help='List paths.'"`
|
||||
}
|
||||
|
||||
func main() {
|
||||
cmd := kong.Parse(&CLI)
|
||||
app := kong.Must(&CLI).Hook(&CLI.Help, kong.Help(nil, nil))
|
||||
cmd, err := app.Parse(os.Args[1:])
|
||||
app.FatalIfErrorf(err)
|
||||
s, _ := json.Marshal(&CLI)
|
||||
fmt.Println(cmd)
|
||||
fmt.Println(string(s))
|
||||
|
||||
Reference in New Issue
Block a user