diff --git a/command.go b/command.go index 48dece3..db60c3b 100644 --- a/command.go +++ b/command.go @@ -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 diff --git a/gocomplete/complete.go b/gocomplete/complete.go index f680c2a..727e190 100644 --- a/gocomplete/complete.go +++ b/gocomplete/complete.go @@ -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() }