• Stars
    star
    115
  • Rank 305,916 (Top 7 %)
  • Language
    Go
  • License
    MIT License
  • Created about 3 years ago
  • Updated 7 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Simple, useful and opinionated CLI package in Go.

acmd

build-img pkg-img reportcard-img coverage-img version-img

Simple, useful and opinionated CLI package in Go. For config loader see 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 and GUIDE.md for more details.

Install

Go version 1.17+

go get github.com/cristalhq/acmd

Example

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.

License

MIT License.

More Repositories

1

jwt

Safe, simple and fast JSON Web Tokens for Go
Go
664
star
2

aconfig

Simple, useful and opinionated config loader.
Go
539
star
3

base64

Faster base64 encoding for Go
Go
180
star
4

hedgedhttp

Hedged HTTP client which helps to reduce tail latency at scale.
Go
119
star
5

builq

Easily build SQL queries in Go.
Go
89
star
6

atomix

Simple and easy wrappers for Go sync/atomic package.
Go
31
star
7

sqlmetrics

Prometheus metrics for Go database/sql via VictoriaMetrics/metrics
Go
24
star
8

synx

Better sync package for Go.
Go
22
star
9

oauth2

OAuth2 client in Go
Go
22
star
10

otp

One time password for Go.
Go
20
star
11

.github

Common stuff across cristalhq organization
Go
18
star
12

redis

WIP. Redis client for Go
Go
16
star
13

sse

Server-Sent Events (SSE) library for Go
Go
11
star
14

pgstats

Postgres statistics for Go
Go
11
star
15

bencode

Bencode encoding and decoding in Go.
Go
10
star
16

pgxutil

Go jackc/pgx helper to write proper transactions
Go
7
star
17

qrcode

QR code for Go.
Go
6
star
18

ipfilterware

Go HTTP middleware to filter clients by IP address
Go
6
star
19

dbump

Go database schema migrator library (See `cristalhq/dbumper` tool)
Go
6
star
20

hedgedgrpc

Hedged Go GRPC client which helps to reduce tail latency at scale.
Go
6
star
21

fastid

Fast ID generator based on timestamp, sequence number and worker id.
Go
5
star
22

httpx

Better net/http for Go
Go
4
star
23

glob

Glob pattern matching in Go.
Go
4
star
24

dbg

Debug helpers for Go
Go
4
star
25

dsvreader

Fast reader for delimiter-separated data
Go
4
star
26

jsn

Go package to easily construct JSON without defined types.
Go
4
star
27

cron

A cron library for Go.
Go
3
star
28

obfid

Obfuscating ID based on modular multiplicative inverse.
Go
3
star
29

dotenv

WIP
Go
3
star
30

errorx

Better `errors` package for Go
Go
3
star
31

benchmarks

Benchmarks for cristalhq and other solutions
Go
3
star
32

ternary

Ternary logic for Go.
Go
3
star
33

fresbi

WIP: Fast Reliable ElasticSearch Bulk Indexer
Makefile
3
star
34

netx

Better net package for Go
Go
3
star
35

bson

BSON for Go
Go
3
star
36

envx

Go environment utils
Go
2
star
37

dbumper

Database schema migrator.
Go
2
star
38

natsort

Natural sorting in Go, see Wikipedia.
Go
2
star
39

timex

Better `time` package for Go
Go
1
star
40

fasthedged

1
star
41

testt

Go
1
star
42

mathx

Go
1
star
43

appx

Go library for building applications. Dramatically simple.
Go
1
star
44

dynconst

Dynamic constants for Go application
Go
1
star
45

paseto

PASETO in Go
Go
1
star
46

lvlbp

Leveled byte pool
Go
1
star
47

feeds

Library for Atom, JSON and RSS feeds creation and parsing.
Go
1
star
48

typex

Type helpers for Go
Go
1
star
49

magneturi

A Go package for magnet links
Go
1
star
50

flagx

Go flag utils
Go
1
star