github.com/jduhamel/gcli@v0.2.4-0.20151019142748-0d5307cd7e21/README.md (about)

     1  gcli
     2  ====
     3  
     4  [![GitHub release](http://img.shields.io/github/release/tcnksm/gcli.svg?style=flat-square)][release]
     5  [![Wercker](http://img.shields.io/wercker/ci/5587a34baf7de9c51b02e04b.svg?style=flat-square)][wercker]
     6  [![MIT License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)][license]
     7  [![Go Documentation](http://img.shields.io/badge/go-documentation-blue.svg?style=flat-square)][godocs]
     8  
     9  [release]: https://github.com/tcnksm/gcli/releases
    10  [wercker]: https://app.wercker.com/#applications/5587a34baf7de9c51b02e04b
    11  [license]: https://github.com/tcnksm/gcli/blob/master/LICENSE
    12  [godocs]: http://godoc.org/github.com/tcnksm/gcli
    13  
    14  `gcli` generates a skeleton (codes and its directory structure) you need to start building Command Line Interface (CLI) tool by Golang right out of the box. You can use your favorite [CLI framework](#frameworks).
    15  
    16  ## Why ?
    17  
    18  Why you need `gcli`? Because you should focus on writing core function of CLI, not on interface. During developing CLI tool by Golang, you may find you're writing the chunk of [boilerplate code](https://en.wikipedia.org/wiki/Boilerplate_code) for interfaces. Stop writing the same codes every time. `gcli` generates them and save you a large amount of time by writing such code. This is like [Rails scaffold](http://guides.rubyonrails.org/command_line.html#rails-generate). Not only that, `gcli` know the best practices of golang CLI framework library which you want to use. Generated codes follows the most ideal way of using that framework, and you don't need to know about that. See the [frameworks](#frameworks) it supports now. 
    19  
    20  ## Demo
    21  
    22  The following demo shows creating `todo` CLI application which has `add`, `list` and `delete` command with [mitchellh/cli](https://github.com/mitchellh/cli) (Which is used for [Hashicorp](https://hashicorp.com/) products) with **one command**. As you can see, the generated codes are `go build`-able from beginning. 
    23  
    24  ![gif](/doc/gif/gcli-new.gif)
    25  
    26  And this [video](https://vimeo.com/142134929) 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. 
    27  
    28  ## Usage
    29  
    30  `gcli` is single command-line application. This application then takes subcommands. To check the all available commands,
    31  
    32  ```bash
    33  $ gcli help
    34  ```
    35  
    36  To get help for any specific subcommand, run it with the `-h` flag.
    37  
    38  `gcli` has 2 main subcommand to generate the project. The one is the `new` command, the other is the `design` & `apply` commands. The former is for generating the project by command line one-liner, the latter is for when you want to design it in your editor before generating (It generates design file and you can generate project based on it). The following section explain, how to use these commands.
    39  
    40  ### `new` command
    41  
    42  The `new` command tells gcli to generate CLI project with command-line one-liner,
    43  
    44  ```bash
    45  $ gcli new [options] NAME
    46  ```
    47  You must provides project name (`NAME`), the name will be the directory name it includes all codes and be the default binary name. In option, you can set subcommand or flag it has and its description. You can alos set your favorite [CLI framework](#frameworks) there. The followings are all available opntions,
    48  
    49  ```bash
    50  -command=name, -c           Command name which you want to add.
    51                              This is valid only when cli pacakge support commands.
    52                              This can be specified multiple times. Synopsis can be
    53                              set after ":". Namely, you can specify command by
    54                              -command=NAME:SYNOPSYS. Only NAME is required.
    55                              You can set multiple variables at same time with ","
    56                              separator.
    57  
    58  -flag=name, -f              Global flag option name which you want to add.
    59                              This can be specified multiple times. By default, flag type
    60                              is string and its description is empty. You can set them,
    61                              with ":" separator. Namaly, you can specify flag by
    62                              -flag=NAME:TYPE:DESCIRPTION. Order must be flow  this and
    63                              TYPE must be string, bool or int. Only NAME is required.
    64                              You can set multiple variables at same time with ","
    65                              separator.
    66  
    67  -framework=name, -F         Cli framework name. By default, gcli use "codegangsta/cli"
    68                              To check cli framework you can use, run 'gcli list'.
    69                              If you set invalid framework, it will be failed.
    70  
    71  -owner=name, -o             Command owner (author) name. This value is also used for
    72                              import path name. By default, owner name is extracted from
    73                              ~/.gitconfig variable.
    74  
    75  -skip-test, -T              Skip generating *_test.go file. By default, gcli generates
    76                              test file If you specify this flag, gcli will not generate
    77                              test files.
    78  ```
    79  
    80  For example, to `todo` CLI application which has `add`, `list` and `delete` command with [mitchellh/cli](https://github.com/mitchellh/cli),
    81  
    82  ```bash
    83  $ gcli new -F mitchellh_cli -c add -c list -c delete todo
    84  ```
    85  
    86  ### `design` & `apply` command
    87  
    88  The `design` command tells gcli to prepare design template file ([`.toml`](https://github.com/toml-lang/toml)). The design file defines all necessary information to generate CLI application. Some fields are filled with the ideal default value, and some have empty value. You can fill that empty filed with your favorite editor with thinking like what interface that should have or description of that and so on. You can see sample template file [`sample.toml`](/sample.toml). 
    89  
    90  After design, use `apply` command and tells gcli to generate CLI project based on the design file. The following describes this workflow. 
    91  
    92  First, generate design template file by `design` command, 
    93  
    94  ```bash
    95  $ gcli design [options] NAME
    96  ```
    97  You must provides project name (`NAME`). In option, you can set subcommand or flag it has and its description. You can alos set your favorite [CLI framework](#frameworks) there. You can edit these values in design file later. 
    98  
    99  Then, edit design file by your favorite `$EDITOR`.
   100  
   101  ```bash
   102  $ $EDITOR <NAME>-design.toml
   103  ```
   104  
   105  After that validate design by `validate` command to check required fields are filled, 
   106  
   107  ```bash
   108  $ gcli validate <NAME>-design.toml
   109  ```
   110  
   111  Finnaly, generate CLI project with that design file by `apply` command, 
   112  
   113  ```bash
   114  $ gcli apply <NAME>-desigon.toml
   115  ```
   116  
   117  The video for this workflow is available on [Vimeo](https://vimeo.com/142134929). 
   118  
   119  ## Frameworks
   120  
   121  There are many framework (package) for buidling command line application by golang. For example, one of the most famous frameworks is [codegangsta/cli](https://github.com/codegangsta/cli). The framework helps you not writing many codes. But still you need to write many boilerplate code for that framework. And there are different way to use that framework and learning the ideal way to use is waste of time. gcli writes out with following the best practice for that framework (learn from famous tool that is built with that framework). 
   122  
   123  `gcli` can generate 2 types of CLI pattern. The one is [*sub-command pattern*](#sub-command), the other is [*flag pattern*](#flag). The former is flexible and you can add many behavior in one command application. The later is for simple application. You can check the all available frameworks by `list` command,
   124  
   125  ```bash
   126  $ gcli list
   127  ```
   128  
   129  To change framework, you can use `-framework` or `-F` option with the framework name. This option can be used for `new`, `design` and `apply` command. By default, [codegangsta_cli](https://github.com/codegangsta/cli) will be used. 
   130  
   131  The following section will explain [*sub-command pattern*](#sub-command) and [*flag pattern*](#flag). 
   132  
   133  ### Sub-Command
   134  
   135  *Sub-Command pattern* is the pattern that executable takes sub-command for change its behavior. `git` command is one example for this pattern. It takes `push`, `pull` subcommands. `gcli` is also this pattern. `gcli` supports the following frameworks for the command pattern.
   136  
   137  |Name|Sample projects|
   138  |:-:|:-:| 
   139  |[codegangsta_cli](https://github.com/codegangsta/cli) | [docker machine](https://github.com/docker/machine) | 
   140  |[mitchellh_cli](https://github.com/mitchellh/cli)| [consul](https://github.com/hashicorp/consul), [terraform](https://github.com/hashicorp/terraform)| 
   141  |[go_cmd](https://github.com/golang/go/blob/master/src/cmd/go/main.go#L30#L51)| [go](https://golang.org/cmd/go/)| 
   142  
   143  ([go_cmd](https://github.com/golang/go/blob/master/src/cmd/go/main.go#L30#L51) is not framework. It only uses standard package. It generates same struct and functions that `go` command uses.)
   144  
   145  ### Flag
   146  
   147  *Flag pattern* is the pattern that executable has flag options for changing its behavior. For example, `grep` command is this pattern. Now `gcli` only supports the official [flag](https://golang.org/pkg/flag/) package for this pattern.
   148  
   149  For example, to create command it has `-ignore-case` option and `context` option (your own `grep`),
   150  
   151  ```bash
   152  $ gcli new -F flag -flag=i:Bool -flag=C:Int grep
   153  ```
   154  
   155  ## Installation
   156  
   157  To install, use `go get` and `make install`. We tag versions so feel free to checkout that tag and compile.
   158  
   159  ```bash
   160  $ go get -d github.com/tcnksm/gcli
   161  $ cd $GOPATH/src/github.com/tcnksm/gcli
   162  $ make install 
   163  ```
   164  
   165  ## Contribution
   166  
   167  1. Fork ([https://github.com/tcnksm/gcli/fork](https://github.com/tcnksm/gcli/fork))
   168  1. Create a feature branch
   169  1. Commit your changes
   170  1. Rebase your local changes against the master branch
   171  1. Run test suite with the `make test` command and confirm that it passes
   172  1. Create a new Pull Request
   173  
   174  ## Author
   175  
   176  [Taichi Nakashima](https://github.com/tcnksm)