Skip to content

nept/cli

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Build StatusLicense Releases Read me docs Build Status Built with GoLang Platforms



Build command line interfaced applications fast and easy.
Ideally suited for novice Developers.

Quick view

import "github.com/kataras/cli"

func main() {
  cli.NewApp("httpserver", "converts current directory into http server", "0.0.1").
  Flag("directory", "C:/users/myfiles", "specify a directory to convert").
  Run(func(cli.Flags) error {
    return nil
  })
}

Features

  • Simple to use, create a working app in one line
  • Easy API, no need to read any docs, just type cli. via your favorite editor and your hand will select the correct function to do the job
  • Auto command naming alias
  • App has commands, each command can have subcommands, the same commands and their flags can be registered and used over multiple Apps
  • Understands the go types automatically, no more *string
  • Monitor, optionally, each command through App's action listener
  • Help command automation
  • Share app's screen and output with any type of io.Writer

Installation

The only requirement is the Go Programming Language.

$ go get -u github.com/kataras/cli

Getting started

// NewApp creates and returns a new cli App instance
//
// example:
// app := cli.NewApp("iris", "Command line tool for Iris web framework", "0.0.1")
NewApp(name string, description string, version string) *App
package main

import (
	"fmt"
	"github.com/kataras/cli"
)

func main() {
	app := cli.NewApp("httpserver", "converts current directory into http server", "0.0.1")

    // $executable -d, $executable --directory $the_dir
	app.Flag("directory", "C:/users/myfiles", "specify a current working directory")

    //  $executable listen
	listenCommand := cli.Command("listen", "starts the server")

    // $executable listen -h, $executable listen --host $the_host
	listenCommand.Flag("host", "127.0.0.1", "specify an address listener")   
    // $executable listen -p, $executable listen --port $the_port   
	listenCommand.Flag("port", 8080, "specify a port to listen")   
    // $executable listen -d, $executable listen --dir $the_dir     
	listenCommand.Flag("dir", "", "current working directory")    
    // $executable listen -r , $executable listen --req $the_req              
	listenCommand.Flag("req", nil, "a required flag because nil default given")

	listenCommand.Action(listen)

	app.Command(listenCommand) //register the listenCommand to the app.

	app.Run(run)
}

// httpserver -d C:/web/site
func run(args cli.Flags) error {
  // if the app has flags then 'run' will do its job as action, not as monitor
  fmt.Printf("Executing from global app's flag -d/-directory = %s\n ", args.String("directory"))

  // you can also run a command by code, listenCommand.Execute()
  return nil
}

// httpserver listen -h mydomain.com
func listen(args cli.Flags) error {
  fmt.Printf("Executing from command listen with Host: %s and Port: %d \n",
    args.String("host"), args.Int("port"))
  return nil
}

Note that: --help (or -help, help, -h) global flag is automatically used and displays help message.

FAQ

If you'd like to discuss this package, or ask questions about it, feel free to

Versioning

Current: 0.0.4

Read more about Semantic Versioning 2.0.0

People

The author of cli is @kataras.

Contributing

If you are interested in contributing to the cli project, please make a PR.

License

This project is licensed under the MIT License.

License can be found here.

Packages

No packages published

Languages

  • Go 100.0%