Simple, useful and opinionated CLI package in Go.

Overview

acmd

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

TODO

Rationale

TODO.

Features

  • Simple API.
  • Easy to integrate.
  • Builtin help and version commands.
  • Clean and tested code.
  • Dependency-free.

Install

Go version 1.17+

go get github.com/cristalhq/acmd

Example

cmds := []acmd.Command{
	{
		Name:        "now",
		Description: "prints current time",
		Do: 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",
		Do: 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 {
	panic(err)
}

Also see examples: examples_test.go.

Documentation

See these docs.

License

MIT License.

Issues
  • Failed with example

    Failed with example

    Tried to make example with acmd, but have no success.

    package main
    
    import (
    	"context"
    	"fmt"
    	"github.com/cristalhq/acmd"
    	"os"
    )
    
    func main() {
    	cmds := []acmd.Command{
    		{
    			Name:        "test",
    			Description: "test cmd",
    			Do: func(ctx context.Context, args []string) error {
    				fmt.Println("test")
    				return nil
    			},
    		},
    	}
    
    	r := acmd.RunnerOf(cmds, acmd.Config{
    		AppName:        "test",
    		AppDescription: "Test example",
    		Version:        "v0.0.1",
    		Output: os.Stdout,
    		Args: os.Args,
    	})
    
    	if err := r.Run(); err != nil {
    		panic(err)
    	}
    
    }
    

    Build with go build main.go. All attempts to exec the command are failed with panic panic: acmd: cannot run command: no such command "./main".

    question 
    opened by lesovsky 1
  • Support to `<context>:<command>` style

    Support to `:` style

    Hey, it's just a suggestion which I can contribute on to create it

    Particularly, I like a lot heroku's command style <context>:<command> and I looked at that acmd doens't has support to put : as caracter in a command. What do you think about starting to accept : caracter to contemple this suggestion?

    🎈 I know that already exists support to put subcommand (congrats for this) but I would like to support <context>:<command> as command for example app:create or user:delete

    opened by guiferpa 0
Releases(v0.5.7)
  • v0.5.7(Mar 3, 2022)

  • v0.5.6(Feb 3, 2022)

    6200af042a8a8971f51722dd70b7de275b74939a Fix test after a PR (#23) 0c750fb547c4e526473696961cd2ec3a2b6c88a0 Remove command error wrapping (#22) 3ffa7db98ab1df45d95a27620b1ff803300964e1 Update GUIDE.md (#20)

    Source code(tar.gz)
    Source code(zip)
  • v0.5.5(Jan 30, 2022)

    096b5333b2dafbffccc209863fc1fc49f8b475da Common flags example (#19) e51f45c1865e4f708895f72889407cc06a8c511b GUIDE.md: Add command and file format in example (#17) 37ccb3e553b723690a7fcf5ac262d7c416c2d2cc Add GUIDE.md (#16)

    Source code(tar.gz)
    Source code(zip)
  • v0.5.4(Jan 27, 2022)

    23e7558904bb24966f1c459a4a5d1817a032afea [BREAKING CHANGE] Use Stdout (#14) ad99142d45c74ae26cdbab06325dbd5de004f917 Fix typo (#15) 51581fdb720ce85085c411d80ba4c7483c7058cc Fix init and Exit (#13) 5fb1c5612c5012200cce88d45cac647587feac52 Test subcommands sort (#12) 3cfaf46b90e754240032202bc4984762e859aea9 Better args handling (#11)

    Source code(tar.gz)
    Source code(zip)
  • v0.5.3(Jan 22, 2022)

    c041fe49274ada573fe49bf6bff7cd54b88e90d0 Runner exit (#10) 7bc2c58d195c31a9b6cbe03790714bc91d78026b Better CI pipeline e11dd906d0d414f6369e09c03f20fa09adb042c5 Add PostDescription

    Source code(tar.gz)
    Source code(zip)
  • v0.5.2(Jan 5, 2022)

  • v0.5.1(Jan 2, 2022)

  • v0.5.0(Dec 31, 2021)

  • v0.4.1(Dec 19, 2021)

  • v0.4.0(Nov 17, 2021)

    a000865ff0c93ea4029a689ca1e84776c71d7d13 Print help when cmd not found 67d03e7ada75f5b21aa4c77460e1f2f55306773c Update README.md ac9a5ca6d976ab7323232be479e6da173abba9e7 Add flags to example

    Source code(tar.gz)
    Source code(zip)
  • v0.3.0(Nov 3, 2021)

    2cac63508e86c467fc3bcb8f7d1cb2170a84e044 Add nested commands (#2) 97f90a54e490db88c75ec5a1cb915fbf61a60e70 Extract subcommands validation to a func

    Source code(tar.gz)
    Source code(zip)
  • v0.2.0(Nov 1, 2021)

  • v0.1.5(Oct 31, 2021)

    ba9e95ddc3641ec2a493e94437c8ed4dfd3e6b33 Panic if no commands 0a67f267098e164c6bc1a20513e78bff6673bbf2 Add Run doc bd95e2904d57b45b9527323cb81a636381f91719 Add autosuggestion example 5d266160b018e70f23e73c0cd214113a7047dac9 Update README 619eb2510e2b0cf675dfa70a7ce6e5b49364851b Better tests 860ec854c37c5e48482ca3eee6a0b17a6800235f Add doc.go e516865d11aaf4b879689ece7509efe5bc9e5c5b Declare defaultUsage as func 92ba8983aef1c79a20f908f073ee488bfc1a31d0 User private root command da626b4ad432cdde5be9e68745321dbcfcadc1a8 Make run as func 8b7ff3319e3998e8372babed43a3cee918d1b15f Make suggestCommand as func

    Source code(tar.gz)
    Source code(zip)
  • v0.1.2(Oct 30, 2021)

    8a16e7929fa28bf44a9fefb570dfc74290dce4bd Cleanup examples 667f9a78b6bdc1780579b7129890e854782cbd58 Add version example 910d5d7e78702d8a2b0af51a73cb2d71585fb3d1 Add suggestion on cmd not found 656e0f29a15be8b52bbd8675a24f0d1d9342aab7 Be passive-aggressive about description a6e43479f0d53a34110f93f2a9ab6f45475456e5 Add help and version cmds to list of commands 84fb5e2ea86afb579456a920b651ae6592f5ff01 Fix README highlighting d9b2c04d10e61cf04a061493b9b876c92dbfc5c4 Validate and test config a7e55697e1c447aa607347820390fdf3491c2047 Add help example 92936fbc1d1664e2c36c1b99095f5ff663a453dd Cleanup readme example

    Source code(tar.gz)
    Source code(zip)
  • v0.1.1(Oct 28, 2021)

    f51abe113027f9584bea0ed148acc14d90b7e9cf Add example 900399eb28ba9aaf268d8a72c7734f331ea8ab7f Configure output 945cdcaf8e71a5ae7f0288ce7a8271ce2a277dd6 Add newline for version command

    Source code(tar.gz)
    Source code(zip)
Owner
cristaltech
Better open source
cristaltech
Rpfaudio - A small opinionated cli to create Readium Audiobooks from a directory containing mp3 files

rpfaudio A small opinionated cli to create Readium Audiobooks from a directory c

raffaele messuti 1 Feb 18, 2022
miscellaneous useful commands, including 'gosh' the Go scripting tool

utilities Miscellaneous useful commands. gosh This is a tool for running Go code from the command line. See here. findCmpRm This finds files with copi

Nick Wells 23 Jun 15, 2022
Ghissue - This repo contains a github issue parser, that is useful for Enterprise Github accounts.

Ghissue - This repo contains a github issue parser, that is useful for Enterprise Github accounts. Sometimes is needed to parse the content of the issue for some data extraction or statistics purposes.

niloofargheibi 1 Feb 6, 2022
Got: Simple golang package and CLI tool to download large files faster 🏃 than cURL and Wget!

Got. Simple and fast concurrent downloader. Installation ❘ CLI Usage ❘ Module Usage ❘ License Comparison Comparison in cloud server: [[email protected]

Mohamed El Bahja 561 Jun 18, 2022
a lightweight and simple cli package

▄████████ ▄█ ▄█ ███ ███ ███ ███ ███ █▀ ███ ███▌ ███ ███ ███▌ ███ ███ ███▌ ███ █▄ ███

seo.do 12 Oct 14, 2021
cli is a simple, fast, and fun package for building command line apps in Go.

cli cli is a simple, fast, and fun package for building command line apps in Go. The goal is to enable developers to write fast and distributable comm

å‡šč¯­č¨€ 1 Jan 8, 2022
News-parser-cli - Simple CLI which allows you to receive news depending on the parameters passed to it

news-parser-cli Simple CLI which allows you to receive news depending on the par

Maxym 0 Jan 4, 2022
Go-file-downloader-ftctl - A file downloader cli built using golang. Makes use of cobra for building the cli and go concurrent feature to download files.

ftctl This is a file downloader cli written in Golang which uses the concurrent feature of go to download files. The cli is built using cobra. How to

Dipto Chakrabarty 2 Jan 2, 2022
Go-api-cli - Small CLI to fetch data from an API sync and async

Async API Cli CLI to fetch data on "todos" from a given API in a number of ways.

Pete Robinson 0 Jan 13, 2022
Syno-cli - Synology unofficial API CLI and library

Synology CLI Unofficial wrapper over Synology API in Go. Focus on administrative

Aleksandr Baryshnikov 11 Jun 16, 2022
Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Nebula Diagnosis CLI Tool is an information diagnosis cli tool for the nebula service and the node to which the service belongs.

Katz 1 Jan 12, 2022
📇 Go package and CLI tool for listing OUIs.

manuf Go package and CLI tool for listing OUIs. Install $ go install github.com/picatz/[email protected] ... Usage The manuf CLI tool can be used with tool

Kent 'picat' Gruber 2 Feb 7, 2022
Elegant CLI wrapper for kubeseal CLI

Overview This is a wrapper CLI ofkubeseal CLI, specifically the raw mode. If you just need to encrypt your secret on RAW mode, this CLI will be the ea

Elm 4 Jan 8, 2022
CLI to run a docker image with R. CLI built using cobra library in go.

BlueBeak Installation Guide Task 1: Building the CLI The directory structure looks like Fastest process: 1)cd into bbtools 2)cd into bbtools/bin 3)I h

Aniruddha Chattopadhyay 0 Dec 20, 2021
A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode.

aliyun-dns A wrapper of aliyun-cli subcommand alidns, run aliyun-cli in Declarative mode. Installation Install aliyun-cli. Usage $ aliyun-dns -h A wra

čŽ¸å˜‰åŽ 0 Dec 21, 2021
Symfony-cli - The Symfony CLI tool For Golang

Symfony CLI Install To install Symfony CLI, please download the appropriate vers

Symfony CLI 330 Jun 20, 2022
Cli-algorithm - A cli program with A&DS in go!

cli-algorithm Objectives The objective of this cli is to implement 4 basic algorithms to sort arrays been Merge Sort Insertion Sort Bubble Sort Quick

Leonardo Brombilla Antunes 0 Jan 2, 2022
Nebulant-cli - Nebulant's CLI

Nebulant CLI Website: https://nebulant.io Documentation: https://nebulant.io/docs.html The Nebulant CLI tool is a single binary that can be used as a

Develatio 2 Jan 11, 2022