MCPcopy
hub / github.com/urfave/cli / DefaultCompleteWithFlags

Function DefaultCompleteWithFlags

help.go:250–283  ·  view source on GitHub ↗
(ctx context.Context, cmd *Command)

Source from the content-addressed store, hash-verified

248}
249
250func DefaultCompleteWithFlags(ctx context.Context, cmd *Command) {
251 args := os.Args
252 if cmd != nil && cmd.parent != nil {
253 args = cmd.Args().Slice()
254 tracef("running default complete with flags[%v] on command %[2]q", args, cmd.Name)
255 } else {
256 tracef("running default complete with os.Args flags[%v]", args)
257 }
258 argsLen := len(args)
259 lastArg := ""
260 // parent command will have --generate-shell-completion so we need
261 // to account for that
262 if argsLen > 1 {
263 lastArg = args[argsLen-2]
264 } else if argsLen > 0 {
265 lastArg = args[argsLen-1]
266 }
267
268 if lastArg == completionFlag {
269 lastArg = ""
270 }
271
272 if strings.HasPrefix(lastArg, "-") {
273 tracef("printing flag suggestion for flag[%v] on command %[1]q", lastArg, cmd.Name)
274 printFlagSuggestions(lastArg, cmd.Flags, cmd.Root().Writer)
275 return
276 }
277
278 if cmd != nil {
279 tracef("printing command suggestions on command %[1]q", cmd.Name)
280 printCommandSuggestions(cmd.Commands, cmd.Root().Writer)
281 return
282 }
283}
284
285// ShowCommandHelpAndExit exits with code after showing help via ShowCommandHelp.
286func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, code int) {

Callers 1

Calls 6

tracefFunction · 0.85
printFlagSuggestionsFunction · 0.85
printCommandSuggestionsFunction · 0.85
ArgsMethod · 0.80
RootMethod · 0.80
SliceMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…