Skip to content

Go package that enable to develop command-line application with subcommand like go more easily

License

Notifications You must be signed in to change notification settings

oirik/gosubcommand

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

gosubcommand

Build Status GoDoc apache license

gosubcommand is a Go package that enable to develop command-line application with subcommand like go more easily.

This is inspired by google/subcommand, and normally you should use google's one.

This could be suitable if you were looking for much simpler one.

Usage

Call Register and Execute like this:

func main() {
	gosubcommand.Register("init", &initCommand{})
	gosubcommand.Register("status", &statusCommand{})
	os.Exit(int(gosubcommand.Execute()))
}

Each subcommand should be implemented like this:

type initCommand struct {
    flagX bool
}

func (init *initCommand) Summary() string {
    return "Init something"
}

func (init *initCommand) SetFlag(fs *flag.FlagSet) {
    fs.BoolVar(&init.flagX, "x", false, "x information")
}

func (init *initCommand) Execute(fs *flag.FlagSet) gosubcommand.ExitCode {
    // Do something
    return gosubcommand.ExitCodeSuccess
}

And your application will be implemented with subcommand like this:

$ yourapp help
yourapp's Summary.

Usage:

  yourapp <command> [arguments]

The commands are:

  init      Init something
  help      Show help information
  version   Show version information

Use "yourapp help <command>" for more information about a command.

GoDoc

https://godoc.org/github.com/oirik/gosubcommand

About

Go package that enable to develop command-line application with subcommand like go more easily

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published