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

Detect and report stray arguments #293

Merged
merged 1 commit into from
May 31, 2024
Merged

Conversation

smortex
Copy link
Member

@smortex smortex commented May 31, 2024

When a tool is run with stray arguments, they are silently ignored. This typically happen when a parameter must be repeated for each value (e.g. the --tag parameter is passed multiple values with --tag foo --tag bar and passing --tag foo bar only provide a single tag and the bar value is an argument that is silently ignored).

In order to avoid this issue, raise an error by default if stray arguments are found. It is possible to indicate that stray arguments are allowed by expilcitly saying so. In this case, the arguments are accessible using the #argv method.

When a tool is run with stray arguments, they are silently ignored.
This typically happen when a parameter must be repeated for each value
(e.g. the `--tag` parameter is passed multiple values with `--tag foo
--tag bar` and passing `--tag foo bar` only provide a single tag and the
`bar` value is an argument that is silently ignored).

In order to avoid this issue, raise an error by default if stray
arguments are found.  It is possible to indicate that stray arguments
are allowed by expilcitly saying so.  In this case, the arguments are
accessible using the `#argv` method.
@smortex smortex added the enhancement New feature or request label May 31, 2024
@smortex
Copy link
Member Author

smortex commented May 31, 2024

There are inconsistencies within the riemann tools when passing parameters with multiple values:

  • Some parameters accept a single value and can be repeated to pass multiple values. They have a singular name e.g. for adding tags:

    --tag foo --tag bar --tab baz
    
  • Some parameters accept multiple values, but cannot be repeated. They have a plural name, e.g. for selecting only some devices with riemann-md:

    --devices md0 md1
    

We can adjust the code to accept both syntax, but this leave the issue that some parameters have a singular name and other a plural one.

I found that optimist gained the ability to have alternative parameters, but this has not been released yet:
ManageIQ/optimist#151

This could allow us to allow both singular and plural form 🤷 I have not yet made my mind. Do you have an opinion?

@smortex smortex changed the title Detect stray arguments Detect and report stray arguments May 31, 2024
Copy link
Member

@jamtur01 jamtur01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable.

@jamtur01 jamtur01 merged commit d2b38d7 into main May 31, 2024
7 checks passed
@smortex smortex deleted the raise-error-on-stray-arguments branch May 31, 2024 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants