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
Add bash completion for get
and set
commands
#2411
base: main
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## main #2411 +/- ##
==========================================
- Coverage 85.22% 85.18% -0.05%
==========================================
Files 208 207 -1
Lines 10388 10433 +45
==========================================
+ Hits 8853 8887 +34
- Misses 1535 1546 +11
Continue to review full report at Codecov.
|
Hi @nicolasbock. Thanks for this! I have been longing for this completion for a while, but didn't have time to get to it myself. I haven't tried it yet, but it's very welcome. There are some other changes in the works that will affect that help text, but we can blend. Adding to my TODO list to review (if no one else does first). |
Hi @ricab ! Thanks for the comments! If you point me towards these other changes I can modify the completions here to make them work with those changes. |
Hey @nicolasbock, have a look at #2352. That's a little outdated now, I mean to push again soon. The thing is, we're going through an overhaul of the settings, with the client now leaving daemon settings to the daemon. The client will no longer know or care what settings the daemon understands (some of them will soon be dynamic). Instead, it will simply ship get/set/keys requests over as needed. But we have yet to settle on the best way to interrogate settings keys. For now, when the daemon can't be reached, I just have a placeholder for its settings ( I will take your PR into account when considering the best approach and I'd otherwise let it simmer for a little 🙂 But I won't forget it. Hope that's alright! |
Thanks for the additional info @ricab ! |
bors try |
tryBuild failed: |
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.
Hey @nicolasbock, circling back to this as it makes sense to include for the next release (even if it could need updating later).
Nice code 👍 only a few details inline.
local append_string="" | ||
local -a settings | ||
|
||
if [[ -v 1 ]]; then |
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.
This doesn't seem to cut it, it's not getting into the if, so no "=".
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.
This is working for me. When I type
multipass set client.primary-na
and hit the tab
key it completes to
multipass set client.primary-name=
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.
Weird, it doesn't here: https://asciinema.org/a/ibIom1Ff3YNs2IrLvrPOfVSrr
I wonder what's affecting it. Trying with a plain function doesn't work either:
elsa@ricab-xps13:~$ test(){
> if [[ -v 1 ]]; then
> echo yes
> else
> echo no
> fi
> }
elsa@ricab-xps13:~$ test
no
elsa@ricab-xps13:~$ test asdf
This works though:
elsa@ricab-xps13:~$ test(){ if [[ -v toto ]]; then echo yes; else echo no; fi; }
elsa@ricab-xps13:~$ test
no
elsa@ricab-xps13:~$ toto=asfd
elsa@ricab-xps13:~$ test
yes
Perhaps -v
for argument numbers only works on very recent bash? I have 5.0.17.
("elsa" is just a sandbox account I use)
completions/bash/multipass
Outdated
@@ -227,6 +242,9 @@ _multipass_complete() | |||
_multipass_aliases | |||
opts="${opts} ${multipass_aliases}" | |||
;; | |||
"get") | |||
opts="${opts} --raw" |
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.
Ideally, this would only be added if not already used. But we can probably let it stick, as that's what we're doing for the likes of --help
already. And it is not technically wrong to say --raw
multiple times.
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.
Fixed with
opts="${opts} --raw" | |
if [[ ! ${COMP_WORDS[*]} =~ --raw ]]; then | |
opts="${opts} --raw" | |
fi |
@@ -339,6 +357,13 @@ _multipass_complete() | |||
# TODO: Do use spaces after the completion of an option starting with "--". | |||
compopt -o nospace | |||
;; | |||
"get") | |||
_multipass_setting_keys |
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.
Both get
and set
both take a single key argument (for the time being, at least). It would be nice to complete that argument only if not yet used (so that we're not suggesting something that doesn't work):
$ multipass get client.primary-name local.driver
Need exactly one setting key.
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.
Fixed.
This change adds completion for the `get` and `set` commands. Signed-off-by: Nicolas Bock <nicolas.bock@canonical.com>
3d62fe6
to
d9cbc38
Compare
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.
Suggesting we move a piece of code to deal with get
case only once.
"get") | ||
if [[ ! ${COMP_WORDS[*]} =~ --raw ]]; then | ||
opts="${opts} --raw" | ||
fi | ||
;; |
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.
"get") | |
if [[ ! ${COMP_WORDS[*]} =~ --raw ]]; then | |
opts="${opts} --raw" | |
fi | |
;; |
@@ -339,6 +364,13 @@ _multipass_complete() | |||
# TODO: Do use spaces after the completion of an option starting with "--". | |||
compopt -o nospace | |||
;; | |||
"get") | |||
_multipass_setting_keys | |||
;; |
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 [[ ! ${COMP_WORDS[*]} =~ --raw ]]; then | |
opts="${opts} --raw" | |
fi | |
;; |
This change adds completion for the
get
andset
commands.Signed-off-by: Nicolas Bock nicolas.bock@canonical.com