Skip to content
Snippets Groups Projects
Commit a3bc8ea6 authored by Seblu's avatar Seblu
Browse files

better list displaying

parent 4f55501c
No related branches found
No related tags found
No related merge requests found
...@@ -10,7 +10,9 @@ import sys ...@@ -10,7 +10,9 @@ import sys
import re import re
import pprint import pprint
import ConfigParser import ConfigParser
from optparse import OptionParser
import cccli
from cccli.exception import * from cccli.exception import *
from cccli.printer import color from cccli.printer import color
...@@ -170,14 +172,33 @@ class Command(object): ...@@ -170,14 +172,33 @@ class Command(object):
def cmd_list(self, argv): def cmd_list(self, argv):
'''List objects''' '''List objects'''
if len(argv) == 1:
argv.append("a")
try: try:
objs = self.cli.rpc.list(str.join("", argv[1:])) oparser = OptionParser(prog="list")
oparser.add_option("-t", action="store_true", dest="table")
(options, args) = oparser.parse_args(argv[1:])
except SystemExit:
return
if len(args) == 0:
args.append("a")
try:
objs = self.cli.rpc.list(str.join("", args))
except RpcError as e: except RpcError as e:
raise cmdError("RPCError: %s"%str(e)) raise cmdError("RPCError: %s"%str(e))
if len(objs) == 0: if len(objs) == 0:
return return
if options.table:
self._list_table(objs)
else:
self._list(objs)
cmd_list.usage = "list [tql]"
def _list(self, objs):
for o in objs:
id = o.pop("id")
tags = " ".join([ "%s%s:%s%s"%(color["green"], t, color["reset"], v) for (t,v) in o.items() ])
self.printer.out("%sid:%s%s %s"%(color["green"], color["yellow"], id, tags))
def _list_table(self, objs):
# get all tag list # get all tag list
tags = dict() tags = dict()
for o in objs: for o in objs:
...@@ -186,17 +207,18 @@ class Command(object): ...@@ -186,17 +207,18 @@ class Command(object):
# extract id info # extract id info
idsize = tags.pop("id") idsize = tags.pop("id")
# print titles # print titles
self.printer.out("%s%s%s"%(color["yellow"], "id".ljust(idsize+1), color["reset"]), nl=" ") self.printer.out(color["green"], nl="")
self.printer.out("id".ljust(idsize+1), nl=" ")
for t,v in tags.items(): for t,v in tags.items():
self.printer.out(t.ljust(v), nl=" ") self.printer.out(t.ljust(v), nl=" ")
self.printer.out() self.printer.out(color["reset"])
# print obj # print obj
for obj in objs: for obj in objs:
self.printer.out("%s%s%s"%(color["yellow"], obj.pop("id").ljust(idsize+1), color["reset"]) ,nl=" ") self.printer.out("%s%s%s"%(color["yellow"], obj.pop("id").ljust(idsize+1), color["reset"]) ,nl=" ")
for (t, v) in tags.items(): for (t, v) in tags.items():
self.printer.out(str(obj.get(t, "")).ljust(v) ,nl=" ") self.printer.out(str(obj.get(t, "")).ljust(v) ,nl=" ")
self.printer.out() self.printer.out()
cmd_list.usage = "list [tql]"
def _startstopsdestroypauseresume(self, argv): def _startstopsdestroypauseresume(self, argv):
# arg stuff # arg stuff
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment