All Projects → teamseodo → cli

teamseodo / cli

Licence: MIT license
a lightweight and simple cli package

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to cli

Wondercms
WonderCMS - fast and small flat file CMS (5 files)
Stars: ✭ 330 (+2650%)
Mutual labels:  lightweight, simple
simple-jwt-provider
No description or website provided.
Stars: ✭ 33 (+175%)
Mutual labels:  lightweight, simple
Qview
Practical and minimal image viewer
Stars: ✭ 460 (+3733.33%)
Mutual labels:  lightweight, simple
tb-grid
tb-grid is a super simple and lightweight 12 column responsive grid system utilizing css grid.
Stars: ✭ 19 (+58.33%)
Mutual labels:  lightweight, simple
CalDOM
An agnostic, reactive & minimalist (3kb) JavaScript UI library with direct access to native DOM.
Stars: ✭ 176 (+1366.67%)
Mutual labels:  lightweight, simple
picamera-motion
Raspberry Pi python PiCamera Lightweight Motion Detection. Includes easy curl script install/upgrade, whiptail admin menu system, single file web server and Rclone for uploading to a variety of web storage services.
Stars: ✭ 80 (+566.67%)
Mutual labels:  lightweight, simple
Htmr
Simple and lightweight (< 2kB) HTML string to React element conversion library
Stars: ✭ 214 (+1683.33%)
Mutual labels:  lightweight, simple
MatrixLib
Lightweight header-only matrix library (C++) for numerical optimization and machine learning. Contact me if there is an exciting opportunity.
Stars: ✭ 35 (+191.67%)
Mutual labels:  lightweight, simple
jpopup
Simple lightweight (<2kB) javascript popup modal plugin
Stars: ✭ 27 (+125%)
Mutual labels:  lightweight, simple
ytmous
Anonymous Youtube Proxy
Stars: ✭ 60 (+400%)
Mutual labels:  lightweight, simple
Bonsai
🌱 a tiny distro-independent package manager
Stars: ✭ 188 (+1466.67%)
Mutual labels:  lightweight, simple
Hexo-Theme-MengD
A simple, lightweight Hexo theme(支持:pjax、discuss、twikoo、waline、valine评论)
Stars: ✭ 69 (+475%)
Mutual labels:  lightweight, simple
hugoblog
Hugoblog is responsive, simple, and clean that would fit for your personal blog based on Hugo Theme Static Site Generator (SSG)
Stars: ✭ 48 (+300%)
Mutual labels:  lightweight, simple
logger
☠ 😈 👀 Simple,Secure & Undetected (6.11.2017) keylogger for Windows :)
Stars: ✭ 37 (+208.33%)
Mutual labels:  lightweight, simple
flagpack
A lightweight flag icon toolkit for the web.
Stars: ✭ 51 (+325%)
Mutual labels:  lightweight, flags
xdecor
A decoration mod for Minetest meant to be light, simple and well-featured
Stars: ✭ 25 (+108.33%)
Mutual labels:  lightweight
mohusman360.github.io
Simple Resume Template with Tailwind CSS
Stars: ✭ 38 (+216.67%)
Mutual labels:  simple
leeks.js
Simple ANSI styling for your terminal
Stars: ✭ 12 (+0%)
Mutual labels:  lightweight
VPAutoComplete
A simple Auto Complete UITextField also support UITableView written in swift 4.2
Stars: ✭ 20 (+66.67%)
Mutual labels:  simple
game-map-editor
game-map-editor
Stars: ✭ 17 (+41.67%)
Mutual labels:  simple
 ▄████████  ▄█        ▄█  
███    ███ ███       ███  
███    █▀  ███       ███▌ 
███        ███       ███▌ 
███        ███       ███▌ 
███    █▄  ███       ███  
███    ███ ███▌    ▄ ███  
████████▀  █████▄▄██ █▀   
           ▀              

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() {
    mainCommand := cli.NewCommand("app", "app [command] [flags]", "description about the app")

    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 := mainCommand.FindHelp(os.Args[1:])
    if err != nil {
        log.Fatal(err)
    }
    help.ShowHelp()

    cmd, err := mainCommand.Parse(os.Args[1:])
    if err != nil {
        log.Fatal(err)
    }

    err = cmd.Run()
    if err != nil {
        cmd.Help().ShowHelp()
    }
}

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,

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

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")
})

Parse the args after all things are done and run the returned command

cmd, err := mainCommand.Parse(os.Args[1:])
if err != nil {
    log.Fatal(err)
}

err = cmd.Run()
if err != nil {
    cmd.Help().ShowHelp()
}

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 := mainCommand.FindHelp(os.Args[1:])
if err != nil {
    log.Fatal(err)
}
help.ShowHelp()

When running the wanted command parsing errors can be occur, so you can make an error check when you run the wanted command and print a help.

err = cmd.Run()
if err != nil {
    cmd.Help().ShowHelp()
}

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].