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

better list display

parent 93b1a976
No related branches found
No related tags found
No related merge requests found
......@@ -172,11 +172,28 @@ class Command(object):
'''List objects'''
if len(argv) == 1:
argv.append("a")
items = self.cli.rpc.list(str.join("", argv[1:]))
for item in items:
pprint.pprint(item)
#for key, val in item.items():
# self.printer.out("%s: %s "%(key, val))
try:
objs = self.cli.rpc.list(str.join("", argv[1:]))
except RpcError as e:
raise cmdError("RPCError: %s"%str(e))
# get all tag list
tags = dict()
for o in objs:
for t,v in o.items():
tags[t] = max(len(str(v)), tags.get(t, len(str(t))))
# extract id info
idsize = tags.pop("id")
# print titles
self.printer.out("%s%s%s"%(color["yellow"], "id".ljust(idsize+1), color["reset"]), nl=" ")
for t,v in tags.items():
self.printer.out(t.ljust(v), nl=" ")
self.printer.out()
# print obj
for obj in objs:
self.printer.out("%s%s%s"%(color["yellow"], obj.pop("id").ljust(idsize+1), color["reset"]) ,nl=" ")
for (t, v) in tags.items():
self.printer.out(str(obj.get(t, "")).ljust(v) ,nl=" ")
self.printer.out()
cmd_list.usage = "list [tql]"
def _startstopsdestroypauseresume(self, argv):
......
......@@ -68,7 +68,7 @@ class Printer(object):
self.history.load(self.historyfile)
self.history.maxsize(self.historysize)
def out(self, message, fd=sys.stdout, nl=os.linesep, flush=True):
def out(self, message="", fd=sys.stdout, nl=os.linesep, flush=True):
'''Print a message in fd ended by nl'''
fd.write("%s%s"%(message, nl))
if flush:
......
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