Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add completion for flags #188

Closed
VarunUmesh opened this issue Mar 3, 2015 · 7 comments · Fixed by #808
Closed

Add completion for flags #188

VarunUmesh opened this issue Mar 3, 2015 · 7 comments · Fixed by #808
Labels
help wanted please help if you can! kind/feature describes a code enhancement / feature request

Comments

@VarunUmesh
Copy link

I am trying to work on the auto-completion part using this framework, and it does not work with the flags option. Here is my piece of code:

package main

import (
"fmt"
"os"

"github.com/codegangsta/cli"

)

func main() {
app := cli.NewApp()
app.Name = "greet"
app.Usage = "sample command-line app by greet"
app.Author = "abc"
app.Email = "xyz@aaa.com"
app.EnableBashCompletion = true
app.Commands = []cli.Command{
{
Name: "read",
ShortName: "r",
Usage: "read something",
Subcommands: []cli.Command{
{
Name: "articles",
Usage: "read articles",
Action: readArticles,
},

            {
                    Name:   "tweets",
                    Usage:  "read Tweets",
                    Flags: []cli.Flag{
                            cli.StringFlag{

Name: "account",
Value: "SomeThing",
Usage: "name of Twitter account",
},
},
Action: readTwitter,
},
},
},
}
app.Run(os.Args)
}

func readArticles(ctx *cli.Context) {
fmt.Println("Go to http://www.google.com to read articles!")
}

func readTwitter(ctx *cli.Context) {
fmt.Printf("Go to https://twitter.com/%s to read tweets!", ctx.String("account"))
}

When i try to do an autocomplete on the flags, it does not work. Could anybody let me know if this is supported by the framework?

Example:

./greet read tweets --a [TAB][TAB] does not work.

@Matt3o12
Copy link

First, please format your code properly (add 4 spaces before pasting it into an issue or use sites like pastebin.org for posting big chunks of code).

Have you check if bash completion works? You can do that by calling gowork-wrapper --generate-bash-completion. If it returns all available commands, you're code is correct, you just haven't sourced the file, yet.
You can source the file like this: PROG=YOU_PROGRAM_NAME source "$GOPATH/src/github.com/codegangsta/cli/autocomplete/bash_autocomplete".

@jszwedko
Copy link
Contributor

@VarunUmesh correct, the autocompletion only works for subcommands, not flags, as noted here: https://github.com/codegangsta/cli#bash-completion

@Matt3o12
Copy link

i think the author means that it should also work for flags since there is no reason for it not to work (at least non I can think of)
If you're concerned about backwards compatibility, you could add the "EnableAutocompleteFlags" field. You could also set it to true by default because it can't think of a case where completing flags could be harmful (even git completes flags).

Sent from my iPhone

On May 10, 2015, at 8:48 PM, Jesse Szwedko notifications@github.com wrote:

@VarunUmesh correct, the autocompletion only works for subcommands, not flags, as noted here: https://github.com/codegangsta/cli#bash-completion


Reply to this email directly or view it on GitHub.

@jszwedko
Copy link
Contributor

Fair enough, I'll re-open as an enhancement.

@jszwedko jszwedko reopened this May 10, 2015
@jszwedko jszwedko added the kind/feature describes a code enhancement / feature request label May 10, 2015
@jszwedko jszwedko changed the title Bash autocomplete for Flags does not work Add completion for flags May 10, 2015
@ngtuna
Copy link

ngtuna commented Aug 16, 2016

Any update on this issue? Is there a way to add completion for flags at this moment ?

@jszwedko
Copy link
Contributor

I haven't had a chance to take a stab at this yet, put PRs are welcome!

@yogeshlonkar
Copy link

Can someone review and merge the changes in #808 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted please help if you can! kind/feature describes a code enhancement / feature request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants