Update cli with new changes

This commit is contained in:
Harshavardhana 2015-03-29 13:38:30 -07:00
parent c728798137
commit 5defd8ffdd
5 changed files with 33 additions and 12 deletions

4
Godeps/Godeps.json generated
View File

@ -15,8 +15,8 @@
},
{
"ImportPath": "github.com/minio-io/cli",
"Comment": "1.2.0-96-gfcc23e2",
"Rev": "fcc23e23a705c0d95fce2a446c364ac31a1c73a5"
"Comment": "1.2.0-99-g1ee5c11",
"Rev": "1ee5c115af7856a16f133e2f2d3d9f91895c2ddb"
},
{
"ImportPath": "github.com/minio-io/iodine",

View File

@ -1,10 +1,8 @@
[![Build Status](https://travis-ci.org/codegangsta/cli.png?branch=master)](https://travis-ci.org/codegangsta/cli)
# cli.go
cli.go is simple, fast, and fun 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.
cli.go is simple, fast, and fun 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. - This is a fork of ``github.com/codegangsta/cli`` until our patches get merge upstream
You can view the API docs here:
http://godoc.org/github.com/codegangsta/cli
http://godoc.org/github.com/minio-io/cli
## Overview
Command line apps are usually so tiny that there is absolutely no reason why your code should *not* be self-documenting. Things like generating help text and parsing command flags/options should not hinder productivity when writing a command line app.
@ -16,7 +14,7 @@ Make sure you have a working Go environment (go 1.1 is *required*). [See the ins
To install `cli.go`, simply run:
```
$ go get github.com/codegangsta/cli
$ go get github.com/minio-io/cli
```
Make sure your `PATH` includes to the `$GOPATH/bin` directory so your commands can be easily used:
@ -32,7 +30,7 @@ package main
import (
"os"
"github.com/codegangsta/cli"
"github.com/minio-io/cli"
)
func main() {
@ -47,7 +45,7 @@ package main
import (
"os"
"github.com/codegangsta/cli"
"github.com/minio-io/cli"
)
func main() {
@ -75,7 +73,7 @@ package main
import (
"os"
"github.com/codegangsta/cli"
"github.com/minio-io/cli"
)
func main() {

View File

@ -36,6 +36,8 @@ type Command struct {
SkipFlagParsing bool
// Boolean to hide built-in help command
HideHelp bool
// Boolean to hide this command from help or completion
Hide bool
}
// Invokes the command given the context, parses ctx.Args() to generate command-specific flags
@ -139,6 +141,10 @@ func (c Command) HasName(name string) bool {
return false
}
func (c Command) isNotHidden() bool {
return !c.Hide
}
func (c Command) startApp(ctx *Context) error {
app := NewApp()

View File

@ -27,6 +27,7 @@ var VersionFlag = BoolFlag{
var HelpFlag = BoolFlag{
Name: "help, h",
Usage: "show help",
Hide: true,
}
// Flag is a common interface related to parsing flags in cli.

View File

@ -71,6 +71,7 @@ var helpCommand = Command{
ShowAppHelp(c)
}
},
Hide: true,
}
var helpSubcommand = Command{
@ -85,6 +86,7 @@ var helpSubcommand = Command{
ShowSubcommandHelp(c)
}
},
Hide: true,
}
// Prints help for the App
@ -99,19 +101,27 @@ func ShowAppHelp(c *Context) {
// Make a copy of c.App context
app := *c.App
app.Flags = make([]Flag, 0)
app.Commands = make([]Command, 0)
for _, flag := range c.App.Flags {
if flag.isNotHidden() {
app.Flags = append(app.Flags, flag)
}
}
for _, command := range c.App.Commands {
if command.isNotHidden() {
app.Commands = append(app.Commands, command)
}
}
HelpPrinter(AppHelpTemplate, app)
}
// Prints the list of subcommands as the default app completion method
func DefaultAppComplete(c *Context) {
for _, command := range c.App.Commands {
for _, name := range command.Names() {
fmt.Fprintln(c.App.Writer, name)
if command.isNotHidden() {
for _, name := range command.Names() {
fmt.Fprintln(c.App.Writer, name)
}
}
}
}
@ -123,11 +133,17 @@ func ShowCommandHelp(c *Context, command string) {
// Make a copy of c.App context
app := *c.App
app.Flags = make([]Flag, 0)
app.Commands = make([]Command, 0)
for _, flag := range c.App.Flags {
if flag.isNotHidden() {
app.Flags = append(app.Flags, flag)
}
}
for _, command := range c.App.Commands {
if command.isNotHidden() {
app.Commands = append(app.Commands, command)
}
}
HelpPrinter(SubcommandHelpTemplate, app)
return
}