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

Unhelpful error message when creating help if an argument doesn't have a help text #242

Open
lengau opened this issue Feb 22, 2024 · 0 comments

Comments

@lengau
Copy link
Contributor

lengau commented Feb 22, 2024

Bug Description

If a command adds an argument without help text, the error raised isn't very useful. It should give a better error.

To Reproduce

import sys

import craft_cli


class ExampleCommand(craft_cli.BaseCommand):

    name = "example"
    help_msg = overview = "unimportant"

    def fill_parser(self, parser):
        parser.add_argument("--do-something")


craft_cli.emit.init(craft_cli.EmitterMode.BRIEF, "example-app", "example app")

dispatcher = craft_cli.Dispatcher(
    "example-app",
    [craft_cli.CommandGroup("Example", [ExampleCommand])],
    summary="summary"
)
dispatcher.pre_parse_args(sys.argv[1:])
dispatcher.load_command(None)
dispatcher.run()

python ./example.py help example

part yaml

n/a

Relevant log output

Traceback (most recent call last):
  File "/home/lengau/Work/Code/charmcraft-2/charmcraft/application/commands/example.py", line 22, in <module>
    dispatcher.pre_parse_args(sys.argv[1:])
  File "/home/lengau/Work/Code/charmcraft-2/.venv/lib/python3.11/site-packages/craft_cli/dispatcher.py", line 469, in pre_parse_args
    help_text = self._get_requested_help(cmd_args)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lengau/Work/Code/charmcraft-2/.venv/lib/python3.11/site-packages/craft_cli/dispatcher.py", line 355, in _get_requested_help
    return self._help_builder.get_command_help(command, command_options, output_format)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lengau/Work/Code/charmcraft-2/.venv/lib/python3.11/site-packages/craft_cli/helptexts.py", line 425, in get_command_help
    textblocks = builder(usage, command.overview, options, other_command_names)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lengau/Work/Code/charmcraft-2/.venv/lib/python3.11/site-packages/craft_cli/helptexts.py", line 312, in _build_plain_command_help
    option_lines.extend(_build_item_plain(title, text, max_title_len))
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/lengau/Work/Code/charmcraft-2/.venv/lib/python3.11/site-packages/craft_cli/helptexts.py", line 71, in _build_item_plain
    first = f"    {title:>{title_space}s}:  {wrapped_lines[0]}"
                                             ~~~~~~~~~~~~~^^^
IndexError: list index out of range
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

No branches or pull requests

1 participant