gcli

command module
Version: v0.2.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 13, 2015 License: MIT Imports: 8 Imported by: 0

README

gcli

GitHub release Wercker MIT License Go Documentation

gcli generates a skeleton (codes and its directory structure) you need to start building CLI tool by Golang right out of the box. You can use your favorite CLI framework.

Demo

The following demo shows creating todo CLI application which has add, list and delete command with mitchellh/cli (Which is used for Hashicorp products) with one command.

gif

The next demo shows creating same todo CLI application with design & apply commands. This is the other way to start building new CLI application. First, it starts with creating design file by design command. In this file, you can define, CLI name, description of the CLI , framework you want to use, and commands & flags with its usages. After editing, it executes apply command to generating a project from that design file (The complete video is available on Vimeo).

gif

As you can see, the generated codes are go build-able from beginning.

Usage

To start new command line tool, run the following command. It generates new cli skeleton project. At least, you must provide executable name. You can go build && go test it from beginning.

$ gcli new [options] NAME

To see available frameworks,

$ gcli list

See more usage,

$ gcli help
Design File

You can generate CLI project from design template file (.toml). You can define command name, its description, commands there.

First, you can create default .toml file via design command,

$ gcli design <NAME>

Then, edit design file by your favorite $EDITOR. You can see sample template file sample.toml,

$ $EDITOR <NAME>-design.toml

You can validate design by validate command to check it has required fields,

$ gcli validate <NAME>-design.toml

To generate CLI project, use apply command,

$ gcli apply <NAME>-desigon.toml

Support frameworks

gcli can generate two types of CLI pattern,

Flag pattern

Flag pattern is the pattern which executable has only flag options like below (e.g., grep),

$ grep —i -C 4 "some string" /tmp   
    │     │              │           
    │     │               `--------- Arguments 
    │     │                          
    │      `------------------------ Option flags   
    │                                
     `------------------------------ Executable  

To generate above CLI application with flag fraemwork,

$ cd $GOPATH/src/github.com/YOUR_NAME
$ gcli new -F flag -flag=i:Bool -flag=C:Int grep
  Created grep/main.go
  Created grep/CHANGELOG.md
  Created grep/cli_test.go
  Created grep/README.md
  Created grep/version.go
  Created grep/cli.go
====> Successfully generated grep

gcli supports the following packages for the flag pattern:

Command pattern

Command pattern is the pattern which executable has command for change its behavior. For example, todo CLI application which has add (Add new task), list (List all tasks) and delete(Delete a task) command.

$ todo add 'Buy a milk' 
   │    │      │           
   │    │       `---------- Arguments 
   │    │ 
   │     `----------------- Command 
   │                                  
    `---------------------- Executable

To generate above CLI application with mitchellh/cli framework,

$ cd $GOPATH/src/github.com/YOUR_NAME
$ gcli new -F mitchellh_cli -c add -c list -c delete todo
  Created todo/main.go
  Created todo/command/meta.go
  Created todo/cli.go
  Created todo/CHANGELOG.md
  Created todo/version.go
  Created todo/commands.go
  Created todo/command/add.go
  Created todo/command/list.go
  Created todo/command/delete.go
  Created todo/README.md
  Created todo/command/add_test.go
  Created todo/command/list_test.go
  Created todo/command/delete_test.go
====> Successfully generated todo

gcli supports the following packages for the command pattern:

Installation

To install, use go get and make install. We tag versions so feel free to checkout that tag and compile.

$ go get -d github.com/tcnksm/gcli
$ cd $GOPATH/src/github.com/tcnksm/gcli
$ make install 

Contribution

  1. Fork (https://github.com/tcnksm/gcli/fork)
  2. Create a feature branch
  3. Commit your changes
  4. Rebase your local changes against the master branch
  5. Run test suite with the make test command and confirm that it passes
  6. Run gofmt -s
  7. Create a new Pull Request

Author

Taichi Nakashima

Documentation

Overview

Command gcli generates a skeleon (codes and its directory structure) you need to start building CLI tool by Golang. https://github.com/tcnksm/gcli

Usage:

gcli [-version] [-help]  <command> [<options>]

Available commands:

apply       Apply design template file for generating cli project
design      Generate project design template
list        List available cli frameworks
new         Generate new cli project
validate    Validate design template file

Use "gcli <command> -help" for more information about command.

Apply design template file for generating cli project

Apply design template file for generating cli project. You can generate design template file via 'gcli design' command. If framework name is not specified gcli use codegangsta/cli. You can set framework name via '-F' option. To check cli framework you can use, run 'gcli list'.

Usage:

gcli apply [option] FILE

Options:

-framework=name, -F        Cli framework name. By default, gcli use "codegangsta/cli"
                           To check cli framework you can use, run 'gcli list'.
                           If you set invalid framework, it will be failed.

-skip-test, -T             Skip generating *_test.go file. By default, gcli generates
                           test file If you specify this flag, gcli will not generate
                           test files.

Generate project design template

Generate project design template (as toml file). You can pass that file to 'gcli apply' command and generate CLI tool based on template file. You can define what command and what flag you need on that file.

Usage:

gcli design [option] NAME

Options:

-command=name, -c           Command name which you want to add.
                            This is valid only when cli pacakge support commands.
                            This can be specified multiple times. Synopsis can be
                            set after ":". Namely, you can specify command by
                            -command=NAME:SYNOPSYS. Only NAME is required.
                            You can set multiple variables at same time with ","
                            separator.

-flag=name, -f              Global flag option name which you want to add.
                            This can be specified multiple times. By default, flag type
                            is string and its description is empty. You can set them,
                            with ":" separator. Namaly, you can specify flag by
                            -flag=NAME:TYPE:DESCIRPTION. Order must be flow  this and
                            TYPE must be string, bool or int. Only NAME is required.
                            You can set multiple variables at same time with ","
                            separator.

-framework=name, -F         Cli framework name. By default, gcli use "codegangsta/cli"
                            To check cli framework you can use, run 'gcli list'.
                            If you set invalid framework, it will be failed.

-owner=name, -o             Command owner (author) name. This value is also used for
                            import path name. By default, owner name is extracted from
                            ~/.gitconfig variable.

-output, -O                 Change output file name. By default, gcli use "NAME-design.toml"

List available cli frameworks

Show all avairable cli frameworks.

Usage:

gcli list

Generate new cli project

Generate new cli skeleton project. At least, you must provide executable name. You can select cli package and set commands via command line option. See more about that on Options section. By default, gcli use codegangsta/cli. To check cli framework you can use, run 'gcli list'.

Usage:

gcli new [option] NAME

Options:

-command=name, -c           Command name which you want to add.
                            This is valid only when cli pacakge support commands.
                            This can be specified multiple times. Synopsis can be
                            set after ":". Namely, you can specify command by
                            -command=NAME:SYNOPSYS. Only NAME is required.
                            You can set multiple variables at same time with ","
                            separator.

-flag=name, -f              Global flag option name which you want to add.
                            This can be specified multiple times. By default, flag type
                            is string and its description is empty. You can set them,
                            with ":" separator. Namaly, you can specify flag by
                            -flag=NAME:TYPE:DESCIRPTION. Order must be flow  this and
                            TYPE must be string, bool or int. Only NAME is required.
                            You can set multiple variables at same time with ","
                            separator.

 -framework=name, -F        Cli framework name. By default, gcli use "codegangsta/cli"
                            To check cli framework you can use, run 'gcli list'.
                            If you set invalid framework, it will be failed.

 -owner=name, -o            Command owner (author) name. This value is also used for
                            import path name. By default, owner name is extracted from
                            ~/.gitconfig variable.

 -skip-test, -T             Skip generating *_test.go file. By default, gcli generates
                            test file If you specify this flag, gcli will not generate
                            test files.

Examples:

To create todo command application skeleton which has 'add' and 'delete' command,

$ gcli new -command=add:"Add new task" -commnad=delete:"delete task" todo

Validate design template file

Validate design template file which has required filed. If not it returns error and non zero value.

Usage:

gcli validate FILE

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL