mirror of
https://github.com/minio/minio.git
synced 2025-01-24 05:03:16 -05:00
Merge pull request #108 from fkautz/pr_out_updates_for_cli_and_context
This commit is contained in:
commit
b3af234ee2
6
Godeps/Godeps.json
generated
6
Godeps/Godeps.json
generated
@ -7,12 +7,12 @@
|
|||||||
"Deps": [
|
"Deps": [
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/codegangsta/cli",
|
"ImportPath": "github.com/codegangsta/cli",
|
||||||
"Comment": "1.2.0-26-gf7ebb76",
|
"Comment": "1.2.0-42-gfbda1ce",
|
||||||
"Rev": "f7ebb761e83e21225d1d8954fde853bf8edd46c4"
|
"Rev": "fbda1ce02d5dabcee952040e5f4025753b6c9ce0"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/gorilla/context",
|
"ImportPath": "github.com/gorilla/context",
|
||||||
"Rev": "14f550f51af52180c2eefed15e5fd18d63c0a64a"
|
"Rev": "50c25fb3b2b3b3cc724e9b6ac75fb44b3bccd0da"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/gorilla/mux",
|
"ImportPath": "github.com/gorilla/mux",
|
||||||
|
23
Godeps/_workspace/src/github.com/codegangsta/cli/README.md
generated
vendored
23
Godeps/_workspace/src/github.com/codegangsta/cli/README.md
generated
vendored
@ -68,8 +68,9 @@ Running this already gives you a ton of functionality, plus support for things l
|
|||||||
|
|
||||||
Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
|
Being a programmer can be a lonely job. Thankfully by the power of automation that is not the case! Let's create a greeter app to fend off our demons of loneliness!
|
||||||
|
|
||||||
|
Start by creating a directory named `greet`, and within it, add a file, `greet.go` with the following code in it:
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
/* greet.go */
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -84,7 +85,7 @@ func main() {
|
|||||||
app.Action = func(c *cli.Context) {
|
app.Action = func(c *cli.Context) {
|
||||||
println("Hello friend!")
|
println("Hello friend!")
|
||||||
}
|
}
|
||||||
|
|
||||||
app.Run(os.Args)
|
app.Run(os.Args)
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
@ -171,6 +172,8 @@ app.Flags = []cli.Flag {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
That flag can then be set with `--lang spanish` or `-l spanish`. Note that giving two different forms of the same flag in the same command invocation is an error.
|
||||||
|
|
||||||
#### Values from the Environment
|
#### Values from the Environment
|
||||||
|
|
||||||
You can also have the default value set from the environment via `EnvVar`. e.g.
|
You can also have the default value set from the environment via `EnvVar`. e.g.
|
||||||
@ -186,7 +189,18 @@ app.Flags = []cli.Flag {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
That flag can then be set with `--lang spanish` or `-l spanish`. Note that giving two different forms of the same flag in the same command invocation is an error.
|
The `EnvVar` may also be given as a comma-delimited "cascade", where the first environment variable that resolves is used as the default.
|
||||||
|
|
||||||
|
``` go
|
||||||
|
app.Flags = []cli.Flag {
|
||||||
|
cli.StringFlag{
|
||||||
|
Name: "lang, l",
|
||||||
|
Value: "english",
|
||||||
|
Usage: "language for the greeting",
|
||||||
|
EnvVar: "LEGACY_COMPAT_LANG,APP_LANG,LANG",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### Subcommands
|
### Subcommands
|
||||||
|
|
||||||
@ -282,6 +296,3 @@ Feel free to put up a pull request to fix a bug or maybe add a feature. I will g
|
|||||||
If you are have contributed something significant to the project, I will most likely add you as a collaborator. As a collaborator you are given the ability to merge others pull requests. It is very important that new code does not break existing code, so be careful about what code you do choose to merge. If you have any questions feel free to link @codegangsta to the issue in question and we can review it together.
|
If you are have contributed something significant to the project, I will most likely add you as a collaborator. As a collaborator you are given the ability to merge others pull requests. It is very important that new code does not break existing code, so be careful about what code you do choose to merge. If you have any questions feel free to link @codegangsta to the issue in question and we can review it together.
|
||||||
|
|
||||||
If you feel like you have contributed to the project but have not yet been added as a collaborator, I probably forgot to add you. Hit @codegangsta up over email and we will get it figured out.
|
If you feel like you have contributed to the project but have not yet been added as a collaborator, I probably forgot to add you. Hit @codegangsta up over email and we will get it figured out.
|
||||||
|
|
||||||
## About
|
|
||||||
cli.go is written by none other than the [Code Gangsta](http://codegangsta.io)
|
|
||||||
|
7
Godeps/_workspace/src/github.com/codegangsta/cli/app.go
generated
vendored
7
Godeps/_workspace/src/github.com/codegangsta/cli/app.go
generated
vendored
@ -24,6 +24,8 @@ type App struct {
|
|||||||
EnableBashCompletion bool
|
EnableBashCompletion bool
|
||||||
// Boolean to hide built-in help command
|
// Boolean to hide built-in help command
|
||||||
HideHelp bool
|
HideHelp bool
|
||||||
|
// Boolean to hide built-in version flag
|
||||||
|
HideVersion bool
|
||||||
// An action to execute when the bash-completion flag is set
|
// An action to execute when the bash-completion flag is set
|
||||||
BashComplete func(context *Context)
|
BashComplete func(context *Context)
|
||||||
// An action to execute before any subcommands are run, but after the context is ready
|
// An action to execute before any subcommands are run, but after the context is ready
|
||||||
@ -75,7 +77,10 @@ func (a *App) Run(arguments []string) error {
|
|||||||
if a.EnableBashCompletion {
|
if a.EnableBashCompletion {
|
||||||
a.appendFlag(BashCompletionFlag)
|
a.appendFlag(BashCompletionFlag)
|
||||||
}
|
}
|
||||||
a.appendFlag(VersionFlag)
|
|
||||||
|
if !a.HideVersion {
|
||||||
|
a.appendFlag(VersionFlag)
|
||||||
|
}
|
||||||
|
|
||||||
// parse flags
|
// parse flags
|
||||||
set := flagSet(a.Name, a.Flags)
|
set := flagSet(a.Name, a.Flags)
|
||||||
|
36
Godeps/_workspace/src/github.com/codegangsta/cli/context.go
generated
vendored
36
Godeps/_workspace/src/github.com/codegangsta/cli/context.go
generated
vendored
@ -13,11 +13,12 @@ import (
|
|||||||
// can be used to retrieve context-specific Args and
|
// can be used to retrieve context-specific Args and
|
||||||
// parsed command-line options.
|
// parsed command-line options.
|
||||||
type Context struct {
|
type Context struct {
|
||||||
App *App
|
App *App
|
||||||
Command Command
|
Command Command
|
||||||
flagSet *flag.FlagSet
|
flagSet *flag.FlagSet
|
||||||
globalSet *flag.FlagSet
|
globalSet *flag.FlagSet
|
||||||
setFlags map[string]bool
|
setFlags map[string]bool
|
||||||
|
globalSetFlags map[string]bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Creates a new context. For use in when invoking an App or Command action.
|
// Creates a new context. For use in when invoking an App or Command action.
|
||||||
@ -105,7 +106,7 @@ func (c *Context) GlobalGeneric(name string) interface{} {
|
|||||||
return lookupGeneric(name, c.globalSet)
|
return lookupGeneric(name, c.globalSet)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Determines if the flag was actually set exists
|
// Determines if the flag was actually set
|
||||||
func (c *Context) IsSet(name string) bool {
|
func (c *Context) IsSet(name string) bool {
|
||||||
if c.setFlags == nil {
|
if c.setFlags == nil {
|
||||||
c.setFlags = make(map[string]bool)
|
c.setFlags = make(map[string]bool)
|
||||||
@ -116,6 +117,17 @@ func (c *Context) IsSet(name string) bool {
|
|||||||
return c.setFlags[name] == true
|
return c.setFlags[name] == true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determines if the global flag was actually set
|
||||||
|
func (c *Context) GlobalIsSet(name string) bool {
|
||||||
|
if c.globalSetFlags == nil {
|
||||||
|
c.globalSetFlags = make(map[string]bool)
|
||||||
|
c.globalSet.Visit(func(f *flag.Flag) {
|
||||||
|
c.globalSetFlags[f.Name] = true
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return c.globalSetFlags[name] == true
|
||||||
|
}
|
||||||
|
|
||||||
// Returns a slice of flag names used in this context.
|
// Returns a slice of flag names used in this context.
|
||||||
func (c *Context) FlagNames() (names []string) {
|
func (c *Context) FlagNames() (names []string) {
|
||||||
for _, flag := range c.Command.Flags {
|
for _, flag := range c.Command.Flags {
|
||||||
@ -128,6 +140,18 @@ func (c *Context) FlagNames() (names []string) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns a slice of global flag names used by the app.
|
||||||
|
func (c *Context) GlobalFlagNames() (names []string) {
|
||||||
|
for _, flag := range c.App.Flags {
|
||||||
|
name := strings.Split(flag.getName(), ",")[0]
|
||||||
|
if name == "help" || name == "version" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
names = append(names, name)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
type Args []string
|
type Args []string
|
||||||
|
|
||||||
// Returns the command line arguments associated with the context.
|
// Returns the command line arguments associated with the context.
|
||||||
|
24
Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go
generated
vendored
24
Godeps/_workspace/src/github.com/codegangsta/cli/context_test.go
generated
vendored
@ -69,9 +69,31 @@ func TestContext_IsSet(t *testing.T) {
|
|||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
set.Bool("myflag", false, "doc")
|
set.Bool("myflag", false, "doc")
|
||||||
set.String("otherflag", "hello world", "doc")
|
set.String("otherflag", "hello world", "doc")
|
||||||
c := cli.NewContext(nil, set, set)
|
globalSet := flag.NewFlagSet("test", 0)
|
||||||
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
|
c := cli.NewContext(nil, set, globalSet)
|
||||||
set.Parse([]string{"--myflag", "bat", "baz"})
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
|
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
||||||
expect(t, c.IsSet("myflag"), true)
|
expect(t, c.IsSet("myflag"), true)
|
||||||
expect(t, c.IsSet("otherflag"), false)
|
expect(t, c.IsSet("otherflag"), false)
|
||||||
expect(t, c.IsSet("bogusflag"), false)
|
expect(t, c.IsSet("bogusflag"), false)
|
||||||
|
expect(t, c.IsSet("myflagGlobal"), false)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestContext_GlobalIsSet(t *testing.T) {
|
||||||
|
set := flag.NewFlagSet("test", 0)
|
||||||
|
set.Bool("myflag", false, "doc")
|
||||||
|
set.String("otherflag", "hello world", "doc")
|
||||||
|
globalSet := flag.NewFlagSet("test", 0)
|
||||||
|
globalSet.Bool("myflagGlobal", true, "doc")
|
||||||
|
globalSet.Bool("myflagGlobalUnset", true, "doc")
|
||||||
|
c := cli.NewContext(nil, set, globalSet)
|
||||||
|
set.Parse([]string{"--myflag", "bat", "baz"})
|
||||||
|
globalSet.Parse([]string{"--myflagGlobal", "bat", "baz"})
|
||||||
|
expect(t, c.GlobalIsSet("myflag"), false)
|
||||||
|
expect(t, c.GlobalIsSet("otherflag"), false)
|
||||||
|
expect(t, c.GlobalIsSet("bogusflag"), false)
|
||||||
|
expect(t, c.GlobalIsSet("myflagGlobal"), true)
|
||||||
|
expect(t, c.GlobalIsSet("myflagGlobalUnset"), false)
|
||||||
|
expect(t, c.GlobalIsSet("bogusGlobal"), false)
|
||||||
}
|
}
|
||||||
|
111
Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
generated
vendored
111
Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
generated
vendored
@ -74,8 +74,12 @@ func (f GenericFlag) String() string {
|
|||||||
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
func (f GenericFlag) Apply(set *flag.FlagSet) {
|
||||||
val := f.Value
|
val := f.Value
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
val.Set(envVal)
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
|
val.Set(envVal)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -118,12 +122,17 @@ func (f StringSliceFlag) String() string {
|
|||||||
|
|
||||||
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
newVal := &StringSlice{}
|
envVar = strings.TrimSpace(envVar)
|
||||||
for _, s := range strings.Split(envVal, ",") {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
newVal.Set(s)
|
newVal := &StringSlice{}
|
||||||
|
for _, s := range strings.Split(envVal, ",") {
|
||||||
|
s = strings.TrimSpace(s)
|
||||||
|
newVal.Set(s)
|
||||||
|
}
|
||||||
|
f.Value = newVal
|
||||||
|
break
|
||||||
}
|
}
|
||||||
f.Value = newVal
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,15 +181,20 @@ func (f IntSliceFlag) String() string {
|
|||||||
|
|
||||||
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
newVal := &IntSlice{}
|
envVar = strings.TrimSpace(envVar)
|
||||||
for _, s := range strings.Split(envVal, ",") {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
err := newVal.Set(s)
|
newVal := &IntSlice{}
|
||||||
if err != nil {
|
for _, s := range strings.Split(envVal, ",") {
|
||||||
fmt.Fprintf(os.Stderr, err.Error())
|
s = strings.TrimSpace(s)
|
||||||
|
err := newVal.Set(s)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Fprintf(os.Stderr, err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
f.Value = newVal
|
||||||
|
break
|
||||||
}
|
}
|
||||||
f.Value = newVal
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,10 +220,14 @@ func (f BoolFlag) String() string {
|
|||||||
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
func (f BoolFlag) Apply(set *flag.FlagSet) {
|
||||||
val := false
|
val := false
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envValBool, err := strconv.ParseBool(envVal)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if err == nil {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
val = envValBool
|
envValBool, err := strconv.ParseBool(envVal)
|
||||||
|
if err == nil {
|
||||||
|
val = envValBool
|
||||||
|
}
|
||||||
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -236,10 +254,14 @@ func (f BoolTFlag) String() string {
|
|||||||
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
func (f BoolTFlag) Apply(set *flag.FlagSet) {
|
||||||
val := true
|
val := true
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envValBool, err := strconv.ParseBool(envVal)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if err == nil {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
val = envValBool
|
envValBool, err := strconv.ParseBool(envVal)
|
||||||
|
if err == nil {
|
||||||
|
val = envValBool
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -275,8 +297,12 @@ func (f StringFlag) String() string {
|
|||||||
|
|
||||||
func (f StringFlag) Apply(set *flag.FlagSet) {
|
func (f StringFlag) Apply(set *flag.FlagSet) {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
f.Value = envVal
|
envVar = strings.TrimSpace(envVar)
|
||||||
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
|
f.Value = envVal
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,10 +328,14 @@ func (f IntFlag) String() string {
|
|||||||
|
|
||||||
func (f IntFlag) Apply(set *flag.FlagSet) {
|
func (f IntFlag) Apply(set *flag.FlagSet) {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envValInt, err := strconv.ParseUint(envVal, 10, 64)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if err == nil {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
f.Value = int(envValInt)
|
envValInt, err := strconv.ParseUint(envVal, 10, 64)
|
||||||
|
if err == nil {
|
||||||
|
f.Value = int(envValInt)
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -332,10 +362,14 @@ func (f DurationFlag) String() string {
|
|||||||
|
|
||||||
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
func (f DurationFlag) Apply(set *flag.FlagSet) {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envValDuration, err := time.ParseDuration(envVal)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if err == nil {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
f.Value = envValDuration
|
envValDuration, err := time.ParseDuration(envVal)
|
||||||
|
if err == nil {
|
||||||
|
f.Value = envValDuration
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -362,10 +396,13 @@ func (f Float64Flag) String() string {
|
|||||||
|
|
||||||
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
func (f Float64Flag) Apply(set *flag.FlagSet) {
|
||||||
if f.EnvVar != "" {
|
if f.EnvVar != "" {
|
||||||
if envVal := os.Getenv(f.EnvVar); envVal != "" {
|
for _, envVar := range strings.Split(f.EnvVar, ",") {
|
||||||
envValFloat, err := strconv.ParseFloat(envVal, 10)
|
envVar = strings.TrimSpace(envVar)
|
||||||
if err == nil {
|
if envVal := os.Getenv(envVar); envVal != "" {
|
||||||
f.Value = float64(envValFloat)
|
envValFloat, err := strconv.ParseFloat(envVal, 10)
|
||||||
|
if err == nil {
|
||||||
|
f.Value = float64(envValFloat)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -404,7 +441,7 @@ func prefixedNames(fullName string) (prefixed string) {
|
|||||||
func withEnvHint(envVar, str string) string {
|
func withEnvHint(envVar, str string) string {
|
||||||
envText := ""
|
envText := ""
|
||||||
if envVar != "" {
|
if envVar != "" {
|
||||||
envText = fmt.Sprintf(" [$%s]", envVar)
|
envText = fmt.Sprintf(" [$%s]", strings.Join(strings.Split(envVar, ","), ", $"))
|
||||||
}
|
}
|
||||||
return str + envText
|
return str + envText
|
||||||
}
|
}
|
||||||
|
170
Godeps/_workspace/src/github.com/codegangsta/cli/flag_test.go
generated
vendored
170
Godeps/_workspace/src/github.com/codegangsta/cli/flag_test.go
generated
vendored
@ -54,7 +54,7 @@ func TestStringFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_FOO", "derp")
|
os.Setenv("APP_FOO", "derp")
|
||||||
for _, test := range stringFlagTests {
|
for _, test := range stringFlagTests {
|
||||||
flag := cli.StringFlag{Name: test.name, Value: test.value, EnvVar: "APP_FOO"}
|
flag := cli.StringFlag{Name: test.name, Value: test.value, EnvVar: "APP_FOO"}
|
||||||
@ -106,7 +106,7 @@ func TestStringSliceFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_QWWX", "11,4")
|
os.Setenv("APP_QWWX", "11,4")
|
||||||
for _, test := range stringSliceFlagTests {
|
for _, test := range stringSliceFlagTests {
|
||||||
flag := cli.StringSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_QWWX"}
|
flag := cli.StringSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_QWWX"}
|
||||||
@ -139,7 +139,7 @@ func TestIntFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2")
|
os.Setenv("APP_BAR", "2")
|
||||||
for _, test := range intFlagTests {
|
for _, test := range intFlagTests {
|
||||||
flag := cli.IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := cli.IntFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
@ -172,7 +172,7 @@ func TestDurationFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAR", "2h3m6s")
|
os.Setenv("APP_BAR", "2h3m6s")
|
||||||
for _, test := range durationFlagTests {
|
for _, test := range durationFlagTests {
|
||||||
flag := cli.DurationFlag{Name: test.name, EnvVar: "APP_BAR"}
|
flag := cli.DurationFlag{Name: test.name, EnvVar: "APP_BAR"}
|
||||||
@ -212,7 +212,7 @@ func TestIntSliceFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_SMURF", "42,3")
|
os.Setenv("APP_SMURF", "42,3")
|
||||||
for _, test := range intSliceFlagTests {
|
for _, test := range intSliceFlagTests {
|
||||||
flag := cli.IntSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"}
|
flag := cli.IntSliceFlag{Name: test.name, Value: test.value, EnvVar: "APP_SMURF"}
|
||||||
@ -245,7 +245,7 @@ func TestFloat64FlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_BAZ", "99.4")
|
os.Setenv("APP_BAZ", "99.4")
|
||||||
for _, test := range float64FlagTests {
|
for _, test := range float64FlagTests {
|
||||||
flag := cli.Float64Flag{Name: test.name, EnvVar: "APP_BAZ"}
|
flag := cli.Float64Flag{Name: test.name, EnvVar: "APP_BAZ"}
|
||||||
@ -280,7 +280,7 @@ func TestGenericFlagHelpOutput(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_ZAP", "3")
|
os.Setenv("APP_ZAP", "3")
|
||||||
for _, test := range genericFlagTests {
|
for _, test := range genericFlagTests {
|
||||||
flag := cli.GenericFlag{Name: test.name, EnvVar: "APP_ZAP"}
|
flag := cli.GenericFlag{Name: test.name, EnvVar: "APP_ZAP"}
|
||||||
@ -309,6 +309,7 @@ func TestParseMultiString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiStringFromEnv(t *testing.T) {
|
func TestParseMultiStringFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_COUNT", "20")
|
os.Setenv("APP_COUNT", "20")
|
||||||
(&cli.App{
|
(&cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -325,6 +326,24 @@ func TestParseMultiStringFromEnv(t *testing.T) {
|
|||||||
}).Run([]string{"run"})
|
}).Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiStringFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_COUNT", "20")
|
||||||
|
(&cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringFlag{Name: "count, c", EnvVar: "COMPAT_COUNT,APP_COUNT"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if ctx.String("count") != "20" {
|
||||||
|
t.Errorf("main name not set")
|
||||||
|
}
|
||||||
|
if ctx.String("c") != "20" {
|
||||||
|
t.Errorf("short name not set")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}).Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseMultiStringSlice(t *testing.T) {
|
func TestParseMultiStringSlice(t *testing.T) {
|
||||||
(&cli.App{
|
(&cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -342,6 +361,7 @@ func TestParseMultiStringSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,40")
|
os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
(&cli.App{
|
(&cli.App{
|
||||||
@ -359,6 +379,25 @@ func TestParseMultiStringSliceFromEnv(t *testing.T) {
|
|||||||
}).Run([]string{"run"})
|
}).Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiStringSliceFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
|
(&cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.StringSliceFlag{Name: "intervals, i", Value: &cli.StringSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if !reflect.DeepEqual(ctx.StringSlice("intervals"), []string{"20", "30", "40"}) {
|
||||||
|
t.Errorf("main name not set from env")
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(ctx.StringSlice("i"), []string{"20", "30", "40"}) {
|
||||||
|
t.Errorf("short name not set from env")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}).Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseMultiInt(t *testing.T) {
|
func TestParseMultiInt(t *testing.T) {
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -377,6 +416,7 @@ func TestParseMultiInt(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiIntFromEnv(t *testing.T) {
|
func TestParseMultiIntFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -394,6 +434,25 @@ func TestParseMultiIntFromEnv(t *testing.T) {
|
|||||||
a.Run([]string{"run"})
|
a.Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiIntFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_TIMEOUT_SECONDS", "10")
|
||||||
|
a := cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.IntFlag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if ctx.Int("timeout") != 10 {
|
||||||
|
t.Errorf("main name not set")
|
||||||
|
}
|
||||||
|
if ctx.Int("t") != 10 {
|
||||||
|
t.Errorf("short name not set")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseMultiIntSlice(t *testing.T) {
|
func TestParseMultiIntSlice(t *testing.T) {
|
||||||
(&cli.App{
|
(&cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -411,6 +470,7 @@ func TestParseMultiIntSlice(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_INTERVALS", "20,30,40")
|
os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
(&cli.App{
|
(&cli.App{
|
||||||
@ -428,6 +488,25 @@ func TestParseMultiIntSliceFromEnv(t *testing.T) {
|
|||||||
}).Run([]string{"run"})
|
}).Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_INTERVALS", "20,30,40")
|
||||||
|
|
||||||
|
(&cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.IntSliceFlag{Name: "intervals, i", Value: &cli.IntSlice{}, EnvVar: "COMPAT_INTERVALS,APP_INTERVALS"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if !reflect.DeepEqual(ctx.IntSlice("intervals"), []int{20, 30, 40}) {
|
||||||
|
t.Errorf("main name not set from env")
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(ctx.IntSlice("i"), []int{20, 30, 40}) {
|
||||||
|
t.Errorf("short name not set from env")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}).Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseMultiFloat64(t *testing.T) {
|
func TestParseMultiFloat64(t *testing.T) {
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -446,6 +525,7 @@ func TestParseMultiFloat64(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiFloat64FromEnv(t *testing.T) {
|
func TestParseMultiFloat64FromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -463,6 +543,25 @@ func TestParseMultiFloat64FromEnv(t *testing.T) {
|
|||||||
a.Run([]string{"run"})
|
a.Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_TIMEOUT_SECONDS", "15.5")
|
||||||
|
a := cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.Float64Flag{Name: "timeout, t", EnvVar: "COMPAT_TIMEOUT_SECONDS,APP_TIMEOUT_SECONDS"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if ctx.Float64("timeout") != 15.5 {
|
||||||
|
t.Errorf("main name not set")
|
||||||
|
}
|
||||||
|
if ctx.Float64("t") != 15.5 {
|
||||||
|
t.Errorf("short name not set")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseMultiBool(t *testing.T) {
|
func TestParseMultiBool(t *testing.T) {
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -481,6 +580,7 @@ func TestParseMultiBool(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolFromEnv(t *testing.T) {
|
func TestParseMultiBoolFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "1")
|
os.Setenv("APP_DEBUG", "1")
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -498,6 +598,25 @@ func TestParseMultiBoolFromEnv(t *testing.T) {
|
|||||||
a.Run([]string{"run"})
|
a.Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiBoolFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_DEBUG", "1")
|
||||||
|
a := cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.BoolFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if ctx.Bool("debug") != true {
|
||||||
|
t.Errorf("main name not set from env")
|
||||||
|
}
|
||||||
|
if ctx.Bool("d") != true {
|
||||||
|
t.Errorf("short name not set from env")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolT(t *testing.T) {
|
func TestParseMultiBoolT(t *testing.T) {
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -516,6 +635,7 @@ func TestParseMultiBoolT(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseMultiBoolTFromEnv(t *testing.T) {
|
func TestParseMultiBoolTFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_DEBUG", "0")
|
os.Setenv("APP_DEBUG", "0")
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -533,6 +653,25 @@ func TestParseMultiBoolTFromEnv(t *testing.T) {
|
|||||||
a.Run([]string{"run"})
|
a.Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseMultiBoolTFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_DEBUG", "0")
|
||||||
|
a := cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.BoolTFlag{Name: "debug, d", EnvVar: "COMPAT_DEBUG,APP_DEBUG"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if ctx.BoolT("debug") != false {
|
||||||
|
t.Errorf("main name not set from env")
|
||||||
|
}
|
||||||
|
if ctx.BoolT("d") != false {
|
||||||
|
t.Errorf("short name not set from env")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.Run([]string{"run"})
|
||||||
|
}
|
||||||
|
|
||||||
type Parser [2]string
|
type Parser [2]string
|
||||||
|
|
||||||
func (p *Parser) Set(value string) error {
|
func (p *Parser) Set(value string) error {
|
||||||
@ -569,6 +708,7 @@ func TestParseGeneric(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseGenericFromEnv(t *testing.T) {
|
func TestParseGenericFromEnv(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
os.Setenv("APP_SERVE", "20,30")
|
os.Setenv("APP_SERVE", "20,30")
|
||||||
a := cli.App{
|
a := cli.App{
|
||||||
Flags: []cli.Flag{
|
Flags: []cli.Flag{
|
||||||
@ -585,3 +725,19 @@ func TestParseGenericFromEnv(t *testing.T) {
|
|||||||
}
|
}
|
||||||
a.Run([]string{"run"})
|
a.Run([]string{"run"})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseGenericFromEnvCascade(t *testing.T) {
|
||||||
|
os.Clearenv()
|
||||||
|
os.Setenv("APP_FOO", "99,2000")
|
||||||
|
a := cli.App{
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
cli.GenericFlag{Name: "foos", Value: &Parser{}, EnvVar: "COMPAT_FOO,APP_FOO"},
|
||||||
|
},
|
||||||
|
Action: func(ctx *cli.Context) {
|
||||||
|
if !reflect.DeepEqual(ctx.Generic("foos"), &Parser{"99", "2000"}) {
|
||||||
|
t.Errorf("value not set from env")
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
a.Run([]string{"run"})
|
||||||
|
}
|
||||||
|
2
Godeps/_workspace/src/github.com/codegangsta/cli/help.go
generated
vendored
2
Godeps/_workspace/src/github.com/codegangsta/cli/help.go
generated
vendored
@ -206,7 +206,7 @@ func checkSubcommandHelp(c *Context) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func checkCompletions(c *Context) bool {
|
func checkCompletions(c *Context) bool {
|
||||||
if c.GlobalBool(BashCompletionFlag.Name) && c.App.EnableBashCompletion {
|
if (c.GlobalBool(BashCompletionFlag.Name) || c.Bool(BashCompletionFlag.Name)) && c.App.EnableBashCompletion {
|
||||||
ShowCompletions(c)
|
ShowCompletions(c)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
2
Godeps/_workspace/src/github.com/gorilla/context/context_test.go
generated
vendored
2
Godeps/_workspace/src/github.com/gorilla/context/context_test.go
generated
vendored
@ -98,7 +98,7 @@ func parallelReader(r *http.Request, key string, iterations int, wait, done chan
|
|||||||
func parallelWriter(r *http.Request, key, value string, iterations int, wait, done chan struct{}) {
|
func parallelWriter(r *http.Request, key, value string, iterations int, wait, done chan struct{}) {
|
||||||
<-wait
|
<-wait
|
||||||
for i := 0; i < iterations; i++ {
|
for i := 0; i < iterations; i++ {
|
||||||
Get(r, key)
|
Set(r, key, value)
|
||||||
}
|
}
|
||||||
done <- struct{}{}
|
done <- struct{}{}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user