mkideal / cli

CLI - A package for building command line app with go
MIT License
730 stars 43 forks source link

ctx.IsSet returns fl.isAssigned instead of fl.isSet #5

Closed fatbrain closed 8 years ago

fatbrain commented 8 years ago

Not very intuitive. From the code (both comments makes reference to same field, copy and paste gone awry?)

// isAssigned indicates wether the flag is set(contains default value)
isAssigned bool
// isAssigned indicates wether the flag is set
isSet bool

Cheers, J

mkideal commented 8 years ago

Note the (contains default value).

isSet is true only if you input the flag in ternminal. isAssigned is if you input the flag in terminal or the flag has defaut value.

type argT struct {
    A int `cli:"a" dft:"2"`
    B int `cli:"b"`
}
# flag(-a).isAssigned=flag(-a).isSet=true
# flag(-b).isAssigned=flag(-b).isSet=false
$ ./app -a 1

# flag(-a).isAssigned=flag(-a).isSet=true
# flag(-b).isAssigned=flag(-b).isSet=true
$ ./app -a 1 -b 2

# flag(-a).isAssigned=true, flag(-a).isSet=false
# flag(-b).isAssigned=flag(-b).isSet=true
$ ./app -b 2
mkideal commented 8 years ago

ctx.IsSet is wrong! 😫😢