diff --git a/share/pot/list.sh b/share/pot/list.sh index 6f88dd1..f886d56 100644 --- a/share/pot/list.sh +++ b/share/pot/list.sh @@ -24,32 +24,67 @@ list-help() # $1 pot name _ls_info_pot() { - local _pname _cdir _lvl + local _pname _format _cdir _lvl _active _pname=$1 + _format=$2 _cdir="${POT_FS_ROOT}/jails/$_pname/conf" _lvl=$( _get_conf_var "$_pname" pot.level) - printf "pot name : %s\\n" "$_pname" - printf "\\tnetwork : %s\\n" "$( _get_conf_var "$_pname" network_type)" + if [ "$_format" = "json" ]; then + printf "{" + fi + if [ "$_format" = "json" ]; then + printf "\"name\":\"%s\"," "$_pname" + printf "\"network\":\"%s\"," "$( _get_conf_var "$_pname" network_type)" + else + printf "pot name : %s\\n" "$_pname" + printf "\\tnetwork : %s\\n" "$( _get_conf_var "$_pname" network_type)" + fi + if [ "$( _get_conf_var "$_pname" network_type)" != "inherit" ]; then - printf "\\tip : %s\\n" "$( _get_ip_var "$_pname" )" + if [ "$_format" = "json" ]; then + printf "\"ip\":\"%s\"," "$( _get_ip_var "$_pname" )" + else + printf "\\tip : %s\\n" "$( _get_ip_var "$_pname" )" + fi fi if _is_pot_running "$_pname" ; then - printf "\\tactive : true\\n" + _active=true else - printf "\\tactive : false\\n" + _active=false fi - if _is_verbose ; then - printf "\\tbase : %s\\n" "$( _get_conf_var "$_pname" pot.base)" - printf "\\tlevel : %s\\n" "$_lvl" + if [ "$_format" = "json" ]; then + printf "\"active\":\"%s\"" "$_active" + else + printf "\\tactive : %s\\n" "$_active" + fi + if _is_verbose ; then + if [ "$_format" = "json" ]; then + printf ",\"base\":\"%s\"," "$( _get_conf_var "$_pname" pot.base)" + printf "\"level\":\"%s\"," "$_lvl" + else + printf "\\tbase : %s\\n" "$( _get_conf_var "$_pname" pot.base)" + printf "\\tlevel : %s\\n" "$_lvl" + fi if [ "$_lvl" -eq 2 ]; then printf "\\tbase pot : %s\\n" "$( _get_conf_var "$_pname" pot.potbase)" fi - printf "\\tdatasets:\\n" - _print_pot_fscomp "$_cdir/fscomp.conf" - printf "\\tsnapshot:\\n" - _print_pot_snaps "$_pname" + if [ "$_format" = "json" ]; then + printf "\"datasets\":" + _print_pot_fscomp_json "$_cdir/fscomp.conf" + printf ",\"snapshot\":" + _print_pot_snaps_json "$_pname" + else + printf "\\tdatasets:\\n" + _print_pot_fscomp "$_cdir/fscomp.conf" + printf "\\tsnapshot:\\n" + _print_pot_snaps "$_pname" + fi + fi + if [ "$_format" = "json" ]; then + printf "}" + else + echo fi - echo } _ls_pots() @@ -72,7 +107,7 @@ _ls_pots() printf "[" fi _i=0 - set -- $_pots + set -- "$_pots" for _p do if [ "$_q" = "quiet" ]; then if [ "$_format" = "json" ]; then @@ -85,7 +120,7 @@ _ls_pots() fi _i=$(( _i + 1 )) # if not the last item add , - if [ "$_i" != "$#" -a "$_format" = "json" ]; then + if [ "$_i" != "$#" ] && [ "$_format" = "json" ]; then printf "," fi done