-
Notifications
You must be signed in to change notification settings - Fork 79
Added an error when invalid subcommand is provided for CLI commands #2655
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
Conversation
.codegen/service.go.tmpl
Outdated
@@ -73,6 +73,23 @@ func New() *cobra.Command { | |||
// This service is being previewed; hide from help output. | |||
Hidden: true, | |||
{{- end }} | |||
RunE: func(cmd *cobra.Command, args []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand correctly, RunE
is only executed if the subcommand is not found.
Would it be possible to instead of specifying a custom RunE
, to specify an Args: cobra.NoArgs
, or custom function that prints something about the subcommand. I doubt this needs to resolve the subcommand.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately not, this is what I was trying to do in the first place. So the args validation happens in cmd.execute
(https://github.com/spf13/cobra/blob/ceb39aba25c86233e4888210c4b57cdb0a78d1e1/command.go#L905) which is called only after c.Find call (which searches for subcommands) https://github.com/spf13/cobra/blob/ceb39aba25c86233e4888210c4b57cdb0a78d1e1/command.go#L1123-L1148
And Find calls this legacyArgs and returns an error before validate args are even executed https://github.com/spf13/cobra/blob/ceb39aba25c86233e4888210c4b57cdb0a78d1e1/command.go#L776
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Very complicated.
.codegen/service.go.tmpl
Outdated
@@ -73,6 +73,23 @@ func New() *cobra.Command { | |||
// This service is being previewed; hide from help output. | |||
Hidden: true, | |||
{{- end }} | |||
RunE: func(cmd *cobra.Command, args []string) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. Very complicated.
## Release v0.248.0 ### Notable Changes * Python for Databricks Asset Bundles is now in Public Preview. This feature extends bundles so that you can define jobs and pipelines as Python code, dynamically create jobs and pipelines using metadata, and modify jobs and pipelines defined in YAML or Python during bundle deployment. For more information and to get started see [Configuration in Python](https://docs.databricks.com/aws/en/dev-tools/bundles/python). * Fixed a regression with pipeline library globs introduced in 0.247.0 ([#2723](#2723)). The issue caused glob patterns to fail when using paths relative to a directory that is not the bundle root. ### Dependency updates * Upgraded Go SDK to 0.63.0 ([#2716](#2716)) * Upgraded TF provider to 1.73.0 ([#2728](#2728)) ### CLI * Added an error when invalid subcommand is provided for CLI commands ([#2655](#2655)) * Added dry-run flag support to sync command ([#2657](#2657)) ### Bundles * Do not use app config section in test templates and generated app configuration ([#2599](#2599)) * Do not exit early when checking incompatible tasks for specified DBR ([#2692](#2692)) * Removed include/exclude flags support from bundle sync command ([#2718](#2718)) * Do not clean up Python artifacts dist and build folder in "bundle validate", do it in "bundle deploy". This reverts the behaviour introduced in 0.245.0 ([#2722](#2722)) ### API Changes * Added enable-export-notebook, enable-notebook-table-clipboard and enable-results-downloading workspace-level commands. * Removed unused `timeout` and `no-wait` flags for clusters and pipelines
Changes
Added an error when invalid subcommand is provided for CLI commands
Why
Previously unknown subcommands of subcommands would be happily accepted due to the cobra behaviour https://github.com/spf13/cobra/blob/ceb39aba25c86233e4888210c4b57cdb0a78d1e1/args.go#L28
This PR makes sure that only valid subcommands are accepted
Tests
Added acceptance test