Giter Club home page Giter Club logo

cli's Introduction


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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.