Add plural forms for less verbose declarations

This commit is contained in:
Eyal Posener 2017-05-05 18:06:31 +03:00
parent bc26c054b7
commit 6311b602ab
2 changed files with 30 additions and 19 deletions

View File

@ -1,8 +1,12 @@
package complete
type Commands map[string]Command
type Flags map[string]FlagOptions
type Command struct {
Sub map[string]Command
Flags map[string]FlagOptions
Sub Commands
Flags Flags
}
// options returns all available complete options for the given command

View File

@ -4,25 +4,32 @@ import (
"github.com/posener/complete"
)
var completer = complete.New(complete.Command{
Sub: map[string]complete.Command{
"build": {
Flags: map[string]complete.FlagOptions {
"-o": complete.FlagUnknownFollow,
}, "-i": complete.FlagNoFollow,
var (
build = complete.Command{
Flags: complete.Flags{
"-o": complete.FlagUnknownFollow,
"-i": complete.FlagNoFollow,
},
"test": {
Flags: map[string]complete.FlagOptions{
"-run": complete.FlagUnknownFollow,
"-count": complete.FlagUnknownFollow,
},
}
test = complete.Command{
Flags: complete.Flags{
"-run": complete.FlagUnknownFollow,
"-count": complete.FlagUnknownFollow,
},
},
Flags: map[string]complete.FlagOptions{
"-h": complete.FlagNoFollow,
},
})
}
gogo = complete.Command{
Sub: complete.Commands{
"build": build,
"test": test,
},
Flags: complete.Flags{
"-h": complete.FlagNoFollow,
},
}
)
func main() {
completer.Complete()
complete.New(gogo).Complete()
}