Skip to content

jobala/commando

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

commando

An elegant CLI framework

Getting Started

Installation

To install commando simply do

go get github.com/jobala/commando

Usage

Create a CLI instance

cli := commando.NewCli("animals", "A cli app about the animal kingdom")

Commando exposes a declarative api for grouping commands and adding commands to a command group. The code snippet below adds the following commands;

  1. $animals vertebrates warm mammals bear --loudnes <int>
  2. $animals vertebrates warm mammals cow --loudness <int>
cli.NewCommandGroup("vertebrates warm mammals").
    WithCommand(commando.Command("bear", Bear)).
    WithCommand(commando.Command("cow", Cow)).

func Bear(args BearArgs) {
    // do something with BearArgs and print result
}

type BearArgs struct {
	Loudness int
}

func Cow(args CowArgs) {
    // do something CowArgs and print result
}

type CowArgs struct {
	Loudness int
}

The handler function takes a single struct as an argument and the struct fields will be used to create the command's flags. The fields must be public.

To add another command group under vertebrates, do the following

cli.NewCommandGroup("vertebrates cold").
    WithCommand(commando.Command("snake", Snake))

Now you'll have $animals vertebrates cold ... on top of the initially defined commands

To add another command group under animals, simply do the following

cli.NewCommandGroup("invertebrates").
    WithCommand(commando.Command("leech", handlerFunc)).

The snippet above will add $animals invertebrates leech

You can use --help to show the available commands in a command group. $animals --help will list available sub command[group]s

About

An elegant Go CLI framework

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages