- Notifications
You must be signed in to change notification settings - Fork0
A simple, fast, and fun package for building command line apps in Go
License
aperturerobotics/cli
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
aperturerobotics/cli
is afork of the popularurfave/cli
v2 package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way, while minimizing dependencies and maximizing compatibility.
Key differences fromurfave/cli
:
- Slim and Reflection-Free:
- Removed
reflect
usage for smaller binaries and better performance. - Tinygo compatible.
- Removed documentation generators.
- Removed altsrc package to focus on CLI handling only.
- Removed
- Stability: Try to maintain backward compatibility as much as possible.
Using this package requires a working Go environment.See the install instructions for Go.
Go Modules are required when using this package.See the go blog guide on using Go Modules.
go get github.com/aperturerobotics/cli
Here's a simple example to get you started:
package mainimport ("fmt""log""os""github.com/aperturerobotics/cli")funcmain() {app:=&cli.App{Name:"greet",Usage:"a simple greeter application",Flags: []cli.Flag{&cli.StringFlag{Name:"name",Value:"world",Usage:"who to greet",EnvVars: []string{"GREET_NAME"},},},// The action for the root command (optional)Action:func(ctx*cli.Context)error {name:=ctx.String("name")fmt.Printf("Hello %s!\n",name)returnnil},// Define subcommandsCommands: []*cli.Command{{Name:"add",Usage:"add a task to the list",// Action for the 'add' subcommandAction:func(ctx*cli.Context)error {fmt.Println("added task: ",ctx.Args().First())returnnil},},{Name:"complete",Usage:"complete a task on the list",// Action for the 'complete' subcommandAction:func(ctx*cli.Context)error {fmt.Println("completed task: ",ctx.Args().First())returnnil},},},}// Run the applicationiferr:=app.Run(os.Args);err!=nil {log.Fatal(err)}}// Try running this:// GREET_NAME=everyone ./greet --name someone add some-task// ./greet complete --help
Running this provides basic command functionality, including help text generation, flag parsing, environment variable handling, and subcommand routing. You can easily add more flags, subcommands, and complex actions.
Full documentation and examples are available in the./docs
directory and online athttps://cli.aperture.app.
This fork retains the original MIT license fromurfave/cli
. SeeLICENSE
.
About
A simple, fast, and fun package for building command line apps in Go
Resources
License
Code of conduct
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Uh oh!
There was an error while loading.Please reload this page.
Languages
- Go99.4%
- Other0.6%