@@ -43,6 +43,11 @@ type Command struct {
43
43
// Hidden determines whether the command should be hidden from help.
44
44
Hidden bool
45
45
46
+ // Deprecated indicates whether this command is deprecated.
47
+ // If empty, the command is not deprecated.
48
+ // If set, the value is used as the deprecation message.
49
+ Deprecated string `json:"deprecated,omitempty"`
50
+
46
51
// RawArgs determines whether the command should receive unparsed arguments.
47
52
// No flags are parsed when set, and the command is responsible for parsing
48
53
// its own flags.
@@ -316,6 +321,13 @@ func (inv *Invocation) CurWords() (prev string, cur string) {
316
321
// allArgs is wired through the stack so that global flags can be accepted
317
322
// anywhere in the command invocation.
318
323
func (inv * Invocation ) run (state * runState ) error {
324
+ if inv .Command .Deprecated != "" {
325
+ fmt .Fprintf (inv .Stderr , "%s %q is deprecated!. %s\n " ,
326
+ prettyHeader ("warning" ),
327
+ inv .Command .FullName (),
328
+ inv .Command .Deprecated ,
329
+ )
330
+ }
319
331
err := inv .Command .Options .ParseEnv (inv .Environ )
320
332
if err != nil {
321
333
return xerrors .Errorf ("parsing env: %w" , err )
0 commit comments