summaryrefslogtreecommitdiff
path: root/command.go
diff options
context:
space:
mode:
authorEyal Posener <[email protected]>2017-05-05 21:57:21 +0300
committerEyal Posener <[email protected]>2017-05-05 21:57:21 +0300
commit5e07cbd4c20a5a3bb5bc84148dc4d4ebffa3d033 (patch)
tree14562796afbc9b220836384339ae80403aa03076 /command.go
parent6311b602abc0f3c0a854c244fca147101b623eba (diff)
Add file completion flag
Diffstat (limited to 'command.go')
-rw-r--r--command.go15
1 files changed, 7 insertions, 8 deletions
diff --git a/command.go b/command.go
index db60c3b..f3321fb 100644
--- a/command.go
+++ b/command.go
@@ -11,7 +11,7 @@ type Command struct {
// options returns all available complete options for the given command
// args are all except the last command line arguments relevant to the command
-func (c *Command) options(args []string) (options []string, only bool) {
+func (c *Command) options(args []string) (options []Option, only bool) {
// remove the first argument, which is the command name
args = args[1:]
@@ -19,7 +19,7 @@ func (c *Command) options(args []string) (options []string, only bool) {
// if prev has something that needs to follow it,
// it is the most relevant completion
if options, ok := c.Flags[last(args)]; ok && options.HasFollow {
- return options.FollowsOptions, true
+ return options.follows(), true
}
sub, options, only := c.searchSub(args)
@@ -35,13 +35,13 @@ func (c *Command) options(args []string) (options []string, only bool) {
// add global available complete options
for flag := range c.Flags {
- options = append(options, flag)
+ options = append(options, Arg(flag))
}
return
}
-func (c *Command) searchSub(args []string) (sub string, all []string, only bool) {
+func (c *Command) searchSub(args []string) (sub string, all []Option, only bool) {
for i, arg := range args {
if cmd, ok := c.Sub[arg]; ok {
sub = arg
@@ -52,11 +52,10 @@ func (c *Command) searchSub(args []string) (sub string, all []string, only bool)
return "", nil, false
}
-func (c *Command) subCommands() []string {
- subs := make([]string, 0, len(c.Sub))
+func (c *Command) subCommands() []Option {
+ subs := make([]Option, 0, len(c.Sub))
for sub := range c.Sub {
- subs = append(subs, sub)
+ subs = append(subs, Arg(sub))
}
return subs
}
-