@ -1,6 +1,7 @@
package cli
import (
"flag"
"fmt"
"os"
"reflect"
@ -20,7 +21,7 @@ var boolFlagTests = []struct {
func TestBoolFlagHelpOutput ( t * testing . T ) {
for _ , test := range boolFlagTests {
flag := BoolFlag { Name : test . name }
flag := & BoolFlag { Name : test . name }
output := flag . String ( )
if output != test . expected {
@ -29,23 +30,35 @@ func TestBoolFlagHelpOutput(t *testing.T) {
}
}
func TestBoolFlagApply_SetsAllNames ( t * testing . T ) {
v := false
fl := BoolFlag { Name : "wat" , Aliases : [ ] string { "W" , "huh" } , Destination : & v }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--wat" , "-W" , "--huh" } )
expect ( t , err , nil )
expect ( t , v , true )
}
var stringFlagTests = [ ] struct {
name string
aliases [ ] string
usage string
value string
expected string
} {
{ "foo" , "" , "" , "--foo value\t" } ,
{ "f" , "" , "" , "-f value\t" } ,
{ "f" , "The total `foo` desired" , "all" , "-f foo\tThe total foo desired (default: \"all\")" } ,
{ "test" , "" , "Something" , "--test value\t(default: \"Something\")" } ,
{ "config,c" , "Load configuration from `FILE`" , "" , "--config FILE, -c FILE\tLoad configuration from FILE" } ,
{ "config ,c", "Load configuration from `CONFIG`" , "config.json" , "--config CONFIG, -c CONFIG\tLoad configuration from CONFIG (default: \"config.json\")" } ,
{ "foo" , nil , "" , "" , "--foo value\t" } ,
{ "f" , nil , "" , "" , "-f value\t" } ,
{ "f" , nil , "The total `foo` desired" , "all" , "-f foo\tThe total foo desired (default: \"all\")" } ,
{ "test" , nil , "" , "Something" , "--test value\t(default: \"Something\")" } ,
{ "config " , [ ] string { " c"} , "Load configuration from `FILE`" , "" , "--config FILE, -c FILE\tLoad configuration from FILE" } ,
{ "config " , [ ] string { " c"} , "Load configuration from `CONFIG`" , "config.json" , "--config CONFIG, -c CONFIG\tLoad configuration from CONFIG (default: \"config.json\")" } ,
}
func TestStringFlagHelpOutput ( t * testing . T ) {
for _ , test := range stringFlagTests {
flag := StringFlag { Name : test . name , Usage : test . usage , Value : test . value }
flag := & StringFlag { Name : test . name , Aliases : test . aliases , Usage : test . usage , Value : test . value }
output := flag . String ( )
if output != test . expected {
@ -58,7 +71,7 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_FOO" , "derp" )
for _ , test := range stringFlagTests {
flag := StringFlag { Name : test . name , Value: test . value , EnvVar : "APP_FOO" }
flag := & StringFlag { Name : test . name , Aliases: test . aliases , Value: test . value , EnvVar s : [ ] string { "APP_FOO" } }
output := flag . String ( )
expectedSuffix := " [$APP_FOO]"
@ -71,21 +84,33 @@ func TestStringFlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestStringFlagApply_SetsAllNames ( t * testing . T ) {
v := "mmm"
fl := StringFlag { Name : "hay" , Aliases : [ ] string { "H" , "hayyy" } , Destination : & v }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--hay" , "u" , "-H" , "yuu" , "--hayyy" , "YUUUU" } )
expect ( t , err , nil )
expect ( t , v , "YUUUU" )
}
var stringSliceFlagTests = [ ] struct {
name string
aliases [ ] string
value * StringSlice
expected string
} {
{ "foo" , NewStringSlice ( "" ) , "--foo value\t" } ,
{ "f" , NewStringSlice ( "" ) , "-f value\t" } ,
{ "f" , NewStringSlice ( "Lipstick" ) , "-f value\t(default: \"Lipstick\")" } ,
{ "test" , NewStringSlice ( "Something" ) , "--test value\t(default: \"Something\")" } ,
{ "d, dee" , NewStringSlice ( "Inka" , "Dinka" , "dooo" ) , "-d value, --dee value\t(default: \"Inka\", \"Dinka\", \"dooo\")" } ,
{ "foo" , nil , NewStringSlice ( "" ) , "--foo value\t" } ,
{ "f" , nil , NewStringSlice ( "" ) , "-f value\t" } ,
{ "f" , nil , NewStringSlice ( "Lipstick" ) , "-f value\t(default: \"Lipstick\")" } ,
{ "test" , nil , NewStringSlice ( "Something" ) , "--test value\t(default: \"Something\")" } ,
{ "d ee" , [ ] string { " d"} , NewStringSlice ( "Inka" , "Dinka" , "dooo" ) , "- - dee value, -d value\t(default: \"Inka\", \"Dinka\", \"dooo\")"} ,
}
func TestStringSliceFlagHelpOutput ( t * testing . T ) {
for _ , test := range stringSliceFlagTests {
flag := StringSliceFlag { Name : test . name , Value : test . value }
flag := & StringSliceFlag { Name : test . name , Aliases : test . aliases , Value : test . value }
output := flag . String ( )
if output != test . expected {
@ -98,7 +123,7 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_QWWX" , "11,4" )
for _ , test := range stringSliceFlagTests {
flag := StringSliceFlag { Name : test . name , Value: test . value , EnvVar : "APP_QWWX" }
flag := & StringSliceFlag { Name : test . name , Aliases: test . aliases , Value: test . value , EnvVar s : [ ] string { "APP_QWWX" } }
output := flag . String ( )
expectedSuffix := " [$APP_QWWX]"
@ -111,6 +136,15 @@ func TestStringSliceFlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestStringSliceFlagApply_SetsAllNames ( t * testing . T ) {
fl := StringSliceFlag { Name : "goat" , Aliases : [ ] string { "G" , "gooots" } }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--goat" , "aaa" , "-G" , "bbb" , "--gooots" , "eeeee" } )
expect ( t , err , nil )
}
var intFlagTests = [ ] struct {
name string
expected string
@ -121,7 +155,7 @@ var intFlagTests = []struct {
func TestIntFlagHelpOutput ( t * testing . T ) {
for _ , test := range intFlagTests {
flag := IntFlag { Name : test . name , Value : 9 }
flag := & IntFlag { Name : test . name , Value : 9 }
output := flag . String ( )
if output != test . expected {
@ -134,7 +168,7 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_BAR" , "2" )
for _ , test := range intFlagTests {
flag := IntFlag { Name : test . name , EnvVar : "APP_BAR" }
flag := & IntFlag { Name : test . name , EnvVar s : [ ] string { "APP_BAR" } }
output := flag . String ( )
expectedSuffix := " [$APP_BAR]"
@ -147,6 +181,17 @@ func TestIntFlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestIntFlagApply_SetsAllNames ( t * testing . T ) {
v := 3
fl := IntFlag { Name : "banana" , Aliases : [ ] string { "B" , "banannanana" } , Destination : & v }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--banana" , "1" , "-B" , "2" , "--banannanana" , "5" } )
expect ( t , err , nil )
expect ( t , v , 5 )
}
var durationFlagTests = [ ] struct {
name string
expected string
@ -157,7 +202,7 @@ var durationFlagTests = []struct {
func TestDurationFlagHelpOutput ( t * testing . T ) {
for _ , test := range durationFlagTests {
flag := DurationFlag { Name : test . name , Value : 1 * time . Second }
flag := & DurationFlag { Name : test . name , Value : 1 * time . Second }
output := flag . String ( )
if output != test . expected {
@ -170,7 +215,7 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_BAR" , "2h3m6s" )
for _ , test := range durationFlagTests {
flag := DurationFlag { Name : test . name , EnvVar : "APP_BAR" }
flag := & DurationFlag { Name : test . name , EnvVar s : [ ] string { "APP_BAR" } }
output := flag . String ( )
expectedSuffix := " [$APP_BAR]"
@ -183,19 +228,31 @@ func TestDurationFlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestDurationFlagApply_SetsAllNames ( t * testing . T ) {
v := time . Second * 20
fl := DurationFlag { Name : "howmuch" , Aliases : [ ] string { "H" , "whyyy" } , Destination : & v }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--howmuch" , "30s" , "-H" , "5m" , "--whyyy" , "30h" } )
expect ( t , err , nil )
expect ( t , v , time . Hour * 30 )
}
var intSliceFlagTests = [ ] struct {
name string
aliases [ ] string
value * IntSlice
expected string
} {
{ "heads" , NewIntSlice ( ) , "--heads value\t" } ,
{ "H" , NewIntSlice ( ) , "-H value\t" } ,
{ "H, heads" , NewIntSlice ( 9 , 3 ) , "-H value, --heads value\t(default: 9, 3)" } ,
{ "heads" , nil , NewIntSlice ( ) , "--heads value\t" } ,
{ "H" , nil , NewIntSlice ( ) , "-H value\t" } ,
{ "H " , [ ] string { " heads"} , NewIntSlice ( 9 , 3 ) , "-H value, --heads value\t(default: 9, 3)" } ,
}
func TestIntSliceFlagHelpOutput ( t * testing . T ) {
for _ , test := range intSliceFlagTests {
flag := IntSliceFlag { Name : test . name , Value : test . value }
flag := & IntSliceFlag { Name : test . name , Aliases : test . aliases , Value : test . value }
output := flag . String ( )
if output != test . expected {
@ -208,7 +265,7 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_SMURF" , "42,3" )
for _ , test := range intSliceFlagTests {
flag := IntSliceFlag { Name : test . name , Value: test . value , EnvVar : "APP_SMURF" }
flag := & IntSliceFlag { Name : test . name , Aliases: test . aliases , Value: test . value , EnvVar s : [ ] string { "APP_SMURF" } }
output := flag . String ( )
expectedSuffix := " [$APP_SMURF]"
@ -221,6 +278,15 @@ func TestIntSliceFlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestIntSliceFlagApply_SetsAllNames ( t * testing . T ) {
fl := IntSliceFlag { Name : "bits" , Aliases : [ ] string { "B" , "bips" } }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--bits" , "23" , "-B" , "3" , "--bips" , "99" } )
expect ( t , err , nil )
}
var float64FlagTests = [ ] struct {
name string
expected string
@ -231,7 +297,7 @@ var float64FlagTests = []struct {
func TestFloat64FlagHelpOutput ( t * testing . T ) {
for _ , test := range float64FlagTests {
flag := Float64Flag { Name : test . name , Value : float64 ( 0.1 ) }
flag := & Float64Flag { Name : test . name , Value : float64 ( 0.1 ) }
output := flag . String ( )
if output != test . expected {
@ -244,7 +310,7 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_BAZ" , "99.4" )
for _ , test := range float64FlagTests {
flag := Float64Flag { Name : test . name , EnvVar : "APP_BAZ" }
flag := & Float64Flag { Name : test . name , EnvVar s : [ ] string { "APP_BAZ" } }
output := flag . String ( )
expectedSuffix := " [$APP_BAZ]"
@ -257,6 +323,17 @@ func TestFloat64FlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestFloat64FlagApply_SetsAllNames ( t * testing . T ) {
v := float64 ( 99.1 )
fl := Float64Flag { Name : "noodles" , Aliases : [ ] string { "N" , "nurbles" } , Destination : & v }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--noodles" , "1.3" , "-N" , "11" , "--nurbles" , "43.33333" } )
expect ( t , err , nil )
expect ( t , v , float64 ( 43.33333 ) )
}
var genericFlagTests = [ ] struct {
name string
value Generic
@ -268,7 +345,7 @@ var genericFlagTests = []struct {
func TestGenericFlagHelpOutput ( t * testing . T ) {
for _ , test := range genericFlagTests {
flag := GenericFlag { Name : test . name , Value : test . value , Usage : "test flag" }
flag := & GenericFlag { Name : test . name , Value : test . value , Usage : "test flag" }
output := flag . String ( )
if output != test . expected {
@ -281,7 +358,7 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
os . Clearenv ( )
os . Setenv ( "APP_ZAP" , "3" )
for _ , test := range genericFlagTests {
flag := GenericFlag { Name : test . name , EnvVar : "APP_ZAP" }
flag := & GenericFlag { Name : test . name , EnvVar s : [ ] string { "APP_ZAP" } }
output := flag . String ( )
expectedSuffix := " [$APP_ZAP]"
@ -294,10 +371,19 @@ func TestGenericFlagWithEnvVarHelpOutput(t *testing.T) {
}
}
func TestGenericFlagApply_SetsAllNames ( t * testing . T ) {
fl := GenericFlag { Name : "orbs" , Aliases : [ ] string { "O" , "obrs" } , Value : & Parser { } }
set := flag . NewFlagSet ( "test" , 0 )
fl . Apply ( set )
err := set . Parse ( [ ] string { "--orbs" , "eleventy,3" , "-O" , "4,bloop" , "--obrs" , "19,s" } )
expect ( t , err , nil )
}
func TestParseMultiString ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
StringFlag { Name : "serve, s" } ,
& StringFlag { Name : "serve " , Alia ses: [ ] string { "s"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . String ( "serve" ) != "10" {
@ -315,7 +401,7 @@ func TestParseDestinationString(t *testing.T) {
var dest string
a := App {
Flags : [ ] Flag {
StringFlag {
& StringFlag {
Name : "dest" ,
Destination : & dest ,
} ,
@ -335,7 +421,7 @@ func TestParseMultiStringFromEnv(t *testing.T) {
os . Setenv ( "APP_COUNT" , "20" )
( & App {
Flags : [ ] Flag {
StringFlag { Name : "count , c" , EnvVar : "APP_COUNT" } ,
& StringFlag { Name : "count " , Aliases : [ ] string { " c"} , EnvVar s : [ ] string { "APP_COUNT" } } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . String ( "count" ) != "20" {
@ -354,7 +440,7 @@ func TestParseMultiStringFromEnvCascade(t *testing.T) {
os . Setenv ( "APP_COUNT" , "20" )
( & App {
Flags : [ ] Flag {
StringFlag { Name : "count , c" , EnvVar : "COMPAT_COUNT ,APP_COUNT"} ,
& StringFlag { Name : "count " , Aliases : [ ] string { " c"} , EnvVar s : [ ] string { "COMPAT_COUNT " , " APP_COUNT"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . String ( "count" ) != "20" {
@ -371,7 +457,7 @@ func TestParseMultiStringFromEnvCascade(t *testing.T) {
func TestParseMultiStringSlice ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "serve , s", Value : NewStringSlice ( ) } ,
& StringSliceFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : NewStringSlice ( ) } ,
} ,
Action : func ( ctx * Context ) error {
expected := [ ] string { "10" , "20" }
@ -389,7 +475,7 @@ func TestParseMultiStringSlice(t *testing.T) {
func TestParseMultiStringSliceWithDefaults ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "serve , s", Value : NewStringSlice ( "9" , "2" ) } ,
& StringSliceFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : NewStringSlice ( "9" , "2" ) } ,
} ,
Action : func ( ctx * Context ) error {
expected := [ ] string { "10" , "20" }
@ -407,7 +493,7 @@ func TestParseMultiStringSliceWithDefaults(t *testing.T) {
func TestParseMultiStringSliceWithDefaultsUnset ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "serve , s", Value : NewStringSlice ( "9" , "2" ) } ,
& StringSliceFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : NewStringSlice ( "9" , "2" ) } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . StringSlice ( "serve" ) , [ ] string { "9" , "2" } ) {
@ -427,7 +513,7 @@ func TestParseMultiStringSliceFromEnv(t *testing.T) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "intervals , i", Value : NewStringSlice ( ) , EnvVar : "APP_INTERVALS" } ,
& StringSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewStringSlice ( ) , EnvVar s : [ ] string { "APP_INTERVALS" } } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . StringSlice ( "intervals" ) , [ ] string { "20" , "30" , "40" } ) {
@ -447,7 +533,7 @@ func TestParseMultiStringSliceFromEnvWithDefaults(t *testing.T) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "intervals , i", Value : NewStringSlice ( "1" , "2" , "5" ) , EnvVar : "APP_INTERVALS" } ,
& StringSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewStringSlice ( "1" , "2" , "5" ) , EnvVar s : [ ] string { "APP_INTERVALS" } } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . StringSlice ( "intervals" ) , [ ] string { "20" , "30" , "40" } ) {
@ -467,7 +553,7 @@ func TestParseMultiStringSliceFromEnvCascade(t *testing.T) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "intervals , i", Value : NewStringSlice ( ) , EnvVar : "COMPAT_INTERVALS ,APP_INTERVALS"} ,
& StringSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewStringSlice ( ) , EnvVar s : [ ] string { "COMPAT_INTERVALS " , " APP_INTERVALS"} } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . StringSlice ( "intervals" ) , [ ] string { "20" , "30" , "40" } ) {
@ -487,7 +573,7 @@ func TestParseMultiStringSliceFromEnvCascadeWithDefaults(t *testing.T) {
( & App {
Flags : [ ] Flag {
StringSliceFlag { Name : "intervals , i", Value : NewStringSlice ( "1" , "2" , "5" ) , EnvVar : "COMPAT_INTERVALS ,APP_INTERVALS"} ,
& StringSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewStringSlice ( "1" , "2" , "5" ) , EnvVar s : [ ] string { "COMPAT_INTERVALS " , " APP_INTERVALS"} } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . StringSlice ( "intervals" ) , [ ] string { "20" , "30" , "40" } ) {
@ -504,7 +590,7 @@ func TestParseMultiStringSliceFromEnvCascadeWithDefaults(t *testing.T) {
func TestParseMultiInt ( t * testing . T ) {
a := App {
Flags : [ ] Flag {
IntFlag { Name : "serve , s"} ,
& IntFlag { Name : "serve " , Alia ses: [ ] string { "s"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Int ( "serve" ) != 10 {
@ -523,7 +609,7 @@ func TestParseDestinationInt(t *testing.T) {
var dest int
a := App {
Flags : [ ] Flag {
IntFlag {
& IntFlag {
Name : "dest" ,
Destination : & dest ,
} ,
@ -543,7 +629,7 @@ func TestParseMultiIntFromEnv(t *testing.T) {
os . Setenv ( "APP_TIMEOUT_SECONDS" , "10" )
a := App {
Flags : [ ] Flag {
IntFlag { Name : "timeout , t" , EnvVar : "APP_TIMEOUT_SECONDS" } ,
& IntFlag { Name : "timeout " , Aliases : [ ] string { " t"} , EnvVar s : [ ] string { "APP_TIMEOUT_SECONDS" } } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Int ( "timeout" ) != 10 {
@ -563,7 +649,7 @@ func TestParseMultiIntFromEnvCascade(t *testing.T) {
os . Setenv ( "APP_TIMEOUT_SECONDS" , "10" )
a := App {
Flags : [ ] Flag {
IntFlag { Name : "timeout , t" , EnvVar : "COMPAT_TIMEOUT_SECONDS ,APP_TIMEOUT_SECONDS"} ,
& IntFlag { Name : "timeout " , Aliases : [ ] string { " t"} , EnvVar s : [ ] string { "COMPAT_TIMEOUT_SECONDS " , " APP_TIMEOUT_SECONDS"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Int ( "timeout" ) != 10 {
@ -581,7 +667,7 @@ func TestParseMultiIntFromEnvCascade(t *testing.T) {
func TestParseMultiIntSlice ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
IntSliceFlag { Name : "serve , s", Value : NewIntSlice ( ) } ,
& IntSliceFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : NewIntSlice ( ) } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . IntSlice ( "serve" ) , [ ] int { 10 , 20 } ) {
@ -598,7 +684,7 @@ func TestParseMultiIntSlice(t *testing.T) {
func TestParseMultiIntSliceWithDefaults ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
IntSliceFlag { Name : "serve , s", Value : NewIntSlice ( 9 , 2 ) } ,
& IntSliceFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : NewIntSlice ( 9 , 2 ) } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . IntSlice ( "serve" ) , [ ] int { 10 , 20 } ) {
@ -615,7 +701,7 @@ func TestParseMultiIntSliceWithDefaults(t *testing.T) {
func TestParseMultiIntSliceWithDefaultsUnset ( t * testing . T ) {
( & App {
Flags : [ ] Flag {
IntSliceFlag { Name : "serve , s", Value : NewIntSlice ( 9 , 2 ) } ,
& IntSliceFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : NewIntSlice ( 9 , 2 ) } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . IntSlice ( "serve" ) , [ ] int { 9 , 2 } ) {
@ -635,7 +721,7 @@ func TestParseMultiIntSliceFromEnv(t *testing.T) {
( & App {
Flags : [ ] Flag {
IntSliceFlag { Name : "intervals , i", Value : NewIntSlice ( ) , EnvVar : "APP_INTERVALS" } ,
& IntSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewIntSlice ( ) , EnvVar s : [ ] string { "APP_INTERVALS" } } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . IntSlice ( "intervals" ) , [ ] int { 20 , 30 , 40 } ) {
@ -655,7 +741,7 @@ func TestParseMultiIntSliceFromEnvWithDefaults(t *testing.T) {
( & App {
Flags : [ ] Flag {
IntSliceFlag { Name : "intervals , i", Value : NewIntSlice ( 1 , 2 , 5 ) , EnvVar : "APP_INTERVALS" } ,
& IntSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewIntSlice ( 1 , 2 , 5 ) , EnvVar s : [ ] string { "APP_INTERVALS" } } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . IntSlice ( "intervals" ) , [ ] int { 20 , 30 , 40 } ) {
@ -675,7 +761,7 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
( & App {
Flags : [ ] Flag {
IntSliceFlag { Name : "intervals , i", Value : NewIntSlice ( ) , EnvVar : "COMPAT_INTERVALS ,APP_INTERVALS"} ,
& IntSliceFlag { Name : "intervals " , Al iases: [ ] string { "i"} , Value : NewIntSlice ( ) , EnvVar s : [ ] string { "COMPAT_INTERVALS " , " APP_INTERVALS"} } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . IntSlice ( "intervals" ) , [ ] int { 20 , 30 , 40 } ) {
@ -692,7 +778,7 @@ func TestParseMultiIntSliceFromEnvCascade(t *testing.T) {
func TestParseMultiFloat64 ( t * testing . T ) {
a := App {
Flags : [ ] Flag {
Float64Flag { Name : "serve , s"} ,
& Float64Flag { Name : "serve " , Alia ses: [ ] string { "s"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Float64 ( "serve" ) != 10.2 {
@ -711,7 +797,7 @@ func TestParseDestinationFloat64(t *testing.T) {
var dest float64
a := App {
Flags : [ ] Flag {
Float64Flag {
& Float64Flag {
Name : "dest" ,
Destination : & dest ,
} ,
@ -731,7 +817,7 @@ func TestParseMultiFloat64FromEnv(t *testing.T) {
os . Setenv ( "APP_TIMEOUT_SECONDS" , "15.5" )
a := App {
Flags : [ ] Flag {
Float64Flag { Name : "timeout , t" , EnvVar : "APP_TIMEOUT_SECONDS" } ,
& Float64Flag { Name : "timeout " , Aliases : [ ] string { " t"} , EnvVar s : [ ] string { "APP_TIMEOUT_SECONDS" } } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Float64 ( "timeout" ) != 15.5 {
@ -751,7 +837,7 @@ func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
os . Setenv ( "APP_TIMEOUT_SECONDS" , "15.5" )
a := App {
Flags : [ ] Flag {
Float64Flag { Name : "timeout , t" , EnvVar : "COMPAT_TIMEOUT_SECONDS ,APP_TIMEOUT_SECONDS"} ,
& Float64Flag { Name : "timeout " , Aliases : [ ] string { " t"} , EnvVar s : [ ] string { "COMPAT_TIMEOUT_SECONDS " , " APP_TIMEOUT_SECONDS"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Float64 ( "timeout" ) != 15.5 {
@ -769,7 +855,7 @@ func TestParseMultiFloat64FromEnvCascade(t *testing.T) {
func TestParseMultiBool ( t * testing . T ) {
a := App {
Flags : [ ] Flag {
BoolFlag { Name : "serve , s"} ,
& BoolFlag { Name : "serve " , Alia ses: [ ] string { "s"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Bool ( "serve" ) != true {
@ -788,7 +874,7 @@ func TestParseDestinationBool(t *testing.T) {
var dest bool
a := App {
Flags : [ ] Flag {
BoolFlag {
& BoolFlag {
Name : "dest" ,
Destination : & dest ,
} ,
@ -808,7 +894,7 @@ func TestParseMultiBoolFromEnv(t *testing.T) {
os . Setenv ( "APP_DEBUG" , "1" )
a := App {
Flags : [ ] Flag {
BoolFlag { Name : "debug , d" , EnvVar : "APP_DEBUG" } ,
& BoolFlag { Name : "debug " , Aliases : [ ] string { " d"} , EnvVar s : [ ] string { "APP_DEBUG" } } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Bool ( "debug" ) != true {
@ -828,7 +914,7 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) {
os . Setenv ( "APP_DEBUG" , "1" )
a := App {
Flags : [ ] Flag {
BoolFlag { Name : "debug , d" , EnvVar : "COMPAT_DEBUG ,APP_DEBUG"} ,
& BoolFlag { Name : "debug " , Aliases : [ ] string { " d"} , EnvVar s : [ ] string { "COMPAT_DEBUG " , " APP_DEBUG"} } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Bool ( "debug" ) != true {
@ -846,7 +932,7 @@ func TestParseMultiBoolFromEnvCascade(t *testing.T) {
func TestParseMultiBoolTrue ( t * testing . T ) {
a := App {
Flags : [ ] Flag {
BoolFlag { Name : "implode , i", Value : true } ,
& BoolFlag { Name : "implode " , Al iases: [ ] string { "i"} , Value : true } ,
} ,
Action : func ( ctx * Context ) error {
if ctx . Bool ( "implode" ) {
@ -866,7 +952,7 @@ func TestParseDestinationBoolTrue(t *testing.T) {
a := App {
Flags : [ ] Flag {
BoolFlag {
& BoolFlag {
Name : "dest" ,
Value : true ,
Destination : & dest ,
@ -887,10 +973,11 @@ func TestParseMultiBoolTrueFromEnv(t *testing.T) {
os . Setenv ( "APP_DEBUG" , "0" )
a := App {
Flags : [ ] Flag {
BoolFlag {
Name : "debug, d" ,
& BoolFlag {
Name : "debug" ,
Aliases : [ ] string { "d" } ,
Value : true ,
EnvVar : "APP_DEBUG" ,
EnvVar s : [ ] string { "APP_DEBUG" } ,
} ,
} ,
Action : func ( ctx * Context ) error {
@ -911,10 +998,11 @@ func TestParseMultiBoolTrueFromEnvCascade(t *testing.T) {
os . Setenv ( "APP_DEBUG" , "0" )
a := App {
Flags : [ ] Flag {
BoolFlag {
Name : "debug, d" ,
& BoolFlag {
Name : "debug" ,
Aliases : [ ] string { "d" } ,
Value : true ,
EnvVar : "COMPAT_DEBUG ,APP_DEBUG",
EnvVar s : [ ] string { "COMPAT_DEBUG " , " APP_DEBUG"} ,
} ,
} ,
Action : func ( ctx * Context ) error {
@ -951,7 +1039,7 @@ func (p *Parser) String() string {
func TestParseGeneric ( t * testing . T ) {
a := App {
Flags : [ ] Flag {
GenericFlag { Name : "serve , s", Value : & Parser { } } ,
& GenericFlag { Name : "serve " , Alia ses: [ ] string { "s"} , Value : & Parser { } } ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . Generic ( "serve" ) , & Parser { "10" , "20" } ) {
@ -971,7 +1059,12 @@ func TestParseGenericFromEnv(t *testing.T) {
os . Setenv ( "APP_SERVE" , "20,30" )
a := App {
Flags : [ ] Flag {
GenericFlag { Name : "serve, s" , Value : & Parser { } , EnvVar : "APP_SERVE" } ,
& GenericFlag {
Name : "serve" ,
Aliases : [ ] string { "s" } ,
Value : & Parser { } ,
EnvVars : [ ] string { "APP_SERVE" } ,
} ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . Generic ( "serve" ) , & Parser { "20" , "30" } ) {
@ -991,7 +1084,11 @@ func TestParseGenericFromEnvCascade(t *testing.T) {
os . Setenv ( "APP_FOO" , "99,2000" )
a := App {
Flags : [ ] Flag {
GenericFlag { Name : "foos" , Value : & Parser { } , EnvVar : "COMPAT_FOO,APP_FOO" } ,
& GenericFlag {
Name : "foos" ,
Value : & Parser { } ,
EnvVars : [ ] string { "COMPAT_FOO" , "APP_FOO" } ,
} ,
} ,
Action : func ( ctx * Context ) error {
if ! reflect . DeepEqual ( ctx . Generic ( "foos" ) , & Parser { "99" , "2000" } ) {