From f045810697d423d108617ccd48bd7a414cb58734 Mon Sep 17 00:00:00 2001
From: sed-i <82407168+sed-i@users.noreply.github.com>
Date: Mon, 15 Nov 2021 16:27:19 -0500
Subject: feat(juju): add `jclean` function to destroy all registered
 controllers (#10426)

Closes #10426
---
 plugins/juju/README.md       |  1 +
 plugins/juju/juju.plugin.zsh | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

(limited to 'plugins/juju')

diff --git a/plugins/juju/README.md b/plugins/juju/README.md
index 49f8b0d47..2417c4669 100644
--- a/plugins/juju/README.md
+++ b/plugins/juju/README.md
@@ -113,5 +113,6 @@ Naming convention:
 
 - `jaddr <app_name> [unit_num]`: display app or unit IP address.
 - `jreld <relation_name> <app_name> <unit_num>`: display app and unit relation data.
+- `jclean`: destroy all controllers
 - `wjst [interval_secs] [args_for_watch]`: watch juju status, with optional interval
   (default: 5s); you may pass additional arguments to `watch`.
diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh
index 07f15b392..cf89418c6 100644
--- a/plugins/juju/juju.plugin.zsh
+++ b/plugins/juju/juju.plugin.zsh
@@ -95,6 +95,37 @@ jaddr() {
   fi
 }
 
+# Destroy all controllers
+jclean() {
+  if (( ! ${+commands[jq]} )); then
+    echo "jq is required but could not be found." >&2
+    return 1
+  fi
+
+  local controllers=$(juju controllers --format=json | jq -r '.controllers | keys[]' 2>/dev/null)
+  if [[ -z "$controllers" ]]; then
+    echo "No controllers registered"
+    return 0
+  fi
+
+  echo "This will forcefully destroy all storages, models and controllers."
+  echo "Controllers to be destroyed:"
+  echo "$controllers"
+
+  if ! read -q '?Are you sure (y/n)? '; then
+    echo
+    echo "Aborted."
+    return 0
+  fi
+
+  echo
+  for controller in ${=controllers}; do
+    timeout 2m juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y $controller
+    timeout 2m juju kill-controller -y -t 0 $controller 2>/dev/null
+    timeout 10s juju unregister $controller 2>/dev/null
+  done
+}
+
 # Display app and unit relation data
 jreld() {
   # $1 = relation name
@@ -125,3 +156,4 @@ wjst() {
   shift $(( $# > 0 ))
   watch -n "$interval" --color juju status --relations --storage --color "$@"
 }
+
-- 
cgit v1.2.3-70-g09d2


From cdd2d6efc612b75577db49604eeb7dc35ba5f9b5 Mon Sep 17 00:00:00 2001
From: sed-i <82407168+sed-i@users.noreply.github.com>
Date: Mon, 15 Nov 2021 16:31:19 -0500
Subject: feat(juju): introduce additional juju aliases (#10426)

---
 plugins/juju/README.md       | 34 ++++++++++++++++++++++------------
 plugins/juju/juju.plugin.zsh | 12 +++++++++++-
 2 files changed, 33 insertions(+), 13 deletions(-)

(limited to 'plugins/juju')

diff --git a/plugins/juju/README.md b/plugins/juju/README.md
index 2417c4669..918c08de5 100644
--- a/plugins/juju/README.md
+++ b/plugins/juju/README.md
@@ -18,26 +18,36 @@ Naming convention:
 
 ### General
 
-| Alias  | Command                                     | Description                                            |
-|--------|---------------------------------------------|--------------------------------------------------------|
-| `jdl`  | `juju debug-log --ms`                       | Display log, with millisecond resolution               |
-| `jdlr` | `juju debug-log --ms --replay`              | Replay entire log                                      |
-| `jh`   | `juju help`                                 | Show help on a command or other topic                  |
-| `jssl` | `juju juju show-status-log`                 | Output past statuses for the specified entity          |
-| `jstj` | `juju status --format=json`                 | Show status in json format (more detailed)             |
-| `jst`  | `juju status --relations --storage --color` | Show status, including relations and storage, in color |
+| Alias   | Command                                     | Description                                            |
+|---------|---------------------------------------------|--------------------------------------------------------|
+| `j`     | `juju`                                      | The juju command                                       |
+| `jcld`  | `juju clouds`                               | Lists all clouds with registered credentials           |
+| `jclda` | `juju clouds --all`                         | Lists all clouds available to Juju                     |
+| `jdl`   | `juju debug-log --ms`                       | Display log, with millisecond resolution               |
+| `jdlr`  | `juju debug-log --ms --replay`              | Replay entire log                                      |
+| `jh`    | `juju help`                                 | Show help on a command or other topic                  |
+| `jssl`  | `juju show-status-log`                      | Output past statuses for the specified entity          |
+| `jstj`  | `juju status --format=json`                 | Show status in json format (more detailed)             |
+| `jst`   | `juju status --relations --color`           | Show status, including relations, in color             |
+| `jsts`  | `juju status --relations --storage --color` | Show status, including relations and storage, in color |
 
 ### Bootstrap
 
-| Alias | Command                   | Description                               |
-|-------|---------------------------|-------------------------------------------|
-| `jb`  | `juju bootstrap`          | Initializing a Juju cloud environment     |
-| `jbm` | `juju bootstrap microk8s` | Initializing a MicroK8s cloud environment |
+| Alias   | Command                             | Description                                           |
+|---------|-------------------------------------|-------------------------------------------------------|
+| `jb`    | `juju bootstrap`                    | Initializing a Juju cloud environment                 |
+| `jbng`  | `juju bootstrap --no-gui`           | Initializing a Juju cloud environment without GUI     |
+| `jbl`   | `juju bootstrap localhost`          | Initializing an lxd cloud environment                 |
+| `jblng` | `juju bootstrap --no-gui localhost` | Initializing an lxd cloud environment without GUI     |
+| `jbm`   | `juju bootstrap microk8s`           | Initializing a MicroK8s cloud environment             |
+| `jbmng` | `juju bootstrap --no-gui microk8s`  | Initializing a MicroK8s cloud environment without GUI |
 
 ### Controller
 
 | Alias    | Command                                                                               | Description                                                       |
 |----------|---------------------------------------------------------------------------------------|-------------------------------------------------------------------|
+| `jctl`   | `juju controllers`                                                                    | List all controllers                                              |
+| `jctlr`  | `juju controllers --refresh`                                                          | List all controllers (download latest details)                    |
 | `jdc`    | `juju destroy-controller --destroy-all-models`                                        | Destroy a controller                                              |
 | `jdc!`   | `juju destroy-controller --destroy-all-models --force --no-wait -y`                   | Destroy a controller                                              |
 | `jdcds`  | `juju destroy-controller --destroy-all-models --destroy-storage`                      | Destroy a controller and associated storage                       |
diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh
index cf89418c6..81fcd6376 100644
--- a/plugins/juju/juju.plugin.zsh
+++ b/plugins/juju/juju.plugin.zsh
@@ -17,11 +17,20 @@ unset completion_file
 #   - `!` means --force --no-wait -y                         #
 #   - `ds` suffix means --destroy-storage                    #
 # ---------------------------------------------------------- #
+alias j="juju"
 alias jam="juju add-model --config logging-config=\"<root>=WARNING; unit=DEBUG\"\
  --config update-status-hook-interval=\"60m\""
 alias jb='juju bootstrap'
+alias jbng='juju bootstrap --no-gui'
+alias jbl='juju bootstrap localhost'
+alias jblng='juju bootstrap --no-gui localhost'
 alias jbm='juju bootstrap microk8s'
+alias jbmng='juju bootstrap --no-gui microk8s'
 alias jc='juju config'
+alias jcld='juju clouds'
+alias jclda='juju clouds --all'
+alias jctl='juju controllers'
+alias jctlr='juju controllers --refresh'
 alias jdc='juju destroy-controller --destroy-all-models'
 alias 'jdc!'='juju destroy-controller --destroy-all-models --force --no-wait -y'
 alias jdcds='juju destroy-controller --destroy-all-models --destroy-storage'
@@ -61,7 +70,8 @@ alias jshc='juju ssh --container'
 alias jshm='juju show-model'
 alias jssl='juju show-status-log'
 alias jstj='juju status --format=json'
-alias jst='juju status --relations --storage --color'
+alias jst='juju status --relations --color'
+alias jsts='juju status --relations --storage --color'
 alias jsu='juju show-unit'
 alias jsw='juju switch'
 
-- 
cgit v1.2.3-70-g09d2


From 564a60608ca3c21d474e27bb436b36ae86c12751 Mon Sep 17 00:00:00 2001
From: sed-i <82407168+sed-i@users.noreply.github.com>
Date: Thu, 3 Feb 2022 02:15:54 -0500
Subject: style(juju)!: don't show storage status in `wjst` for consistency
 (#10426)

BREAKING CHANGE: `wjst` will no longer show storage in the status
output. This is done for consistency with the `jst` and `jsts`
aliases.
---
 plugins/juju/juju.plugin.zsh | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'plugins/juju')

diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh
index 81fcd6376..408692dc7 100644
--- a/plugins/juju/juju.plugin.zsh
+++ b/plugins/juju/juju.plugin.zsh
@@ -164,6 +164,6 @@ jreld() {
 wjst() {
   local interval="${1:-5}"
   shift $(( $# > 0 ))
-  watch -n "$interval" --color juju status --relations --storage --color "$@"
+  watch -n "$interval" --color juju status --relations --color "$@"
 }
 
-- 
cgit v1.2.3-70-g09d2


From aaaa55424ad7c440506024fac86927fc9916348f Mon Sep 17 00:00:00 2001
From: sed-i <82407168+sed-i@users.noreply.github.com>
Date: Mon, 7 Feb 2022 01:34:20 -0500
Subject: refactor(juju)!: use the jsh prefix for `juju show-*` commands
 (#10426)

BREAKING CHANGE: some aliases have been renamed to be consistent with the rest.
Mainly, aliases for `juju show-` commands are renamed to `jsh*`. This also means
that `jsh` and `jshc` have been renamed to `jssh` and `jsshc`. Have a look at the
README for the complete alias changes.
---
 plugins/juju/README.md       | 10 ++++++----
 plugins/juju/juju.plugin.zsh | 11 +++++++----
 2 files changed, 13 insertions(+), 8 deletions(-)

(limited to 'plugins/juju')

diff --git a/plugins/juju/README.md b/plugins/juju/README.md
index 918c08de5..f0c65309c 100644
--- a/plugins/juju/README.md
+++ b/plugins/juju/README.md
@@ -15,6 +15,7 @@ Naming convention:
 
 - `!` suffix: `--force --no-wait -y`.
 - `ds` suffix: `--destroy-storage`.
+- `jsh` prefix means `juju show-*`.
 
 ### General
 
@@ -26,7 +27,7 @@ Naming convention:
 | `jdl`   | `juju debug-log --ms`                       | Display log, with millisecond resolution               |
 | `jdlr`  | `juju debug-log --ms --replay`              | Replay entire log                                      |
 | `jh`    | `juju help`                                 | Show help on a command or other topic                  |
-| `jssl`  | `juju show-status-log`                      | Output past statuses for the specified entity          |
+| `jshsl` | `juju show-status-log`                      | Output past statuses for the specified entity          |
 | `jstj`  | `juju status --format=json`                 | Show status in json format (more detailed)             |
 | `jst`   | `juju status --relations --color`           | Show status, including relations, in color             |
 | `jsts`  | `juju status --relations --storage --color` | Show status, including relations and storage, in color |
@@ -53,6 +54,7 @@ Naming convention:
 | `jdcds`  | `juju destroy-controller --destroy-all-models --destroy-storage`                      | Destroy a controller and associated storage                       |
 | `jdcds!` | `juju destroy-controller --destroy-all-models --destroy-storage --force --no-wait -y` | Destroy a controller and associated storage                       |
 | `jkc`    | `juju kill-controller -y -t 0`                                                        | Forcibly terminate all associated resources for a Juju controller |
+| `jshc`   | `juju show-controller`                                                                | Shows detailed information of a controller                    |
 | `jsw`    | `juju switch`                                                                         | Select or identify the current controller and model               |
 
 ### Model
@@ -84,9 +86,9 @@ Naming convention:
 | `jrmds!` | `juju remove-application --destroy-storage --force --no-wait` | Remove application forcefully, destroying attached storage                |
 | `jrp`    | `juju refresh --path`                                         | Upgrade charm from local charm file                                       |
 | `jsa`    | `juju scale-application`                                      | Set the desired number of application units                               |
-| `jsh`    | `juju ssh`                                                    | Initiate an SSH session or execute a command on a Juju target             |
-| `jshc`   | `juju ssh --container`                                        | Initiate an SSH session or execute a command on a given container         |
-| `jsu`    | `juju show-unit`                                              | Displays information about a unit                                         |
+| `jssh`   | `juju ssh`                                                    | Initiate an SSH session or execute a command on a Juju target             |
+| `jsshc`  | `juju ssh --container`                                        | Initiate an SSH session or execute a command on a given container         |
+| `jshu`   | `juju show-unit`                                              | Displays information about a unit                                         |
 
 ### Storage
 
diff --git a/plugins/juju/juju.plugin.zsh b/plugins/juju/juju.plugin.zsh
index 408692dc7..be8a2c7ae 100644
--- a/plugins/juju/juju.plugin.zsh
+++ b/plugins/juju/juju.plugin.zsh
@@ -16,6 +16,7 @@ unset completion_file
 # Generally,                                                 #
 #   - `!` means --force --no-wait -y                         #
 #   - `ds` suffix means --destroy-storage                    #
+#   - `jsh` prefix means juju show-*                         #
 # ---------------------------------------------------------- #
 alias j="juju"
 alias jam="juju add-model --config logging-config=\"<root>=WARNING; unit=DEBUG\"\
@@ -65,14 +66,16 @@ alias jrp='juju refresh --path'
 alias jrs='juju remove-storage'
 alias 'jrs!'='juju remove-storage --force'
 alias jsa='juju scale-application'
-alias jsh='juju ssh'
-alias jshc='juju ssh --container'
+alias jsha='juju show-application'
+alias jshc='juju show-controller'
 alias jshm='juju show-model'
-alias jssl='juju show-status-log'
+alias jshsl='juju show-status-log'
+alias jshu='juju show-unit'
+alias jssh='juju ssh'
+alias jsshc='juju ssh --container'
 alias jstj='juju status --format=json'
 alias jst='juju status --relations --color'
 alias jsts='juju status --relations --storage --color'
-alias jsu='juju show-unit'
 alias jsw='juju switch'
 
 # ---------------------------------------------------------- #
-- 
cgit v1.2.3-70-g09d2