aboutsummaryrefslogtreecommitdiffstats
path: root/Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
diff options
context:
space:
mode:
Diffstat (limited to 'Godeps/_workspace/src/github.com/codegangsta/cli/flag.go')
-rw-r--r--Godeps/_workspace/src/github.com/codegangsta/cli/flag.go45
1 files changed, 44 insertions, 1 deletions
diff --git a/Godeps/_workspace/src/github.com/codegangsta/cli/flag.go b/Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
index 251158667..531b09130 100644
--- a/Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
+++ b/Godeps/_workspace/src/github.com/codegangsta/cli/flag.go
@@ -99,21 +99,27 @@ func (f GenericFlag) getName() string {
return f.Name
}
+// StringSlice is an opaque type for []string to satisfy flag.Value
type StringSlice []string
+// Set appends the string value to the list of values
func (f *StringSlice) Set(value string) error {
*f = append(*f, value)
return nil
}
+// String returns a readable representation of this value (for usage defaults)
func (f *StringSlice) String() string {
return fmt.Sprintf("%s", *f)
}
+// Value returns the slice of strings set by this flag
func (f *StringSlice) Value() []string {
return *f
}
+// StringSlice is a string flag that can be specified multiple times on the
+// command-line
type StringSliceFlag struct {
Name string
Value *StringSlice
@@ -121,12 +127,14 @@ type StringSliceFlag struct {
EnvVar string
}
+// String returns the usage
func (f StringSliceFlag) String() string {
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
pref := prefixFor(firstName)
return withEnvHint(f.EnvVar, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f StringSliceFlag) Apply(set *flag.FlagSet) {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -144,6 +152,9 @@ func (f StringSliceFlag) Apply(set *flag.FlagSet) {
}
eachName(f.Name, func(name string) {
+ if f.Value == nil {
+ f.Value = &StringSlice{}
+ }
set.Var(f.Value, name, f.Usage)
})
}
@@ -152,10 +163,11 @@ func (f StringSliceFlag) getName() string {
return f.Name
}
+// StringSlice is an opaque type for []int to satisfy flag.Value
type IntSlice []int
+// Set parses the value into an integer and appends it to the list of values
func (f *IntSlice) Set(value string) error {
-
tmp, err := strconv.Atoi(value)
if err != nil {
return err
@@ -165,14 +177,18 @@ func (f *IntSlice) Set(value string) error {
return nil
}
+// String returns a readable representation of this value (for usage defaults)
func (f *IntSlice) String() string {
return fmt.Sprintf("%d", *f)
}
+// Value returns the slice of ints set by this flag
func (f *IntSlice) Value() []int {
return *f
}
+// IntSliceFlag is an int flag that can be specified multiple times on the
+// command-line
type IntSliceFlag struct {
Name string
Value *IntSlice
@@ -180,12 +196,14 @@ type IntSliceFlag struct {
EnvVar string
}
+// String returns the usage
func (f IntSliceFlag) String() string {
firstName := strings.Trim(strings.Split(f.Name, ",")[0], " ")
pref := prefixFor(firstName)
return withEnvHint(f.EnvVar, fmt.Sprintf("%s [%v]\t%v", prefixedNames(f.Name), pref+firstName+" option "+pref+firstName+" option", f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f IntSliceFlag) Apply(set *flag.FlagSet) {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -206,6 +224,9 @@ func (f IntSliceFlag) Apply(set *flag.FlagSet) {
}
eachName(f.Name, func(name string) {
+ if f.Value == nil {
+ f.Value = &IntSlice{}
+ }
set.Var(f.Value, name, f.Usage)
})
}
@@ -214,16 +235,19 @@ func (f IntSliceFlag) getName() string {
return f.Name
}
+// BoolFlag is a switch that defaults to false
type BoolFlag struct {
Name string
Usage string
EnvVar string
}
+// String returns a readable representation of this value (for usage defaults)
func (f BoolFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f BoolFlag) Apply(set *flag.FlagSet) {
val := false
if f.EnvVar != "" {
@@ -248,16 +272,20 @@ func (f BoolFlag) getName() string {
return f.Name
}
+// BoolTFlag this represents a boolean flag that is true by default, but can
+// still be set to false by --some-flag=false
type BoolTFlag struct {
Name string
Usage string
EnvVar string
}
+// String returns a readable representation of this value (for usage defaults)
func (f BoolTFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s\t%v", prefixedNames(f.Name), f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f BoolTFlag) Apply(set *flag.FlagSet) {
val := true
if f.EnvVar != "" {
@@ -282,6 +310,7 @@ func (f BoolTFlag) getName() string {
return f.Name
}
+// StringFlag represents a flag that takes as string value
type StringFlag struct {
Name string
Value string
@@ -289,6 +318,7 @@ type StringFlag struct {
EnvVar string
}
+// String returns the usage
func (f StringFlag) String() string {
var fmtString string
fmtString = "%s %v\t%v"
@@ -302,6 +332,7 @@ func (f StringFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf(fmtString, prefixedNames(f.Name), f.Value, f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f StringFlag) Apply(set *flag.FlagSet) {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -322,6 +353,8 @@ func (f StringFlag) getName() string {
return f.Name
}
+// IntFlag is a flag that takes an integer
+// Errors if the value provided cannot be parsed
type IntFlag struct {
Name string
Value int
@@ -329,10 +362,12 @@ type IntFlag struct {
EnvVar string
}
+// String returns the usage
func (f IntFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f IntFlag) Apply(set *flag.FlagSet) {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -356,6 +391,8 @@ func (f IntFlag) getName() string {
return f.Name
}
+// DurationFlag is a flag that takes a duration specified in Go's duration
+// format: https://golang.org/pkg/time/#ParseDuration
type DurationFlag struct {
Name string
Value time.Duration
@@ -363,10 +400,12 @@ type DurationFlag struct {
EnvVar string
}
+// String returns a readable representation of this value (for usage defaults)
func (f DurationFlag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f DurationFlag) Apply(set *flag.FlagSet) {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {
@@ -390,6 +429,8 @@ func (f DurationFlag) getName() string {
return f.Name
}
+// Float64Flag is a flag that takes an float value
+// Errors if the value provided cannot be parsed
type Float64Flag struct {
Name string
Value float64
@@ -397,10 +438,12 @@ type Float64Flag struct {
EnvVar string
}
+// String returns the usage
func (f Float64Flag) String() string {
return withEnvHint(f.EnvVar, fmt.Sprintf("%s \"%v\"\t%v", prefixedNames(f.Name), f.Value, f.Usage))
}
+// Apply populates the flag given the flag set and environment
func (f Float64Flag) Apply(set *flag.FlagSet) {
if f.EnvVar != "" {
for _, envVar := range strings.Split(f.EnvVar, ",") {