Skip to content

#363 Add nested subcommand support for help#364

Merged
gunnarmorling merged 1 commit into
kcctl:mainfrom
C0urante:gh-363-1
Aug 1, 2023
Merged

#363 Add nested subcommand support for help#364
gunnarmorling merged 1 commit into
kcctl:mainfrom
C0urante:gh-363-1

Conversation

@C0urante

@C0urante C0urante commented Jul 31, 2023

Copy link
Copy Markdown
Contributor

Fixes #363

Augments the help command to process nested subcommands, and adds support for the -h/--help flag to every subcommand.

Before:

> kcctl help restart connectors
Usage: kcctl restart [COMMAND]
Restarts some connectors or a task
Commands:
  connector, connectors  Restarts the specified connector(s)
  task                   Restarts the specified connector or task

(This shows the usage info for restart, even though we requested it for restart connectors)

After:

> kcctl help restart connectors
Usage: kcctl restart connector [-eh] [-t=<tasks>] [NAME...]
Restarts the specified connector(s)
      [NAME...]         Name of the connector (e.g. 'my-connector')
  -e, --reg-exp         use NAME(s) as regexp pattern(s) to use on all
                          connectors
  -h, --help            Show this help message and exit.
  -t, --tasks=<tasks>   also restart tasks for the connector(s); valid values:
                          all, failed

Before:

> kcctl restart connectors -h
Unknown option: '-h'
Usage: kcctl restart connector [-e] [NAME...]
Restarts the specified connector(s)
      [NAME...]   Name of the connector (e.g. 'my-connector')
  -e, --reg-exp   use NAME(s) as regexp pattern(s) to use on all connectors

(Prints an error message about -h being an unknown option)

After:

> kcctl restart connectors -h
Usage: kcctl restart connector [-eh] [-t=<tasks>] [NAME...]
Restarts the specified connector(s)
      [NAME...]         Name of the connector (e.g. 'my-connector')
  -e, --reg-exp         use NAME(s) as regexp pattern(s) to use on all
                          connectors
  -h, --help            Show this help message and exit.
  -t, --tasks=<tasks>   also restart tasks for the connector(s); valid values:
                          all, failed

There is one small drawback to this approach in that it adds a bit of noise to the usage summary for every command. Commands that accepted a single argument or flag now have info on one additional flag (-h/--help).

Autocomplete is supported, but only for top-level commands. This behavior mirrors current autocomplete support for the help command, which repeatedly recommends top-level commands even though only the first one is used. Ideally we could support autocomplete for nested subcommands, but this may be difficult to do with picocli.

@gunnarmorling

Copy link
Copy Markdown
Collaborator

(This shows the usage info for restart, even though we requested it for restart connectors)

I'm confused by this one, it still shows the wrong one, no?

> kcctl help restart connectors
Usage: kcctl restart [-hV] [COMMAND]
Restarts some connectors or a task
  -h, --help      Show this help message and exit.
  -V, --version   Print version information and exit.
Commands:
  connector, connectors  Restarts the specified connector(s)
  task                   Restarts the specified connector or task
  • Why does it mention the task sub-command, when displaying the help for the connectors sub-command? It seems that output above is actually for the restart command?
  • Unrelated, but it seems the help message for task is wrong, it should just say "Restarts the specified task"?

@C0urante C0urante force-pushed the gh-363-1 branch 2 times, most recently from 97b8619 to 7d92f20 Compare July 31, 2023 19:00
@gunnarmorling

Copy link
Copy Markdown
Collaborator

Even though the -V flag is included in the usage summary for every command, it doesn't actually do anything when invoked with a command/subcommand (e.g., kcctl delete -V). When this happens, nothing is printed and the exit status is zero.

Hum, yeah, that's a bit weird.

A bit of noise is added to the usage summary for every command. Commands that accepted a single argument or flag now have info on two additional flags (-h and -V), one of which is a no-op.

The -h seems justified, but -V not so much?

Autocomplete support for the help command is completely wiped. We can probably restore it if that's a dealbreaker fro this PR.

Not a deal-breaker if it's only for the help command. Maybe though we should get rid of it and only support option 3 (-h, --help)?

@C0urante

Copy link
Copy Markdown
Contributor Author

I jumped the gun implementing this. Going to mark as a draft and continue the discussion on #363 until we've settled on an ideal syntax; you raised some good points there that deserve to be addressed before we spend time on code review. Thanks for the rapid turnaround though! 😄

@C0urante C0urante marked this pull request as draft July 31, 2023 19:04
@C0urante C0urante marked this pull request as ready for review July 31, 2023 19:37
@C0urante

Copy link
Copy Markdown
Contributor Author

Got rid of the extraneous -V flag. Took a little bit of legwork but hopefully the approach of adding a mixin to each command class isn't too brittle. If it is, I can try to look into more automatic/magical approaches that don't require per-command changes.

@C0urante

C0urante commented Jul 31, 2023

Copy link
Copy Markdown
Contributor Author

Not a deal-breaker if it's only for the help command. Maybe though we should get rid of it and only support option 3 (-h, --help)?

Correct, it's only for the help command. I personally really like the help <command> <subcommand> syntax so I'll look into bringing back autocomplete for it (hopefully including nested subcommands!)... hoping we can all be happy with the result here 😄

@C0urante

C0urante commented Aug 1, 2023

Copy link
Copy Markdown
Contributor Author

I'm confused by this one, it still shows the wrong one, no?

Sorry, missed this comment earlier! Was a copy+paste error on my part. I've updated the description with the correct output, after verifying that it accurately reflects what the CLI emits after being built with the latest commit for this PR.

@C0urante

C0urante commented Aug 1, 2023

Copy link
Copy Markdown
Contributor Author

Unrelated, but it seems the help message for task is wrong, it should just say "Restarts the specified task"?

Yeah, good catch! I'll add it to this PR tomorrow if there are no objections.

@gunnarmorling

Copy link
Copy Markdown
Collaborator

Sweet, this LGTM overall to me. IIUC, there's two remaining loose ends:

  • Wrong message for restart task (+1 for adding this to this PR)
  • Completion broken for help command

Anything else?

@C0urante

C0urante commented Aug 1, 2023

Copy link
Copy Markdown
Contributor Author

I think that's it!

With the latest commit, I fixed the restart task help description, and yesterday I "fixed" the help autocompletion. It's broken for nested subcommands, but works for top-level commands, which matches the logic on the current main. More info in the description.

I want to try to get autocomplete working for nested subcommands with help at some point, but don't think that should be a blocker. If you agree, I think we can merge this 🎉

@gunnarmorling

Copy link
Copy Markdown
Collaborator

Sounds good, can you just log a follow-up issue for the nested subcommand help auto-completion?

@gunnarmorling

Copy link
Copy Markdown
Collaborator

Applied. Thanks a lot, @C0urante!

@gunnarmorling gunnarmorling merged commit d90423f into kcctl:main Aug 1, 2023
@C0urante C0urante deleted the gh-363-1 branch August 1, 2023 14:36
@C0urante

C0urante commented Aug 1, 2023

Copy link
Copy Markdown
Contributor Author

Thanks Gunnar! Filed #370 as a follow-up for autocompletion of nested subcommands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show help for nested subcommands

2 participants