Popularity
3.2
Growing
Activity
0.0
Stable
48
3
6
Programming language: Go
License: MIT License
Tags:
Command Line
Standard CLI
Latest version: v3.1.0
gocmd alternatives and similar packages
Based on the "Standard CLI" category.
Alternatively, view gocmd alternatives based on common mentions on social networks and blogs.
-
The Platinum Searcher
A code search tool similar to ack and the_silver_searcher(ag). It supports multi platforms and multi encodings. -
readline
A pure golang implementation that provide most of features in GNU-Readline under MIT license. -
mow.cli
A Go library for building CLI applications with sophisticated flag and argument parsing and validation. -
commandeer
Dev-friendly CLI apps: sets up flags, defaults, and usage based on struct fields and tags. -
sflags
Struct based flags generator for flag, urfave/cli, pflag, cobra, kingpin and other libraries. -
Go-Console
GoConsole allows you to create butifull command-line commands with arguments and options. (follow the docopt standard)
Get performance insights in less than 4 minutes
Scout APM uses tracing logic that ties bottlenecks to source code so you know the exact line of code causing performance issues and can get back to building a great product faster.
Sponsored
scoutapm.com
Do you think we are missing an alternative of gocmd or a related project?
Popular Comparisons
README
gocmd
A Go library for building command line applications.
Features
- Advanced command line arguments handling
- Subcommand handling
- Short and long command line arguments
- Multiple arguments (repeated or delimited)
- Support for environment variables
- Well formatted usage printing
- Auto usage and version printing
- Unknown argument handling
- Output tables in the terminal
- Template support for config files
- No external dependency
Installation
go get github.com/devfacet/gocmd
Usage
A basic app
See [basic](examples/basic/main.go) for full code.
func main() {
flags := struct {
Help bool `short:"h" long:"help" description:"Display usage" global:"true"`
Version bool `short:"v" long:"version" description:"Display version"`
VersionEx bool `long:"vv" description:"Display version (extended)"`
Echo struct {
Settings bool `settings:"true" allow-unknown-arg:"true"`
} `command:"echo" description:"Print arguments"`
Math struct {
Sqrt struct {
Number float64 `short:"n" long:"number" required:"true" description:"Number"`
} `command:"sqrt" description:"Calculate square root"`
Pow struct {
Base float64 `short:"b" long:"base" required:"true" description:"Base"`
Exponent float64 `short:"e" long:"exponent" required:"true" description:"Exponent"`
} `command:"pow" description:"Calculate base exponential"`
} `command:"math" description:"Math functions" nonempty:"true"`
}{}
// Echo command
gocmd.HandleFlag("Echo", func(cmd *gocmd.Cmd, args []string) error {
fmt.Printf("%s\n", strings.Join(cmd.FlagArgs("Echo")[1:], " "))
return nil
})
// Math commands
gocmd.HandleFlag("Math.Sqrt", func(cmd *gocmd.Cmd, args []string) error {
fmt.Println(math.Sqrt(flags.Math.Sqrt.Number))
return nil
})
gocmd.HandleFlag("Math.Pow", func(cmd *gocmd.Cmd, args []string) error {
fmt.Println(math.Pow(flags.Math.Pow.Base, flags.Math.Pow.Exponent))
return nil
})
// Init the app
gocmd.New(gocmd.Options{
Name: "basic",
Version: "1.0.0",
Description: "A basic app",
Flags: &flags,
ConfigType: gocmd.ConfigTypeAuto,
})
}
cd examples/basic/
go build .
$ ./basic
Usage: basic [options...] COMMAND [options...]
A basic app
Options:
-h, --help Display usage
-v, --version Display version
--vv Display version (extended)
Commands:
echo Print arguments
math Math functions
sqrt Calculate square root
-n, --number Number
pow Calculate base exponential
-b, --base Base
-e, --exponent Exponent
Build
go build .
Test
./test.sh
Release
git add CHANGELOG.md # update CHANGELOG.md
./release.sh v1.0.0 # replace "v1.0.0" with new version
git ls-remote --tags # check the new tag
Contributing
- Code contributions must be through pull requests
- Run tests, linting and formatting before a pull request
- Pull requests can not be merged without being reviewed
- Use "Issues" for bug reports, feature requests and discussions
- Do not refactor existing code without a discussion
- Do not add a new third party dependency without a discussion
- Use semantic versioning and git tags for versioning
License
Licensed under The MIT License (MIT)
For the full copyright and license information, please view the LICENSE.txt file.
*Note that all licence references and agreements mentioned in the gocmd README section above
are relevant to that project's source code only.