164 // outWriter is a writer defined by the user that replaces stdout |
165 // outWriter is a writer defined by the user that replaces stdout |
165 outWriter io.Writer |
166 outWriter io.Writer |
166 // errWriter is a writer defined by the user that replaces stderr |
167 // errWriter is a writer defined by the user that replaces stderr |
167 errWriter io.Writer |
168 errWriter io.Writer |
168 |
169 |
169 //FParseErrWhitelist flag parse errors to be ignored |
170 // FParseErrWhitelist flag parse errors to be ignored |
170 FParseErrWhitelist FParseErrWhitelist |
171 FParseErrWhitelist FParseErrWhitelist |
171 |
172 |
172 // CompletionOptions is a set of options to control the handling of shell completion |
173 // CompletionOptions is a set of options to control the handling of shell completion |
173 CompletionOptions CompletionOptions |
174 CompletionOptions CompletionOptions |
174 |
175 |
222 // SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions. |
223 // SuggestionsMinimumDistance defines minimum levenshtein distance to display suggestions. |
223 // Must be > 0. |
224 // Must be > 0. |
224 SuggestionsMinimumDistance int |
225 SuggestionsMinimumDistance int |
225 } |
226 } |
226 |
227 |
227 // Context returns underlying command context. If command wasn't |
228 // Context returns underlying command context. If command was executed |
228 // executed with ExecuteContext Context returns Background context. |
229 // with ExecuteContext or the context was set with SetContext, the |
|
230 // previously set context will be returned. Otherwise, nil is returned. |
|
231 // |
|
232 // Notice that a call to Execute and ExecuteC will replace a nil context of |
|
233 // a command with a context.Background, so a background context will be |
|
234 // returned by Context after one of these functions has been called. |
229 func (c *Command) Context() context.Context { |
235 func (c *Command) Context() context.Context { |
230 return c.ctx |
236 return c.ctx |
|
237 } |
|
238 |
|
239 // SetContext sets context for the command. It is set to context.Background by default and will be overwritten by |
|
240 // Command.ExecuteContext or Command.ExecuteContextC |
|
241 func (c *Command) SetContext(ctx context.Context) { |
|
242 c.ctx = ctx |
231 } |
243 } |
232 |
244 |
233 // SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden |
245 // SetArgs sets arguments for the command. It is set to os.Args[1:] by default, if desired, can be overridden |
234 // particularly useful when testing. |
246 // particularly useful when testing. |
235 func (c *Command) SetArgs(a []string) { |
247 func (c *Command) SetArgs(a []string) { |
973 |
989 |
974 err = cmd.execute(flags) |
990 err = cmd.execute(flags) |
975 if err != nil { |
991 if err != nil { |
976 // Always show help if requested, even if SilenceErrors is in |
992 // Always show help if requested, even if SilenceErrors is in |
977 // effect |
993 // effect |
978 if err == flag.ErrHelp { |
994 if errors.Is(err, flag.ErrHelp) { |
979 cmd.HelpFunc()(cmd, args) |
995 cmd.HelpFunc()(cmd, args) |
980 return cmd, nil |
996 return cmd, nil |
981 } |
997 } |
982 |
998 |
983 // If root command has SilenceErrors flagged, |
999 // If root command has SilenceErrors flagged, |