Giter Site home page Giter Site logo

cli's Introduction

cli

GoDoc Go Report Card

cli is a simple package for building command line apps in Go. The goal is to enable developers to write fast and distributable command line applications in an expressive way.

Installation

Using this package requires a working Go environment. See the install instructions for Go.

Go Modules are required when using this package. See the go blog guide on using Go Modules.

$ GO111MODULE=on go get github.com/sedind/cli
...
import (
  "github.com/sedind/cli"
)
...

Usage Documentation

Getting Started

One of the philosophies behind cli is that an API should be playful and full of discovery. So a cli app can be as little as one line of code in main().

package main

import (
  "os"

  "github.com/sedind/cli"
)

func main() {
  cli.New().Run(os.Args)
}

This app will run and show help text, but is not very useful. Let's give an action to execute and some help documentation:

package main

import (
  "fmt"
  "log"
  "os"

  "github.com/sedind/cli"
)

func main() {
  app := cli.New()
  app.Name = "greet"
  app.Description =  "creates greeting message"
  app.Action =  func(c *cli.Context) error {
    fmt.Println("Howdy!")
    return nil
  }
  

  err := app.Run(os.Args)
  if err != nil {
    log.Fatal(err)
  }
}

Install our command to the $GOPATH/bin directory:

$ go install

Finally run our new command:

$ greet
Howdy!

cli also generates neat help text:

$ greet help
creates greeting message

Usage:	build [flags] [args...]
	-help	    h	Prints application help (false)
	-version	v	Prints application version (false)

GOPATH

Make sure your PATH includes the $GOPATH/bin directory so your commands can be easily used:

export PATH=$PATH:$GOPATH/bin

Supported platforms

cli is tested against multiple versions of Go on Linux, and against the latest released version of Go on OS X and Windows.

cli's People

Contributors

sedind avatar

Watchers

James Cloos avatar  avatar

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.