Skip to content

Commit

Permalink
help: deduplicate 'pro help' command entries
Browse files Browse the repository at this point in the history
We use a class variable to make sure each command can register its own
help entry to the main help page. When get_parser is called more than
once, the subparsers are instance bound but the help content gets
duplicated. We now make sure to only add entries that are not present
yet.

Signed-off-by: Renan Rodrigo <[email protected]>
  • Loading branch information
renanrodrigo committed Oct 1, 2024
1 parent 4027b9b commit 615f7db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
39 changes: 39 additions & 0 deletions features/cli/help.feature
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,45 @@ Feature: Pro Client help text
"""
usage: pro [-h] [--debug] [--version] <command> ...
Quick start commands:
status current status of all Ubuntu Pro services
attach attach this machine to an Ubuntu Pro subscription
enable enable a specific Ubuntu Pro service on this machine
system show system information related to Pro services
security-status list available security updates for the system
Security-related commands:
fix check for and mitigate the impact of a CVE/USN on this system
Troubleshooting-related commands:
collect-logs collect Pro logs and debug information
Other commands:
api Calls the Client API endpoints.
auto-attach automatically attach on supported platforms
config manage Ubuntu Pro configuration on this machine
detach remove this machine from an Ubuntu Pro subscription
disable disable a specific Ubuntu Pro service on this machine
refresh refresh Ubuntu Pro services
Flags:
-h, --help Displays help on pro and command line options
--debug show all debug log messages to console
--version show version of pro
Use pro <command> --help for more information about a command.
"""
# '--help' and 'help' should both work and produce the same output
When I run `pro help` as non-root
Then I will see the following on stdout
"""
usage: pro [-h] [--debug] [--version] <command> ...
Quick start commands:
status current status of all Ubuntu Pro services
Expand Down
6 changes: 4 additions & 2 deletions uaclient/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,11 @@ def add_help_entry(
help_string: str,
position: int = 0,
):
cls.help_entries[category].append(
HelpEntry(position=position, name=name, help_string=help_string)
entry = HelpEntry(
position=position, name=name, help_string=help_string
)
if entry not in cls.help_entries[category]:
cls.help_entries[category].append(entry)

def __init__(self, *args, use_main_help: bool = True, **kwargs):
super().__init__(*args, **kwargs)
Expand Down

0 comments on commit 615f7db

Please sign in to comment.