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

Support for default command when using subcommands #31

Closed
maxekman opened this issue Sep 4, 2013 · 2 comments
Closed

Support for default command when using subcommands #31

maxekman opened this issue Sep 4, 2013 · 2 comments

Comments

@maxekman
Copy link

maxekman commented Sep 4, 2013

This may already be doable..

In my own Python lib called Skal (which does the same thing as this one) inserting the default command in the args before using the library works but is a ugly work around. I tried this in Go also, and it works! But it is still a little unclean:

func main() {
    fmt.Println(os.Args)
    // Make sure to only add "test" if no other subcommand is set..
    os.Args = append(os.Args, "test")
    fmt.Println(os.Args)
}

Would it be possible to set which subcommand (or another command) that will be called when no subcommand is specified?

@codegangsta
Copy link
Contributor

This can be done by setting Action on the cli.App instance. Here is a snippet from the NewApp() function in the source where we set the default action to the help command:

func NewApp() *App {
    return &App{
        Name:    os.Args[0],
        Usage:   "A new cli application",
        Version: "0.0.0",
        Action:  helpCommand.Action,
    }
}

@maxekman
Copy link
Author

maxekman commented Sep 6, 2013

Excellent, didn't think about that!

@maxekman maxekman closed this as completed Sep 6, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants