@@ -9,7 +9,7 @@ If you find any issues not covered by this document, please post a
9
9
comment on [ the discussion] ( https://github.com/urfave/cli/discussions/2084 ) or
10
10
consider sending a PR to help improve this guide.
11
11
12
- ## Import string changed
12
+ ## New Import
13
13
14
14
=== "v2"
15
15
@@ -23,9 +23,9 @@ Check each file for this and make the change.
23
23
24
24
Shell command to find them all: ` fgrep -rl github.com/urfave/cli/v2 * `
25
25
26
- ## FilePath
26
+ ## Sources
27
27
28
- Change ` FilePath: "XXXXX" ` to ` Sources: Files("XXXXX") ` .
28
+ ### FilePath
29
29
30
30
=== "v2"
31
31
@@ -39,13 +39,21 @@ Change `FilePath: "XXXXX"` to `Sources: Files("XXXXX")`.
39
39
40
40
```go
41
41
cli.StringFlag{
42
- Sources: Files("/path/to/foo"),
42
+ Sources: cli. Files("/path/to/foo"),
43
43
}
44
44
```
45
45
46
- ## EnvVars
46
+ or
47
47
48
- Change ` EnvVars: "XXXXX" ` to ` Sources: EnvVars("XXXXX") ` .
48
+ ```go
49
+ cli.StringFlag{
50
+ Sources: cli.NewValueSourceChain(
51
+ cli.File("/path/to/foo"),
52
+ ),
53
+ }
54
+ ```
55
+
56
+ ### EnvVars
49
57
50
58
=== "v2"
51
59
@@ -59,83 +67,107 @@ Change `EnvVars: "XXXXX"` to `Sources: EnvVars("XXXXX")`.
59
67
60
68
```go
61
69
cli.StringFlag{
62
- Sources: EnvVars("APP_LANG"),
70
+ Sources: cli.EnvVars("APP_LANG"),
71
+ }
72
+ ```
73
+
74
+ or
75
+
76
+ ```go
77
+ cli.StringFlag{
78
+ Sources: cli.NewValueSourceChain(
79
+ cli.EnvVar("APP_LANG"),
80
+ ),
63
81
}
64
82
```
65
83
66
- ## Altsrc has been moved out of the cli library into its own repo
84
+ ### Altsrc
85
+
86
+ #### Altsrc is now a dedicated module
67
87
68
88
=== "v2"
69
89
70
90
`import "github.com/urfave/cli/v2/altsrc"`
71
91
72
92
=== "v3"
73
93
74
- `import "github.com/urfave/cli-altsrc/v3"`
94
+ `import altsrc "github.com/urfave/cli-altsrc/v3"`
75
95
76
- ## Altsrc is now a value source for cli
96
+ #### Altsrc is now a value source for CLI
77
97
78
98
=== "v2"
79
99
80
100
```go
81
- altsrc.StringFlag{
82
- &cli.String{....}
83
- }
101
+ altsrc.NewStringFlag(
102
+ &cli.StringFlag{
103
+ Name: "key",
104
+ Value: "/tmp/foo",
105
+ },
106
+ ),
84
107
```
85
108
86
109
=== "v3"
87
110
111
+ Requires to use at least ` github.com/urfave/cli-altsrc/v3@v3.0.0-alpha2.0.20250227140532-11fbec4d81a7 `
112
+
88
113
```go
89
114
cli.StringFlag{
90
- Sources: altsrc. JSON("key", "/tmp/ foo")
115
+ Sources: cli.NewValueSourceChain(altsrcjson. JSON("key", altsrc.StringSourcer("/path/to/ foo.json"))),
91
116
}
92
117
```
93
118
94
- ## Order of precedence of envvars, filepaths, altsrc now depends on the order in which they are defined
95
-
119
+ ### Order of precedence of envvars, filepaths, altsrc now depends on the order in which they are defined
96
120
97
121
=== "v2"
98
122
99
123
```go
100
- cli.StringFlag{
101
- EnvVars: []string{"APP_LANG"},
102
- }
103
- cli.StringFlag{
124
+ altsrc.NewStringFlag(
125
+ &cli.StringFlag{
126
+ Name: "key",
127
+ EnvVars: []string{"APP_LANG"},
104
128
FilePath: "/path/to/foo",
105
- }
129
+ },
130
+ ),
106
131
```
107
132
108
133
=== "v3"
109
134
135
+ Requires to use at least `github.com/urfave/cli-altsrc/v3@v3.0.0-alpha2.0.20250227140532-11fbec4d81a7`
136
+
110
137
```go
111
- cli.StringFlag{
112
- Sources: cli.ValueSourceChain{
113
- Chain: {
114
- EnvVars("APP_LANG"),
115
- Files("/path/to/foo"),
116
- altsrc.JSON("foo", "/path/to/"),
117
- }
118
- },
119
- }
138
+ import altsrcjson "github.com/urfave/cli-altsrc/v3/json"
139
+
140
+ // ...
141
+
142
+ &cli.StringFlag{
143
+ Name: "key",
144
+ Sources: cli.NewValueSourceChain(
145
+ cli.EnvVar("APP_LANG"),
146
+ cli.File("/path/to/foo"),
147
+ altsrcjson.JSON("key", altsrc.StringSourcer("/path/to/foo.json")),
148
+ ),
149
+ },
120
150
```
121
151
122
152
In the above case the Envs are checked first and if not found then files are looked at and then finally the ` altsrc `
123
153
124
154
## cli.Context has been removed
125
155
126
- All functions handled previously by cli.Context have been incorporated into ` cli.Command ` :
156
+ All functions handled previously by ` cli.Context ` have been incorporated into ` cli.Command ` :
127
157
128
- * Change ` cli.Context.IsSet ` -> ` cli.Command.IsSet `
129
- * Change ` cli.Context.NumFlags ` -> ` cli.Command.NumFlags `
130
- * Change ` cli.Context.FlagNames ` -> ` cli.Command.FlagNames `
131
- * Change ` cli.Context.LocalFlagNames ` -> ` cli.Command.LocalFlagNames `
132
- * Change ` cli.Context.Lineage ` -> ` cli.Command.Lineage `
133
- * Change ` cli.Context.Count ` -> ` cli.Command.Count `
134
- * Change ` cli.Context.Value ` -> ` cli.Command.Value `
135
- * Change ` cli.Context.Args ` -> ` cli.Command.Args `
136
- * Change ` cli.Context.NArg ` -> ` cli.Command.NArg `
158
+ | v2 | v3 |
159
+ | ------------------------------| ------------------------------|
160
+ | ` cli.Context.IsSet ` | ` cli.Command.IsSet ` |
161
+ | ` cli.Context.NumFlags ` | ` cli.Command.NumFlags ` |
162
+ | ` cli.Context.FlagNames ` | ` cli.Command.FlagNames ` |
163
+ | ` cli.Context.LocalFlagNames ` | ` cli.Command.LocalFlagNames ` |
164
+ | ` cli.Context.Lineage ` | ` cli.Command.Lineage ` |
165
+ | ` cli.Context.Count ` | ` cli.Command.Count ` |
166
+ | ` cli.Context.Value ` | ` cli.Command.Value ` |
167
+ | ` cli.Context.Args ` | ` cli.Command.Args ` |
168
+ | ` cli.Context.NArg ` | ` cli.Command.NArg ` |
137
169
138
- ## Handler func signatures have changed
170
+ ## Handler Function Signatures Changes
139
171
140
172
All handler functions now take at least 2 arguments a ` context.Context ` and a pointer to ` Cli.Command `
141
173
in addition to other specific args. This allows handler functions to utilize ` context.Context ` for
@@ -240,3 +272,44 @@ Similar messages would be shown for other funcs.
240
272
},
241
273
}
242
274
```
275
+
276
+ ## Authors
277
+
278
+ === "v2"
279
+
280
+ ```go
281
+ &cli.App{
282
+ Authors: []*cli.Author{
283
+ {Name: "Some Guy", Email: "someguy@example.com"},
284
+ },
285
+ }
286
+ ```
287
+
288
+ === "v3"
289
+
290
+ ```go
291
+ // import "net/mail"
292
+ &cli.Command{
293
+ Authors: []any{
294
+ mail.Address{Name: "Some Guy", Address: "someguy@example.com"},
295
+ },
296
+ }
297
+ ```
298
+
299
+ ## BashCompletion/ShellCompletion
300
+
301
+ === "v2"
302
+
303
+ ```go
304
+ &cli.App{
305
+ EnableBashCompletion: true,
306
+ }
307
+ ```
308
+
309
+ === "v3"
310
+
311
+ ```go
312
+ &cli.Command{
313
+ EnableShellCompletion: true,
314
+ }
315
+ ```
0 commit comments