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

Fixed ignoring required positional parameters when --json flag is provided #535

Merged
merged 5 commits into from
Jul 3, 2023

Conversation

andrewnester
Copy link
Contributor

@andrewnester andrewnester commented Jun 29, 2023

Changes

When there are positional required parameters in the command which can't be unmarshalled from JSON, we should require them despite the fact --json flag is provided.

The reason is that for some of the command, for example, databricks groups patch ID these arguments are actually path arguments in API and can't be set as part of --json body provided.

Original change which introduced this ignore logic is here: #405

Fixes #533, #537

Note: Code generation is based on the change in this PR: databricks/databricks-sdk-go#536

Tests

  1. Running cli groups patch 123 --json {...} works correctly

Backward compatibility tests with previous changes from #405

  1. cli clusters events --json '{"cluster_id": "1029-xxxx"}' - works, returns list of events
  2. cli clusters events 1029-xxxx - works, returns list of events
  3. cli clusters events - works, first prompts for Cluster ID and then returns the list of events

patchReq.Id = args[0]
args = append(args, id)
}
if len(args) != 1 {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will break I believe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mgyucht no, why? This is a general logic for prompts. If no args provided it will go to the condition on line 284 and ask user to choose group ID from the list and append it to args on line 296 so len(args) == 1

Or if customer provided positional argument, the prompt condition will be skipped

Copy link
Contributor

Choose a reason for hiding this comment

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

My mistake, didn't realize args itself was modified in that block.

Copy link
Contributor

@mgyucht mgyucht left a comment

Choose a reason for hiding this comment

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

Nice fix! Though let's hold off merging this until the Go SDK PR merges, and let's update the name of the new method here.

Copy link
Contributor

@pietern pietern left a comment

Choose a reason for hiding this comment

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

Nice work! I'd like to decouple the SDK bump from the function change, though.

@andrewnester andrewnester force-pushed the fix-missing-required-param-with-json branch from 9de3679 to 2772621 Compare July 3, 2023 10:30
@andrewnester andrewnester requested a review from pietern July 3, 2023 10:34
@andrewnester andrewnester merged commit 17ed7a3 into main Jul 3, 2023
4 checks passed
@andrewnester andrewnester deleted the fix-missing-required-param-with-json branch July 3, 2023 11:20
@pietern pietern mentioned this pull request Jul 7, 2023
pietern added a commit that referenced this pull request Jul 10, 2023
## Changes

CLI:
* Fix secrets put-secret command
([#545](#545)).
* Fixed ignoring required positional parameters when --json flag is
provided ([#535](#535)).
* Update cp help message to not require file scheme
([#554](#554)).

Bundles:
* Fix: bundle destroy fails when bundle.tf.json file is deleted
([#519](#519)).
* Fixed error reporting when included invalid files in include section
([#543](#543)).
* Make top level workspace optional in JSON schema
([#562](#562)).
* Propagate TF_CLI_CONFIG_FILE env variable
([#555](#555)).
* Update Terraform provider schema structs
([#563](#563)).
* Update inline JSON schema documentation
([#557](#557)).

Dependencies:
* Bump Go SDK to v0.12.0
([#540](#540)).
* Bump github.com/hashicorp/terraform-json from 0.17.0 to 0.17.1
([#541](#541)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants