From 1af970e428fcca786a579b85e9199f8cd7efa316 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 7 Oct 2012 19:24:51 +0200 Subject: o Adding a -P option to 'list' to give more parsable output. --- app | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 52 insertions(+), 5 deletions(-) diff --git a/app b/app index 2363f19..137f532 100755 --- a/app +++ b/app @@ -350,17 +350,61 @@ method_stop() { method_list() { - printf "%-20s %-20s %-20s\n" "Name" "Instance" "Version" + local mode="pretty" + + while getopts "P" opt + do + case $opt in + P) + mode="parseable" + shift + ;; + \?) + install_usage "Invalid option: -$OPTARG" + ;; + esac + done if [ ! -r $BASEDIR/.app/var/list ] then return fi - sort $BASEDIR/.app/var/list | (export IFS=:; while read instance name version - do - printf "%-20s %-20s %-20s\n" "$name" "$instance" "$version" - done) + x="$@" + if [ -z "$x" ] + then + vars="name instance version" + else + vars="$@" + fi + + if [ $mode = "pretty" ] + then + printf "%-20s %-20s %-20s\n" "Name" "Instance" "Version" + fi + + sort $BASEDIR/.app/var/list | ( + IFS=:; while read instance name version + do + if [ $mode = "pretty" ] + then + printf "%-20s %-20s %-20s\n" "$name" "$instance" "$version" + else + line="" + IFS=" "; for var in $vars + do + eval v=\$$var + if [ -z "$line" ] + then + line="$line$v" + else + line="$line:$v" + fi + done + echo $line + fi + done + ) } method_usage() { @@ -369,6 +413,9 @@ method_usage() { echo "Available methods:" >&2 echo " install - Installs an application" >&2 echo " list - List all installed applications" >&2 + echo " start - Starts an applications" >&2 + echo " stop - Stops an applications" >&2 + echo " conf - Application configuration management" >&2 echo "" >&2 echo "Run '$0 ' to get more help" >&2 } -- cgit v1.2.3