Reverse order of flag searching
Flags specified later can override flags specified earlier.
This commit is contained in:
parent
6842224b37
commit
ce84a374cc
6
cli.go
6
cli.go
@ -169,7 +169,8 @@ func (this *Cli) ParseOrExit (args []string) *Cli {
|
|||||||
// was found, it returns true. If it was not found, it returns nil, false.
|
// was found, it returns true. If it was not found, it returns nil, false.
|
||||||
func (this *Cli) ShortFlag (short rune) (*Flag, bool) {
|
func (this *Cli) ShortFlag (short rune) (*Flag, bool) {
|
||||||
if short == 0 { return nil, false }
|
if short == 0 { return nil, false }
|
||||||
for _, flag := range this.Flags {
|
for index := len(this.Flags) - 1; index >= 0; index -- {
|
||||||
|
flag := this.Flags[index]
|
||||||
if flag.Short == short { return flag, true }
|
if flag.Short == short { return flag, true }
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
@ -179,7 +180,8 @@ func (this *Cli) ShortFlag (short rune) (*Flag, bool) {
|
|||||||
// was found, it returns true. If it was not found, it returns nil, false.
|
// was found, it returns true. If it was not found, it returns nil, false.
|
||||||
func (this *Cli) LongFlag (long string) (*Flag, bool) {
|
func (this *Cli) LongFlag (long string) (*Flag, bool) {
|
||||||
if long == "" { return nil, false }
|
if long == "" { return nil, false }
|
||||||
for _, flag := range this.Flags {
|
for index := len(this.Flags) - 1; index >= 0; index -- {
|
||||||
|
flag := this.Flags[index]
|
||||||
if flag.Long == long { return flag, true }
|
if flag.Long == long { return flag, true }
|
||||||
}
|
}
|
||||||
return nil, false
|
return nil, false
|
||||||
|
Loading…
Reference in New Issue
Block a user