Commit e5d6941d authored by Seblu's avatar Seblu
Browse files

better list display

parent 93b1a976
Loading
Loading
Loading
Loading
+22 −5
Original line number Diff line number Diff line
@@ -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):
+1 −1
Original line number Diff line number Diff line
@@ -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: