Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
[jjo] juju2 bash autocompletion improvements #5057
Conversation
bz2
reviewed
Apr 9, 2016
| @@ -1,42 +1,55 @@ | ||
| +#!/bin/bash |
bz2
Apr 9, 2016
Contributor
Lintian told someone to remove this from the file. I didn't see the message so don't know why, but not that:
grep -F '#!/' /usr/share/bash-completion/completions/*
Matches nothing on my system.
bz2
reviewed
Apr 9, 2016
| # juju-core.bash_completion.sh: dynamic bash completion for juju cmdline, | ||
| # from parsed (and cached) juju status output. | ||
| # | ||
| # Author: JuanJo Ciarlante <jjo@canonical.com> | ||
| # Copyright 2013+, Canonical Ltd. | ||
| # License: GPLv3 | ||
| # | ||
| +# For juju2, includes --model and --controller handling: |
bz2
Apr 9, 2016
Contributor
Per the recent mail to #juju-dev, the binary name will just be 'juju'. I was looking at this script for the packaging, and think what I need is a top level variable JUJU=juju that I can replace when installing, so the wrapping scripts 'juju-1' and 'juju-2.0' can also get correct completetion goodness.
jjo
Jun 8, 2016
•
Contributor
Fixed with a run-time approach, see comments in added "juju-version" file.
Note that being run-time, supports whatever "juju" [verbatim] cmd version the user currently have, even if e.g. aliased.
bz2
reviewed
Apr 9, 2016
| -_juju_machines_from_file() { | ||
| -python -c ' | ||
| +_juju_machines_from_status_file() { | ||
| +python3 -c ' |
bz2
Apr 9, 2016
Contributor
We want this script to work on backports to trusty etc, which may have python3 available, but not installed. Can we also have a $PYTHON variable that gets set the appropriate default for the system?
bz2
reviewed
Apr 9, 2016
| +_juju_list_controllers_noflags() { | ||
| + _juju_cache_cmd 10 cat \ | ||
| + juju list-controllers --format json | \ | ||
| + python3 -c 'import json,sys; print("\n".join(json.load(sys.stdin)["controllers"].keys()))' |
bz2
Apr 9, 2016
Contributor
Will need a space after print before ( for this to work on Python 2 and 3.
Could make the json parsing helper take a 'key' name to work for all these cases? Just sub in machines/services/controllers?
jjo
Jun 8, 2016
•
Contributor
Thanks the spacing for python2,3.
Regarding generalizing the functions to receive a key instead, I'd rather prefer to keep them explicit to avoid adding another "layer of indirection", for readability and debugging.
bz2
reviewed
Apr 9, 2016
| return $? | ||
| } | ||
| complete -F _juju juju | ||
| +complete -F _juju juju2 |
|
Thanks! Have added various comments inline, main note being about the binary name. |
jrwren
reviewed
Jun 7, 2016
| + juju help commands 2>/dev/null | awk '{print $1}' | ||
| +} | ||
| + | ||
| +# Print (return) flags for juju action, shamelessly excluding |
|
I've addressed bz2 comments (tho in a different way than proposed), PTAL. |
jjo
added some commits
Apr 8, 2016
|
Appreciate another review - several improvements since last PR:
|
jjo
added some commits
Jun 17, 2016
|
Thanks for addressing my comments, I poked the juju team as well to get a review. |
mjs
reviewed
Jun 28, 2016
| +${_juju_cmd_PYTHON?} -c ' | ||
| +import json, sys | ||
| +sys.stderr.close() | ||
| +j=json.load(sys.stdin) |
mjs
reviewed
Jun 28, 2016
| + local cache_fname=$(_juju_2_0_juju_status_cache_fname) | ||
| + [ -n "${cache_fname}" ] || return 0 | ||
| +${_juju_cmd_PYTHON?} -c ' | ||
| +trail="'${2}'" |
mjs
reviewed
Jun 28, 2016
| +j=json.load(sys.stdin) | ||
| +all_units=[] | ||
| +for k,v in j.get("applications", {}).items(): | ||
| + if v.get("units"): |
mjs
reviewed
Jun 28, 2016
| + if [ -z "${model}" ];then | ||
| + model=${JUJU_MODEL:-$(${_juju_cmd_JUJU_2_0?} switch)} | ||
| + fi | ||
| + # echo "** comp=$(set|egrep ^COMP) ** model=${model} **">&2 |
|
Thanks! This looks OK to me. For a future iteration of this, I wonder if it would be worth leaning on Python more to avoid the ugliness of doing fairly complex work in bash. I guess there's perhaps a speed trade off. |
|
Addressed above comments, PTAL. |
mjs
reviewed
Jun 28, 2016
| +# juju list-models --controller <TAB> | ||
| +# juju switch <TAB> | ||
| +# juju status --model <TAB> | ||
| +# juju ssh --model <TAB> [... will complete with proper model's units/etc ...] |
mjs
Jun 28, 2016
Contributor
Did you want to describe other supported completions here as well? (e.g. storage)
|
LGTM |
cherylj
commented
Jun 29, 2016
|
$$JFDI$$ |
|
Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju |
jjo commentedApr 8, 2016