-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
subcommand.go
36 lines (30 loc) · 702 Bytes
/
subcommand.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package zas
import (
"flag"
"strings"
)
/*
* Zas internal subcommand.
*
* Inspired by go command.
*/
type Subcommand struct {
// Runs the subcommand
// The args are the arguments after the subcommand name.
Run func()
// UsageLine is the one-line usage message.
// The first word in the line is taken to be the subcommand name.
UsageLine string
// Name is the name of the subcommand.
Name string
// Flag is a set of flags specific to this command.
Flag flag.FlagSet
}
func NewSubcommand(usageLine string, run func()) *Subcommand {
data := strings.SplitN(usageLine, " ", 2)
return &Subcommand{
UsageLine: usageLine,
Name: strings.ToLower(data[0]),
Run: run,
}
}