a lightweight and simple cli package

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

a lightweight and simple cli package

Go Reference Go Report Card License: MIT

Contents

Get Started

You can use this command to install the package

go get github.com/teamseodo/cli

A example code for the basics of the cli

package main

import "github.com/teamseodo/cli"

func main() {
    c := cli.NewConfigurator(os.Args[1:])

    mainCommand := cli.NewCommand("app", "app [command] [flags]", "description about the app")
    c.SetMainCommand(mainCommand)

    say := cli.NewCommand("say", "say [flags]", "prints the values")
    mainCommand.AddCommand(say)

    var messageParameter string
    say.AddStringParameter(&cli.Parameter{
        Use: "app print --message [value]",
        Name: "message",
        Shortname: "m",
    }, &messageParameter, "hello world")

    say.Do(func(cmd *cli.Command) {
        fmt.Println(messageParameter)
    })

    help, err := c.FindHelp()
    if err != nil {
        log.Fatal(err)
    }
    help.ShowHelp()

    err := c.Initialize()
    if err != nil {
        log.Fatal(err)
    }
}

Commands

You need to create a configurator to use commands or anything in this package. Configurator takes a main command and you can add sub commands to the main command.

You can create a main command like that,

c := cli.NewConfigurator(os.Args[1:])

mainCommand := cli.NewCommand("app", "app [command] [flags]", "description about the app")
c.SetMainCommand(mainCommand)

Every command can have multiple sub commands, you can add a subcommand like that

hi := cli.NewCommand("hi", "hi", "prints a hello message back")
mainCommand.AddCommand(hi)

Now you will get an structure in command line like that,

app hi

If you want to add a functionality to the command, you can use the command.Do method.

hi.Do(func (cmd *cli.Command) {
    fmt.Println("hi")
})

Initialize the configurator after all things are done

err = c.Initialize()
if err != nil {
	log.Fatal(err)
}

Now when you type app hi, application will print a "hi" message.

You can add a functionality to the main command either, so it will run when no command is received.

Parameters

Every command can take multiple parameters (also known as: flags) You can add three types of parameters, string, int and bool.

AddBoolParameter(parameter *Parameter, value *bool, defaultValue bool) *Parameter

AddIntParameter(parameter *Parameter, value *int, defaultValue int) *Parameter

AddStringParameter(parameter *Parameter, value *string, defaultValue string) *Parameter

If you want to add a string parameter, you can add the parameter like this

var messageParameter string
printCommand.AddStringParameter(&cli.Parameter{
	Use:       "app print --message [value]",
	Name:      "message",
	Shortname: "m",
}, &messageParameter, "hello world")

Help Messages

If you want to print a help message for the command you need to run the FindHelp() method before configurator initialization.

help, err := c.FindHelp()
if err != nil {
	log.Fatal(err)
}
help.ShowHelp()

err = c.Initialize()
if err != nil {
	log.Fatal(err)
}

Contribute

Pull requests are welcome. please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Owner
seo.do
💫 Data science meets SEO.
seo.do
Highly customizable and lightweight Go CLI app framework 👌

Nice ?? Nice is a highly customizable and lightweight framework for crafting CLI apps. Nice respects idiomatic Go code and focuses to be clear, effici

Aleksandr Krivoshchekov 199 May 13, 2022
Show Languages In Code. A fast and lightweight CLI to generate stats on the languages inside your project

slic Show Languages In Code. Usage Run it with an -h flag to list all commands. -d flag can be used to specify the directory of search -i flag can be

Saurav Pal 3 Dec 25, 2021
a lightweight CLI client for interacting with the Akash Network

Akash Command Center A lite weight client for communicating with the Akash Network. There are no provider, or validator bits in this project. Install

Akash Network 12 Feb 12, 2022
Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending

Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending

Jonathan Mataloni 41 Apr 29, 2022
Go package to make lightweight ASCII line graph ╭┈╯ in command line apps with no other dependencies.

asciigraph Go package to make lightweight ASCII line graphs ╭┈╯. Installation go get github.com/guptarohit/asciigraph Usage Basic graph package main

Rohit Gupta 1.9k May 12, 2022
A lightweight replacement for the standard fmt package, reduces binary size by roughly 400kb in a hello world

console This is a lightweight replacement for the fmt package, reduces the binary size by roughly 400kb in a hello world program. Please note: This pa

null 1 Nov 7, 2021
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 550 May 13, 2022
Simple, useful and opinionated CLI package in Go.

acmd TODO Rationale TODO. Features Simple API. Easy to integrate. Builtin help and version commands. Clean and tested code. Dependency-free. Install G

cristaltech 48 May 7, 2022
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
Simple, seamless, lightweight time tracking for Git

Git Time Metric Seamless time tracking for all your Git projects $ gtm report -last-month $ gtm report -last-month -format summary $ gtm report -last-

Git Time Metric 895 Apr 20, 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 8 May 10, 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