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

chip-tool handling of optional arguments that are not at the end of the list is all broken #12063

Closed
bzbarsky-apple opened this issue Nov 20, 2021 · 0 comments · Fixed by #12064

Comments

@bzbarsky-apple
Copy link
Contributor

Problem

After #11749 the behavior of chip-tool is as follows:

  1. Walk argv for indices up to required-arg-count and initialize the arguments at those indices.
  2. Walk argv 2 at a time for indices corresponding to the count of optional args and init arguments that match by name.

But what happens if the optional arg is not at the end? A real-life example of this is:

chip-tool otasoftwareupdaterequestor announce-ota-provider ProviderLocation VendorId AnnouncementReason [--MetadataForNode] node-id endpoint-id

but let's walk through a hypothetical example with just two args the first of which is optional: my-command [--optional-arg] required-arg.

As far as I can tell, what this will do is:

  1. If called with one argument, initialize the optional arg with that value and leave the required arg uninitialized.
  2. If called with three arguments, init the optional arg with the first argument, then try to match the second arg against the string "--required-arg", etc.

Proposed Solution

Either fix the code in Command::InitArguments or fix the ordering so the optional arguments really do come last.

bzbarsky-apple added a commit to bzbarsky-apple/connectedhomeip that referenced this issue Nov 20, 2021
The code that initializes arguments assumes the optional ones are
sorted at the end.  So make sure that's actually true.

Fixes project-chip#12063
bzbarsky-apple added a commit to bzbarsky-apple/connectedhomeip that referenced this issue Nov 20, 2021
The code that initializes arguments assumes the optional ones are
sorted at the end.  So make sure that's actually true.

Fixes project-chip#12063
andy31415 pushed a commit that referenced this issue Nov 22, 2021
The code that initializes arguments assumes the optional ones are
sorted at the end.  So make sure that's actually true.

Fixes #12063
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

Successfully merging a pull request may close this issue.

1 participant