Skip to content

Commit 175b67e

Browse files
committed
stop automatically generating shorthand for each flag
it can lead to unstable arguments when adding fields to structs—better to define them explicitly
1 parent 5db1b10 commit 175b67e

File tree

2 files changed

+1
-11
lines changed

2 files changed

+1
-11
lines changed

com.go

-10
Original file line numberDiff line numberDiff line change
@@ -494,16 +494,6 @@ func (fTr *flagTracker) short(field reflect.StructField, flagName string) (lette
494494
fTr.shorts[runeVal] = struct{}{}
495495
return short, nil
496496
}
497-
for _, chr := range flagName {
498-
if _, ok := fTr.shorts[chr]; ok {
499-
continue
500-
}
501-
// TODO if the lowercase version of first letter is taken, try upper case and vice versa
502-
if unicode.IsLetter(chr) {
503-
fTr.shorts[chr] = struct{}{}
504-
return string(chr), nil
505-
}
506-
}
507497
return "", nil // no shorthand char available, but that's ok
508498
}
509499

test/test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ type MyMain struct {
2424
Aint16 int16 `json:"anint16"`
2525
Aint32 int32
2626
Aint64 int64 `flag:"a-int64" help:"int64 flag"`
27-
Afloat float64 `flag:"a-float" help:"float flag"`
27+
Afloat float64 `flag:"a-float" help:"float flag" short:"f"`
2828
Afloat32 float32
2929
Auint uint `flag:"a-uint" help:"uint flag"`
3030
Auint8 uint8

0 commit comments

Comments
 (0)