Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help: remove service list from help output #3172

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 0 additions & 162 deletions features/attached_commands.feature
Original file line number Diff line number Diff line change
Expand Up @@ -397,81 +397,6 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
"""
No help available for 'invalid-service'
"""
When I run `pro --help` as non-root
Then stdout matches regexp:
"""
Client to manage Ubuntu Pro services on a machine.
- anbox-cloud: .*
- cc-eal: Common Criteria EAL2 Provisioning Packages
\(https://ubuntu.com/security/cc\)
- cis: Security compliance and audit tools
\(https://ubuntu.com/security/certifications/docs/usg\)
- esm-apps: Expanded Security Maintenance for Applications
\(https://ubuntu.com/security/esm\)
- esm-infra: Expanded Security Maintenance for Infrastructure
\(https://ubuntu.com/security/esm\)
- fips-preview: .*
.*\(https://ubuntu.com/security/fips\)
- fips-updates: FIPS compliant crypto packages with stable security updates
\(https://ubuntu.com/security/fips\)
- fips: NIST-certified FIPS crypto packages \(https://ubuntu.com/security/fips\)
- landscape: Management and administration tool for Ubuntu
\(https://ubuntu.com/landscape\)
- livepatch: Canonical Livepatch service
\(https://ubuntu.com/security/livepatch\)
"""
When I run `pro help` with sudo
Then stdout matches regexp:
"""
Client to manage Ubuntu Pro services on a machine.
- anbox-cloud: .*
- cc-eal: Common Criteria EAL2 Provisioning Packages
\(https://ubuntu.com/security/cc\)
- cis: Security compliance and audit tools
\(https://ubuntu.com/security/certifications/docs/usg\)
- esm-apps: Expanded Security Maintenance for Applications
\(https://ubuntu.com/security/esm\)
- esm-infra: Expanded Security Maintenance for Infrastructure
\(https://ubuntu.com/security/esm\)
- fips-preview: .*
.*\(https://ubuntu.com/security/fips\)
- fips-updates: FIPS compliant crypto packages with stable security updates
\(https://ubuntu.com/security/fips\)
- fips: NIST-certified FIPS crypto packages \(https://ubuntu.com/security/fips\)
- landscape: Management and administration tool for Ubuntu
\(https://ubuntu.com/landscape\)
- livepatch: Canonical Livepatch service
\(https://ubuntu.com/security/livepatch\)
"""
When I run `pro help --all` as non-root
Then stdout matches regexp:
"""
Client to manage Ubuntu Pro services on a machine.
- anbox-cloud: .*
- cc-eal: Common Criteria EAL2 Provisioning Packages
\(https://ubuntu.com/security/cc\)
- cis: Security compliance and audit tools
\(https://ubuntu.com/security/certifications/docs/usg\)
- esm-apps: Expanded Security Maintenance for Applications
\(https://ubuntu.com/security/esm\)
- esm-infra: Expanded Security Maintenance for Infrastructure
\(https://ubuntu.com/security/esm\)
- fips-preview: .*
.*\(https://ubuntu.com/security/fips\)
- fips-updates: FIPS compliant crypto packages with stable security updates
\(https://ubuntu.com/security/fips\)
- fips: NIST-certified FIPS crypto packages \(https://ubuntu.com/security/fips\)
- landscape: Management and administration tool for Ubuntu
\(https://ubuntu.com/landscape\)
- livepatch: Canonical Livepatch service
\(https://ubuntu.com/security/livepatch\)
- realtime-kernel: Ubuntu kernel with PREEMPT_RT patches integrated
\(https://ubuntu.com/realtime-kernel\)
- ros-updates: All Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- ros: Security Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
"""

Examples: ubuntu release
| release | machine_type | infra-status |
Expand Down Expand Up @@ -512,93 +437,6 @@ Feature: Command behaviour when attached to an Ubuntu Pro subscription
"""
No help available for 'invalid-service'
"""
When I run `pro --help` as non-root
Then stdout matches regexp:
"""
Client to manage Ubuntu Pro services on a machine.
- anbox-cloud: .*
- cc-eal: Common Criteria EAL2 Provisioning Packages
\(https://ubuntu.com/security/cc\)
- esm-apps: Expanded Security Maintenance for Applications
\(https://ubuntu.com/security/esm\)
- esm-infra: Expanded Security Maintenance for Infrastructure
\(https://ubuntu.com/security/esm\)
- fips-preview: .*
.*\(https://ubuntu.com/security/fips\)
- fips-updates: FIPS compliant crypto packages with stable security updates
\(https://ubuntu.com/security/fips\)
- fips: NIST-certified FIPS crypto packages \(https://ubuntu.com/security/fips\)
- landscape: Management and administration tool for Ubuntu
\(https://ubuntu.com/landscape\)
- livepatch: Canonical Livepatch service
\(https://ubuntu.com/security/livepatch\)
- realtime-kernel: Ubuntu kernel with PREEMPT_RT patches integrated
\(https://ubuntu.com/realtime-kernel\)
- ros-updates: All Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- ros: Security Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- usg: Security compliance and audit tools
\(https://ubuntu.com/security/certifications/docs/usg\)
"""
When I run `pro help` with sudo
Then stdout matches regexp:
"""
Client to manage Ubuntu Pro services on a machine.
- anbox-cloud: .*
- cc-eal: Common Criteria EAL2 Provisioning Packages
\(https://ubuntu.com/security/cc\)
- esm-apps: Expanded Security Maintenance for Applications
\(https://ubuntu.com/security/esm\)
- esm-infra: Expanded Security Maintenance for Infrastructure
\(https://ubuntu.com/security/esm\)
- fips-preview: .*
.*\(https://ubuntu.com/security/fips\)
- fips-updates: FIPS compliant crypto packages with stable security updates
\(https://ubuntu.com/security/fips\)
- fips: NIST-certified FIPS crypto packages \(https://ubuntu.com/security/fips\)
- landscape: Management and administration tool for Ubuntu
\(https://ubuntu.com/landscape\)
- livepatch: Canonical Livepatch service
\(https://ubuntu.com/security/livepatch\)
- realtime-kernel: Ubuntu kernel with PREEMPT_RT patches integrated
\(https://ubuntu.com/realtime-kernel\)
- ros-updates: All Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- ros: Security Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- usg: Security compliance and audit tools
\(https://ubuntu.com/security/certifications/docs/usg\)
"""
When I run `pro help --all` as non-root
Then stdout matches regexp:
"""
Client to manage Ubuntu Pro services on a machine.
- anbox-cloud: .*
- cc-eal: Common Criteria EAL2 Provisioning Packages
\(https://ubuntu.com/security/cc\)
- esm-apps: Expanded Security Maintenance for Applications
\(https://ubuntu.com/security/esm\)
- esm-infra: Expanded Security Maintenance for Infrastructure
\(https://ubuntu.com/security/esm\)
- fips-preview: .*
.*\(https://ubuntu.com/security/fips\)
- fips-updates: FIPS compliant crypto packages with stable security updates
\(https://ubuntu.com/security/fips\)
- fips: NIST-certified FIPS crypto packages \(https://ubuntu.com/security/fips\)
- landscape: Management and administration tool for Ubuntu
\(https://ubuntu.com/landscape\)
- livepatch: Canonical Livepatch service
\(https://ubuntu.com/security/livepatch\)
- realtime-kernel: Ubuntu kernel with PREEMPT_RT patches integrated
\(https://ubuntu.com/realtime-kernel\)
- ros-updates: All Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- ros: Security Updates for the Robot Operating System
\(https://ubuntu.com/robotics/ros-esm\)
- usg: Security compliance and audit tools
\(https://ubuntu.com/security/certifications/docs/usg\)
"""

Examples: ubuntu release
| release | machine_type |
Expand Down
80 changes: 4 additions & 76 deletions uaclient/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
import sys
import tarfile
import tempfile
import textwrap
import time
from typing import List, Optional, Tuple # noqa
from typing import Optional

from uaclient import (
actions,
Expand Down Expand Up @@ -53,7 +52,6 @@
from uaclient.cli import cli_api, cli_util, disable, enable, fix
from uaclient.cli.constants import NAME, USAGE_TMPL
from uaclient.data_types import AttachActionsConfigFile, IncorrectTypeError
from uaclient.defaults import PRINT_WRAP_WIDTH
from uaclient.entitlements import (
create_enable_entitlements_not_found_error,
entitlements_disable_order,
Expand Down Expand Up @@ -81,23 +79,6 @@


class UAArgumentParser(argparse.ArgumentParser):
def __init__(
self,
prog=None,
usage=None,
epilog=None,
formatter_class=argparse.HelpFormatter,
base_desc: Optional[str] = None,
):
super().__init__(
prog=prog,
usage=usage,
epilog=epilog,
formatter_class=formatter_class,
)

self.base_desc = base_desc

def error(self, message):
self.print_usage(sys.stderr)
# In some cases (e.g. `pro --wrong-flag`) argparse errors out asking
Expand All @@ -114,55 +95,6 @@ def error(self, message):
message = messages.CLI_TRY_HELP
self.exit(2, message + "\n")

def print_help(self, file=None, show_all=False):
if self.base_desc:
service_descriptions = sorted(
UAArgumentParser._get_service_descriptions()
)
self.description = "\n".join(
[self.base_desc] + service_descriptions
)

self.description += "\n\n" + messages.PRO_HELP_SERVICE_INFO

super().print_help(file=file)

@staticmethod
def _get_service_descriptions() -> List[str]:
cfg = config.UAConfig()

service_info_tmpl = " - {name}: {description}{url}"
service_descriptions = []

resources = contract.get_available_resources(config.UAConfig())
for resource in resources:
try:
ent = entitlements.entitlement_factory(
cfg=cfg, name=resource["name"]
)
except exceptions.EntitlementNotFoundError:
continue
# Because we don't know the presentation name if unattached
presentation_name = resource.get("presentedAs", resource["name"])
if ent.help_doc_url:
url = " ({})".format(ent.help_doc_url)
else:
url = ""
service_info = textwrap.fill(
service_info_tmpl.format(
name=presentation_name,
description=ent.description,
url=url,
),
width=PRINT_WRAP_WIDTH,
subsequent_indent=" ",
break_long_words=False,
break_on_hyphens=False,
)
service_descriptions.append(service_info)

return service_descriptions


def auto_attach_parser(parser):
"""Build or extend an arg parser for auto-attach subcommand."""
Expand Down Expand Up @@ -1001,13 +933,11 @@ def action_collect_logs(args, *, cfg: config.UAConfig, **kwargs):


def get_parser(cfg: config.UAConfig):
base_desc = __doc__
parser = UAArgumentParser(
prog=NAME,
formatter_class=argparse.RawDescriptionHelpFormatter,
usage=USAGE_TMPL.format(name=NAME, command="<command>"),
epilog=messages.CLI_HELP_EPILOG.format(name=NAME, command="<command>"),
base_desc=base_desc,
)
parser.add_argument(
"--debug", action="store_true", help=messages.CLI_ROOT_DEBUG
Expand Down Expand Up @@ -1221,10 +1151,9 @@ def configure_apt_proxy(

def action_help(args, *, cfg, **kwargs):
service = args.service
show_all = args.all

if not service:
get_parser(cfg=cfg).print_help(show_all=show_all)
get_parser(cfg=cfg).print_help()
return 0

if not cfg:
Expand Down Expand Up @@ -1393,9 +1322,8 @@ def main(sys_argv=None):
parser = get_parser(cfg=cfg)
cli_arguments = sys_argv[1:]
if not cli_arguments:
parser.print_usage()
print(messages.CLI_TRY_HELP)
sys.exit(1)
parser.print_help()
sys.exit(0)

# Grab everything after a "--" if present and handle separately
if "--" in cli_arguments:
Expand Down
Loading
Loading