summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xlib/container/list36
-rw-r--r--share/bash-completion/container2
-rw-r--r--share/man/container-list.1.txt5
3 files changed, 41 insertions, 2 deletions
diff --git a/lib/container/list b/lib/container/list
index 0347c78..a07b85b 100755
--- a/lib/container/list
+++ b/lib/container/list
@@ -117,6 +117,18 @@ List ()
echo "${HOST}${CSV_SEPARATOR}${CONTAINER}${CSV_SEPARATOR}${STATE}${CSV_SEPARATOR}${ADDRESS}"
;;
+ json)
+
+cat << EOF
+ {
+ "name": "${CONTAINER}",
+ "status": "${STATE}",
+ "ipv4Address": "${ADDRESS}",
+ },
+EOF
+
+ ;;
+
shell)
echo "${CONTAINER}"
;;
@@ -147,6 +159,21 @@ Host${CSV_SEPARATOR}Container${CSV_SEPARATOR}Status${CSV_SEPARATOR}IPv4-Address
EOF
;;
+
+ json)
+
+cat << EOF
+{
+ "container-tools": {
+ "version": "${VERSION}",
+ },
+ "host": {
+ "name": "${HOST}",
+ },
+ "container": [
+EOF
+
+ ;;
esac
CONTAINERS="$(cd "${MACHINES}" 2>/dev/null && find -maxdepth 1 -type d -and -not -name '.container-tools' -and -not -name 'container-tools' -and -not -name 'lost+found' -and -not -name '.snap' -and -not -name '.snapshot' -printf '%P\n' | sort)"
@@ -226,4 +253,13 @@ cat << EOF
EOF
;;
+
+ json)
+
+cat << EOF
+ ],
+}
+EOF
+
+ ;;
esac
diff --git a/share/bash-completion/container b/share/bash-completion/container
index 13bcdf3..3b0e033 100644
--- a/share/bash-completion/container
+++ b/share/bash-completion/container
@@ -139,7 +139,7 @@ _container()
;;
-f|--format)
- opts="cli csv shell"
+ opts="cli csv json shell"
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
;;
diff --git a/share/man/container-list.1.txt b/share/man/container-list.1.txt
index 3e4498b..488b718 100644
--- a/share/man/container-list.1.txt
+++ b/share/man/container-list.1.txt
@@ -50,7 +50,7 @@ The following container options are available, defaults to *--started --stopped*
Specify custom CSV separator, defaults to ','.
*-f, --format='FORMAT'*::
- Use format to list container. Currently available formats are 'cli' (default), 'csv', or 'shell'.
+ Use format to list container. Currently available formats are 'cli' (default), 'csv', 'json', or 'shell'.
*-h, --host='HOSTNAME'*::
List only container that are enabled for automatic start on the specified hostname. Defaults to list containers of the local system only. Using 'all' shows all container regardless of any automatic start configuration.
@@ -75,6 +75,9 @@ EXAMPLES
*Create a CSV export of all started and stopped containers:*::
sudo container list -f csv
+*Create a JSON export of all started and stopped containers:*::
+ sudo container list -f json
+
*Create a shell export of all started and stopped containers:*::
sudo container list -f shell