Skip to content

Add usage string when command fails with incorrect arguments - #1276

Merged
andrewnester merged 5 commits into
mainfrom
fix/usage-on-err
Mar 12, 2024
Merged

Add usage string when command fails with incorrect arguments#1276
andrewnester merged 5 commits into
mainfrom
fix/usage-on-err

Conversation

@andrewnester

Copy link
Copy Markdown
Contributor

Changes

Add usage string when command fails with incorrect arguments

Fixes#1119

Tests

Example output

> databricks libraries cluster-status Error: accepts 1 arg(s), received 0
Usage:
databricks libraries cluster-status CLUSTER_ID [flags]
Flags:
-h, --help help for cluster-status
Global Flags:
--debug enable debug logging
-o, --output type output type: text or json (default text)
-p, --profile string ~/.databrickscfg profile
-t, --target string bundle target to use (if applicable)

@codecov-commenter

codecov-commenter commented Mar 11, 2024

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 11.36364% with 39 lines in your changes are missing coverage. Please review.

Project coverage is 52.05%. Comparing base (a44c52a) to head (4175bec).
Report is 2 commits behind head on main.

FilesPatch %Lines
cmd/root/args.go0.00%21 Missing ⚠️
cmd/workspace/repos/repos.go0.00%3 Missing ⚠️
cmd/bundle/deploy.go0.00%1 Missing ⚠️
cmd/bundle/destroy.go0.00%1 Missing ⚠️
cmd/bundle/init.go0.00%1 Missing ⚠️
cmd/bundle/launch.go0.00%1 Missing ⚠️
cmd/bundle/run.go0.00%1 Missing ⚠️
cmd/bundle/schema.go0.00%1 Missing ⚠️
cmd/bundle/summary.go0.00%1 Missing ⚠️
cmd/bundle/sync.go0.00%1 Missing ⚠️
... and 7 more
Additional details and impacted files
@@ Coverage Diff @@## main #1276 +/- ##
==========================================
- Coverage 52.28% 52.05% -0.24% 
==========================================
Files 316 317 +1 Lines 17968 18001 +33 ==========================================
- Hits 9395 9370 -25 - Misses 7881 7935 +54 - Partials 692 696 +4 

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pieternpietern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This triggers for the # of required arguments. Could we do the same for typo's in flags?

@pietern

Copy link
Copy Markdown
Contributor

And if we can, it would be great to generalize into an error type such that we can deal with handling centrally.

As is, we would need to implement the same for custom commands, and getting that for free is good for consistency.

@andrewnester

Copy link
Copy Markdown
ContributorAuthor

Could we do the same for typo's in flags?

It's already handled here https://github.com/databricks/cli/blob/main/cmd/root/root.go#L82-L89

@pieternpietern left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thanks!

@andrewnester
andrewnester added this pull request to the merge queueMar 12, 2024
Merged via the queue into main with commit c781856Mar 12, 2024
@andrewnester
andrewnester deleted the fix/usage-on-err branch March 12, 2024 14:19
pietern added a commit that referenced this pull request Mar 25, 2024
CLI:
* Propagate correct `User-Agent` for CLI during OAuth flow ([#1264](#1264)).
* Add usage string when command fails with incorrect arguments ([#1276](#1276)).
Bundles:
* Include `dyn.Path` as argument to the visit callback function ([#1260](#1260)).
* Inline logic to set a value in `dyn.SetByPath` ([#1261](#1261)).
* Add assertions for the `dyn.Path` argument to the visit callback ([#1265](#1265)).
* Add `dyn.MapByPattern` to map a function to values with matching paths ([#1266](#1266)).
* Filter current user from resource permissions ([#1262](#1262)).
* Retain location annotation when expanding globs for pipeline libraries ([#1274](#1274)).
* Added deployment state for bundles ([#1267](#1267)).
* Do CheckRunningResource only after terraform.Write ([#1292](#1292)).
* Rewrite relative paths using `dyn.Location` of the underlying value ([#1273](#1273)).
* Push deployment state right after files upload ([#1293](#1293)).
* Make `Append` function to `dyn.Path` return independent slice ([#1295](#1295)).
* Move bundle tests into bundle/tests ([#1299](#1299)).
* Upgrade Terraform provider to 1.38.0 ([#1308](#1308)).
Internal:
* Add integration test for mlops-stacks initialization ([#1155](#1155)).
* Update actions/setup-python to v5 ([#1290](#1290)).
* Update codecov/codecov-action to v4 ([#1291](#1291)).
API Changes:
* Changed `databricks catalogs list` command.
* Changed `databricks online-tables create` command.
* Changed `databricks lakeview publish` command.
* Added `databricks lakeview create` command.
* Added `databricks lakeview get` command.
* Added `databricks lakeview get-published` command.
* Added `databricks lakeview trash` command.
* Added `databricks lakeview update` command.
* Moved settings related commands to `databricks settings` and `databricks account settings`.
OpenAPI commit 93763b0d7ae908520c229c786fff28b8fd623261 (2024-03-20)
Dependency updates:
* Bump golang.org/x/oauth2 from 0.17.0 to 0.18.0 ([#1270](#1270)).
* Bump golang.org/x/mod from 0.15.0 to 0.16.0 ([#1271](#1271)).
* Update Go SDK to v0.35.0 ([#1300](#1300)).
* Update Go SDK to v0.36.0 ([#1304](#1304)).
@pieternpietern mentioned this pull request Mar 25, 2024
github-merge-queueBot pushed a commit that referenced this pull request Mar 25, 2024
CLI:
* Propagate correct `User-Agent` for CLI during OAuth flow
([#1264](#1264)).
* Add usage string when command fails with incorrect arguments
([#1276](#1276)).
Bundles:
* Include `dyn.Path` as argument to the visit callback function
([#1260](#1260)).
* Inline logic to set a value in `dyn.SetByPath`
([#1261](#1261)).
* Add assertions for the `dyn.Path` argument to the visit callback
([#1265](#1265)).
* Add `dyn.MapByPattern` to map a function to values with matching paths
([#1266](#1266)).
* Filter current user from resource permissions
([#1262](#1262)).
* Retain location annotation when expanding globs for pipeline libraries
([#1274](#1274)).
* Added deployment state for bundles
([#1267](#1267)).
* Do CheckRunningResource only after terraform.Write
([#1292](#1292)).
* Rewrite relative paths using `dyn.Location` of the underlying value
([#1273](#1273)).
* Push deployment state right after files upload
([#1293](#1293)).
* Make `Append` function to `dyn.Path` return independent slice
([#1295](#1295)).
* Move bundle tests into bundle/tests
([#1299](#1299)).
* Upgrade Terraform provider to 1.38.0
([#1308](#1308)).
Internal:
* Add integration test for mlops-stacks initialization
([#1155](#1155)).
* Update actions/setup-python to v5
([#1290](#1290)).
* Update codecov/codecov-action to v4
([#1291](#1291)).
API Changes:
* Changed `databricks catalogs list` command.
* Changed `databricks online-tables create` command.
* Changed `databricks lakeview publish` command.
* Added `databricks lakeview create` command.
* Added `databricks lakeview get` command.
* Added `databricks lakeview get-published` command.
* Added `databricks lakeview trash` command.
* Added `databricks lakeview update` command.
* Moved settings related commands to `databricks settings` and
`databricks account settings`.
OpenAPI commit 93763b0d7ae908520c229c786fff28b8fd623261 (2024-03-20)
Dependency updates:
* Bump golang.org/x/oauth2 from 0.17.0 to 0.18.0
([#1270](#1270)).
* Bump golang.org/x/mod from 0.15.0 to 0.16.0
([#1271](#1271)).
* Update Go SDK to v0.35.0
([#1300](#1300)).
* Update Go SDK to v0.36.0
([#1304](#1304)).
denik pushed a commit that referenced this pull request May 20, 2026
## Changes
Add usage string when command fails with incorrect arguments
Fixes#1119
## Tests
Example output
```
> databricks libraries cluster-status Error: accepts 1 arg(s), received 0
Usage:
databricks libraries cluster-status CLUSTER_ID [flags]
Flags:
-h, --help help for cluster-status
Global Flags:
--debug enable debug logging
-o, --output type output type: text or json (default text)
-p, --profile string ~/.databrickscfg profile
-t, --target string bundle target to use (if applicable)
```
denik pushed a commit that referenced this pull request May 20, 2026
CLI:
* Propagate correct `User-Agent` for CLI during OAuth flow
([#1264](#1264)).
* Add usage string when command fails with incorrect arguments
([#1276](#1276)).
Bundles:
* Include `dyn.Path` as argument to the visit callback function
([#1260](#1260)).
* Inline logic to set a value in `dyn.SetByPath`
([#1261](#1261)).
* Add assertions for the `dyn.Path` argument to the visit callback
([#1265](#1265)).
* Add `dyn.MapByPattern` to map a function to values with matching paths
([#1266](#1266)).
* Filter current user from resource permissions
([#1262](#1262)).
* Retain location annotation when expanding globs for pipeline libraries
([#1274](#1274)).
* Added deployment state for bundles
([#1267](#1267)).
* Do CheckRunningResource only after terraform.Write
([#1292](#1292)).
* Rewrite relative paths using `dyn.Location` of the underlying value
([#1273](#1273)).
* Push deployment state right after files upload
([#1293](#1293)).
* Make `Append` function to `dyn.Path` return independent slice
([#1295](#1295)).
* Move bundle tests into bundle/tests
([#1299](#1299)).
* Upgrade Terraform provider to 1.38.0
([#1308](#1308)).
Internal:
* Add integration test for mlops-stacks initialization
([#1155](#1155)).
* Update actions/setup-python to v5
([#1290](#1290)).
* Update codecov/codecov-action to v4
([#1291](#1291)).
API Changes:
* Changed `databricks catalogs list` command.
* Changed `databricks online-tables create` command.
* Changed `databricks lakeview publish` command.
* Added `databricks lakeview create` command.
* Added `databricks lakeview get` command.
* Added `databricks lakeview get-published` command.
* Added `databricks lakeview trash` command.
* Added `databricks lakeview update` command.
* Moved settings related commands to `databricks settings` and
`databricks account settings`.
OpenAPI commit 93763b0d7ae908520c229c786fff28b8fd623261 (2024-03-20)
Dependency updates:
* Bump golang.org/x/oauth2 from 0.17.0 to 0.18.0
([#1270](#1270)).
* Bump golang.org/x/mod from 0.15.0 to 0.16.0
([#1271](#1271)).
* Update Go SDK to v0.35.0
([#1300](#1300)).
* Update Go SDK to v0.36.0
([#1304](#1304)).
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Usability: Provide short usage information when user doesn't supply enough arguments

3 participants

@andrewnester@codecov-commenter@pietern