-
Notifications
You must be signed in to change notification settings - Fork 40
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
Support tab completion for profiles #572
Conversation
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.
Nice!!
libs/databrickscfg/profiles.go
Outdated
@@ -99,3 +100,11 @@ func LoadProfiles(path string, fn ProfileMatchFunction) (file string, profiles P | |||
|
|||
return | |||
} | |||
|
|||
func ProfileCompletion(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) { | |||
_, profiles, err := LoadProfiles(DefaultPath, func(p Profile) bool { return true }) |
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.
What you suggest should be easy. You can traverse cmd
all the way to root and figure out of any of the parts is account
. If so, we complete account profiles, otherwise workspace profiles.
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.
I see. I think to make this actually work, we need to do a slightly more subtle change:
- If no command group is set at all, complete with both profile types.
- If the command group is "accounts", complete with account profiles only.
- Otherwise, complete with workspace profiles only.
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.
Otherwise, databricks --profile <TAB>
would only show workspace profiles.
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.
Indeed. Can also be a follow up, either way works.
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.
Just tried it, and args
is always empty even if there are arguments supplied. I guess the values supplied to args
are only in the context of the command that the flag is defined on... I just refactored this function for now. In the future, we can autogenerate the --profile flag in command groups.
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.
It is, but the cmd
should be the command for which the completion is triggered.
* Add development runs ([#522](#522)). * Support tab completion for profiles ([#572](#572)). * Correctly use --profile flag passed for all bundle commands ([#571](#571)). * Disallow notebooks in paths where files are expected ([#573](#573)). * Improve auth login experience ([#570](#570)). * Remove base path checks during sync ([#576](#576)). * First look for databricks.yml before falling back to bundle.yml ([#580](#580)). * Integrate with auto-release infra ([#581](#581)). API Changes: * Removed `databricks metastores maintenance` command. * Added `databricks metastores enable-optimization` command. * Added `databricks tables update` command. * Changed `databricks account settings delete-personal-compute-setting` command with new required argument order. * Changed `databricks account settings read-personal-compute-setting` command with new required argument order. * Added `databricks clean-rooms` command group. OpenAPI SHA: 850a075ed9758d21a6bc4409506b48c8b9f93ab4, Date: 2023-07-18 Dependency updates: * Bump golang.org/x/term from 0.9.0 to 0.10.0 ([#567](#567)). * Bump golang.org/x/oauth2 from 0.9.0 to 0.10.0 ([#566](#566)). * Bump golang.org/x/mod from 0.11.0 to 0.12.0 ([#568](#568)). * Bump github.com/databricks/databricks-sdk-go from 0.12.0 to 0.13.0 ([#585](#585)).
* Add development runs ([#522](#522)). * Support tab completion for profiles ([#572](#572)). * Correctly use --profile flag passed for all bundle commands ([#571](#571)). * Disallow notebooks in paths where files are expected ([#573](#573)). * Improve auth login experience ([#570](#570)). * Remove base path checks during sync ([#576](#576)). * First look for databricks.yml before falling back to bundle.yml ([#580](#580)). * Integrate with auto-release infra ([#581](#581)). API Changes: * Removed `databricks metastores maintenance` command. * Added `databricks metastores enable-optimization` command. * Added `databricks tables update` command. * Changed `databricks account settings delete-personal-compute-setting` command with new required argument order. * Changed `databricks account settings read-personal-compute-setting` command with new required argument order. * Added `databricks clean-rooms` command group. OpenAPI SHA: 850a075ed9758d21a6bc4409506b48c8b9f93ab4, Date: 2023-07-18 Dependency updates: * Bump golang.org/x/term from 0.9.0 to 0.10.0 ([#567](#567)). * Bump golang.org/x/oauth2 from 0.9.0 to 0.10.0 ([#566](#566)). * Bump golang.org/x/mod from 0.11.0 to 0.12.0 ([#568](#568)). * Bump github.com/databricks/databricks-sdk-go from 0.12.0 to 0.13.0 ([#585](#585)).
* Add development runs ([#522](#522)). * Support tab completion for profiles ([#572](#572)). * Correctly use --profile flag passed for all bundle commands ([#571](#571)). * Disallow notebooks in paths where files are expected ([#573](#573)). * Improve auth login experience ([#570](#570)). * Remove base path checks during sync ([#576](#576)). * First look for databricks.yml before falling back to bundle.yml ([#580](#580)). * Integrate with auto-release infra ([#581](#581)). API Changes: * Removed `databricks metastores maintenance` command. * Added `databricks metastores enable-optimization` command. * Added `databricks tables update` command. * Changed `databricks account settings delete-personal-compute-setting` command with new required argument order. * Changed `databricks account settings read-personal-compute-setting` command with new required argument order. * Added `databricks clean-rooms` command group. OpenAPI SHA: 850a075ed9758d21a6bc4409506b48c8b9f93ab4, Date: 2023-07-18 Dependency updates: * Bump golang.org/x/term from 0.9.0 to 0.10.0 ([#567](#567)). * Bump golang.org/x/oauth2 from 0.9.0 to 0.10.0 ([#566](#566)). * Bump golang.org/x/mod from 0.11.0 to 0.12.0 ([#568](#568)). * Bump github.com/databricks/databricks-sdk-go from 0.12.0 to 0.13.0 ([#585](#585)).
Changes
Currently,
databricks --profile <TAB>
autocompletes with the shell default behavior, listing files in the local directory. This is not a great experience. Especially given that the suggested profile names for accounts are so long, it can be cumbersome to type them out by hand. This PR configures autocompletion for--profile
to inspect the profiles of ~/.databrickscfg.One potential improvement is to filter the response based on whether the command is known to be account-level or workspace-level.
Tests
Manual test.
![Screenshot_11_07_2023__18_31](https://private-user-images.githubusercontent.com/1850319/252730805-d7a3acd0-2511-45ac-bd82-95567775c10a.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjAyMDk1NzYsIm5iZiI6MTcyMDIwOTI3NiwicGF0aCI6Ii8xODUwMzE5LzI1MjczMDgwNS1kN2EzYWNkMC0yNTExLTQ1YWMtYmQ4Mi05NTU2Nzc3NWMxMGEucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcwNSUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MDVUMTk1NDM2WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZGU3OTFlNDk3YzE0MTViMDYyZGM4OTI1YTRhYzBlMTFmOWJkMTRiYWZmYTlhZTBmZDcyOWU5NmU2NDY2ODhhNyZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.GPUxVAEd7PPoPDVtxiAV2-d0OPMz8sQrBCA5zP4MsFA)