From 456efbfa13fb43f8394291aa18e878d8d3acbda1 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 11 Dec 2016 12:06:53 +0100 Subject: Adding CSV export format to container list command. Signed-off-by: Daniel Baumann --- lib/container/list | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/container/list b/lib/container/list index 453b46e..0347c78 100755 --- a/lib/container/list +++ b/lib/container/list @@ -23,9 +23,11 @@ COMMAND="$(basename ${0})" CONFIG="/etc/container-tools/config" MACHINES="/var/lib/machines" +VERSION="$(container version)" + Parameters () { - GETOPT_LONGOPTIONS="all,format:,host:,other,started,stopped," + GETOPT_LONGOPTIONS="all,csv-separator:,format:,host:,other,started,stopped," GETOPT_OPTIONS="a,f:,h:,o,s,t," PARAMETERS="$(getopt --longoptions ${GETOPT_LONGOPTIONS} --name=${COMMAND} --options ${GETOPT_OPTIONS} --shell sh -- ${@})" @@ -46,6 +48,11 @@ Parameters () shift 1 ;; + --csv-separator) + CSV_SEPARATOR="${2}" + shift 2 + ;; + -f|--format) FORMAT="${2}" shift 2 @@ -86,7 +93,7 @@ Parameters () Usage () { - echo "Usage: container ${COMMAND} [-a|--all] [--format FORMAT] [-h|--host HOSTNAME] [-o|--other] [-s|--started] [-t|--stopped]" >&2 + echo "Usage: container ${COMMAND} [-a|--all] [--csv-separator SEPARATOR] [--format FORMAT] [-h|--host HOSTNAME] [-o|--other] [-s|--started] [-t|--stopped]" >&2 exit 1 } @@ -96,6 +103,8 @@ LIST="${LIST:-started stopped}" FORMAT="${FORMAT:-cli}" HOST="${HOST:-$(hostname -f)}" +CSV_SEPARATOR="${CSV_SEPARATOR:-,}" + # Run List () { @@ -104,6 +113,10 @@ List () printf "%-80s %-29s\n" "${STATUS} ${BLUE}${CONTAINER}${NORMAL}" "${YELLOW}${ADDRESS}${NORMAL}" ;; + csv) + echo "${HOST}${CSV_SEPARATOR}${CONTAINER}${CSV_SEPARATOR}${STATE}${CSV_SEPARATOR}${ADDRESS}" + ;; + shell) echo "${CONTAINER}" ;; @@ -122,6 +135,15 @@ case "${FORMAT}" in cat << EOF ${WHITE} ${NORMAL} Container IPv4 Address(es) -------------------------------------------------------------------------------- +EOF + + ;; + + csv) + +cat << EOF +# container-tools version ${VERSION} +Host${CSV_SEPARATOR}Container${CSV_SEPARATOR}Status${CSV_SEPARATOR}IPv4-Address EOF ;; -- cgit v1.2.3