@@ -94,10 +94,34 @@ func MigrateGlobalFlags(ctx *cli.Context) {
94
94
}
95
95
96
96
func doMigrateFlags (ctx * cli.Context ) {
97
+ // Figure out if there are any aliases of commands. If there are, we want
98
+ // to ignore them when iterating over the flags.
99
+ var aliases = make (map [string ]bool )
100
+ for _ , fl := range ctx .Command .Flags {
101
+ for _ , alias := range fl .Names ()[1 :] {
102
+ aliases [alias ] = true
103
+ }
104
+ }
97
105
for _ , name := range ctx .FlagNames () {
98
106
for _ , parent := range ctx .Lineage ()[1 :] {
99
107
if parent .IsSet (name ) {
100
- ctx .Set (name , parent .String (name ))
108
+ // When iterating across the lineage, we will be served both
109
+ // the 'canon' and alias formats of all commmands. In most cases,
110
+ // it's fine to set it in the ctx multiple times (one for each
111
+ // name), however, the Slice-flags are not fine.
112
+ // The slice-flags accumulate, so if we set it once as
113
+ // "foo" and once as alias "F", then both will be present in the slice.
114
+ if _ , isAlias := aliases [name ]; isAlias {
115
+ continue
116
+ }
117
+ // If it is a string-slice, we need to set it as
118
+ // "alfa, beta, gamma" instead of "[alfa beta gamma]", in order
119
+ // for the backing StringSlice to parse it properly.
120
+ if result := parent .StringSlice (name ); len (result ) > 0 {
121
+ ctx .Set (name , strings .Join (result , "," ))
122
+ } else {
123
+ ctx .Set (name , parent .String (name ))
124
+ }
101
125
break
102
126
}
103
127
}
0 commit comments