Skip to content

cli flag value parsing bug when value starts with a hypen/dash #3618

@reubenmiller

Description

@reubenmiller

Describe the bug

There seems to be a cli parsing bug where if a flag that expects a value starts with a hypen/dash -, then the value is misinterpreted as an option resulting in the command to fail.

This was observed when auto generating a password for downloading a certificate using the new Cumulocity certificate authority feature (but it might affect all commands if the same parsing logic/library is used):

The example below shows that the one-time password value starts with - which causes problems with the command when parsing the value.

tedge cert download c8y --one-time-password '-vLz3i.bO0iypPPn' --device-id example
error: unexpected argument '-v' found

Usage: tedge cert download c8y [OPTIONS]

For more information, try '--help'.

Technically the - may work if it is escaped, however needing to escape the value is unusual in linux shells, as - is a "normal" character that should not require escaping, and other cli tools (go-c8y-cli) don't seem to having to escaping values starting with -.

To Reproduce

The error can be reproduced by running the following command, where the --one-time-password value should start with -:

tedge cert download c8y --one-time-password '-vLz3i.bO0iypPPn' --device-id example

Expected behavior

Screenshots

Environment (please complete the following information):

  • OS [incl. version]: any
  • Hardware [incl. revision]: any
  • System-Architecture [e.g. result of "uname -a"]: any
  • thin-edge.io version [e.g. 0.1.0]: 1.5.1

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtheme:cliTheme: cli related topics

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions