diff --git a/cccli/command.py b/cccli/command.py index a0ada544aa5c55f90cc0e84a479ee16f107936d3..58aca87aa9105a1828ccb11015dc9caf2b31b30f 100644 --- a/cccli/command.py +++ b/cccli/command.py @@ -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): diff --git a/cccli/printer.py b/cccli/printer.py index d447bbfd13c057ef4d790a058fe410692732becc..6a1f00491fb283ae94e92e5e4bb735adc34f8d6a 100644 --- a/cccli/printer.py +++ b/cccli/printer.py @@ -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: