From 5e07cbd4c20a5a3bb5bc84148dc4d4ebffa3d033 Mon Sep 17 00:00:00 2001 From: Eyal Posener Date: Fri, 5 May 2017 21:57:21 +0300 Subject: Add file completion flag --- command.go | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'command.go') 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 } - -- cgit v1.2.3