(ctx context.Context, cmd *Command)
| 248 | } |
| 249 | |
| 250 | func 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. |
| 286 | func ShowCommandHelpAndExit(ctx context.Context, cmd *Command, command string, code int) { |
no test coverage detected
searching dependent graphs…