Skip to content

Improve the completion command to handle flags and arguments properly #2278

@suzuki-shunsuke

Description

@suzuki-shunsuke

This issue proposes improvements to the behavior of the completion command.

Current Issues

  1. The completion command does not parse flags, so it does not support the --help flag and returns an error.
completion --help
unknown shell --help, available shells are [bash fish pwsh zsh]
  1. Since the completion command does not parse flags, specifying an unknown flag results in an unknown shell error.
completion --foo
unknown shell --foo, available shells are [bash fish pwsh zsh]
  1. Because flags are not parsed, unknown flags such as completion bash --foo are silently ignored.
completion bash --foo
#!/bin/bash

# This is a shell completion script auto-generated by https://github.com/urfave/cli for bash.
...
  1. Since shells such as bash and zsh are not treated as subcommands, completion help bash and completion bash --help do not display help messages.
completion help bash
unknown shell help, available shells are [bash fish pwsh zsh]
completion bash --help
#!/bin/bash

# This is a shell completion script auto-generated by https://github.com/urfave/cli for bash.
...

Proposed Improvements

  1. Enable flag parsing for the completion command.
    1. Add support for --help.
    2. Provide more appropriate error messages for unknown flags.
completion --help
NAME:
   xxx completion - Output shell completion script for bash, zsh, fish, or Powershell
...
completion --foo
Incorrect Usage: flag provided but not defined: -foo
  1. Treat shells such as bash and zsh as subcommands.
    1. completion help bash and completion bash --help should display help messages.
completion help bash
NAME:
   xxx completion bash - Output bash completion script
completion bash --help
NAME:
   xxx completion bash - Output bash completion script
  1. Since global options are ignored for the completion command, remove them from the help message as well.
completion bash --help
NAME:
   xxx completion bash - Output bash completion script

USAGE:
   xxx completion bash [options]

OPTIONS:
   --help, -h  show help

Background: Why the completion Command Does Not Parse Flags

Flag parsing was originally disabled for the completion command to avoid errors when global required options were not provided.

In this proposal, flag parsing will be enabled while skipping the validation of required options for the completion command, thereby avoiding the original issue.

Metadata

Metadata

Labels

area/v3relates to / is being considered for v3kind/bugdescribes or fixes a bug

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions