Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cristalhq/acmd
Simple, useful and opinionated CLI package in Go.
https://github.com/cristalhq/acmd
cli command-line go golang
Last synced: 30 days ago
JSON representation
Simple, useful and opinionated CLI package in Go.
- Host: GitHub
- URL: https://github.com/cristalhq/acmd
- Owner: cristalhq
- License: mit
- Created: 2021-10-27T15:13:31.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-04-26T21:41:31.000Z (8 months ago)
- Last Synced: 2024-07-31T20:41:24.683Z (4 months ago)
- Topics: cli, command-line, go, golang
- Language: Go
- Homepage:
- Size: 98.6 KB
- Stars: 114
- Watchers: 2
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-go - acmd - Simple, useful, and opinionated CLI package in Go. (Command Line / Standard CLI)
- fucking-awesome-go - acmd - Simple, useful, and opinionated CLI package in Go. (Command Line / Standard CLI)
- awesome-go - acmd - Simple, useful, and opinionated CLI package in Go. (Command Line / Standard CLI)
- awesome-go - acmd - Simple, useful and opinionated CLI package in Go. (Command Line / Standard CLI)
- awesome-go-extra - acmd - 10-27T15:13:31Z|2022-08-24T22:16:54Z| (Build Automation / Standard CLI)
- awesome-go-with-stars - acmd - Simple, useful, and opinionated CLI package in Go. (Command Line / Standard CLI)
- awesome-go-cn - acmd
- awesome-go-plus - acmd - Simple, useful, and opinionated CLI package in Go. ![stars](https://img.shields.io/badge/stars-116-blue) (Command Line / Standard CLI)
- awesome-go-plus - acmd - Simple, useful, and opinionated CLI package in Go. ![stars](https://img.shields.io/badge/stars-116-blue) (Command Line / Standard CLI)
README
# acmd
[![build-img]][build-url]
[![pkg-img]][pkg-url]
[![reportcard-img]][reportcard-url]
[![coverage-img]][coverage-url]
[![version-img]][version-url]Simple, useful and opinionated CLI package in Go. For config loader see [cristalhq/aconfig](https://github.com/cristalhq/aconfig)
## Rationale
Popular CLI libraries (or better frameworks) have too large and unclear API, in most cases, you just want to define commands for your CLI application and run them without additional work. This package does this by providing a small API, good defaults and clear code.
## Features
* Simple API.
* Dependency-free.
* Clean and tested code.
* Command aliases.
* Auto suggesting command.
* Builtin `help` and `version` commands.See [docs][pkg-url] and [GUIDE.md](GUIDE.md) for more details.
## Install
Go version 1.17+
```
go get github.com/cristalhq/acmd
```## Example
```go
cmds := []acmd.Command{
{
Name: "now",
Description: "prints current time",
ExecFunc: func(ctx context.Context, args []string) error {
fmt.Printf("now: %s\n", now.Format("15:04:05"))
return nil
},
},
{
Name: "status",
Description: "prints status of the system",
ExecFunc: func(ctx context.Context, args []string) error {
// do something with ctx :)
return nil
},
},
}// all the acmd.Config fields are optional
r := acmd.RunnerOf(cmds, acmd.Config{
AppName: "acmd-example",
AppDescription: "Example of acmd package",
Version: "the best v0.x.y",
// Context - if nil `signal.Notify` will be used
// Args - if nil `os.Args[1:]` will be used
// Usage - if nil default print will be used
})if err := r.Run(); err != nil {
r.Exit(err)
}
```See examples: [example_test.go](example_test.go).
## License
[MIT License](LICENSE).
[build-img]: https://github.com/cristalhq/acmd/workflows/build/badge.svg
[build-url]: https://github.com/cristalhq/acmd/actions
[pkg-img]: https://pkg.go.dev/badge/cristalhq/acmd
[pkg-url]: https://pkg.go.dev/github.com/cristalhq/acmd
[reportcard-img]: https://goreportcard.com/badge/cristalhq/acmd
[reportcard-url]: https://goreportcard.com/report/cristalhq/acmd
[coverage-img]: https://codecov.io/gh/cristalhq/acmd/branch/main/graph/badge.svg
[coverage-url]: https://codecov.io/gh/cristalhq/acmd
[version-img]: https://img.shields.io/github/v/release/cristalhq/acmd
[version-url]: https://github.com/cristalhq/acmd/releases