Loading cccli/command.py +24 −3 Original line number Diff line number Diff line Loading @@ -172,7 +172,10 @@ class Command(object): '''List objects''' try: oparser = OptionParser(prog="list") oparser.add_option("-t", action="store_true", dest="table") oparser.add_option("-c", action="store_true", dest="table", help="column aligment display") oparser.add_option("-l", action="store_true", dest="align", help="line aligment display") (options, args) = oparser.parse_args(argv[1:]) except SystemExit: return Loading @@ -184,11 +187,13 @@ class Command(object): raise cmdError("RPCError: %s"%str(e)) if len(objs) == 0: return if options.table: if options.align: self._list_align(objs) elif options.table: self._list_table(objs) else: self._list(objs) cmd_list.usage = "list [-t] [--help] <tql>" cmd_list.usage = "list [-t] [-a] [--help] <tql>" def _list(self, objs): for o in objs: Loading @@ -196,6 +201,22 @@ class Command(object): 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 %s"%(color["green"], color["yellow"], id, color["reset"], tags)) def _list_align(self, objs): # 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)))) for o in objs: id = str(o.pop("id")) line = "%sid:%s%s%s"%(color["green"], color["yellow"], id.ljust(tags["id"] + 2), color["reset"]) taglist = o.keys() taglist.sort() for tagname in taglist: line += "%s%s:%s%s"%(color["green"], tagname, color["reset"], str(o[tagname]).ljust(tags[tagname] + 1)) self.printer.out(line) def _list_table(self, objs): # get all tag list tags = dict() Loading Loading
cccli/command.py +24 −3 Original line number Diff line number Diff line Loading @@ -172,7 +172,10 @@ class Command(object): '''List objects''' try: oparser = OptionParser(prog="list") oparser.add_option("-t", action="store_true", dest="table") oparser.add_option("-c", action="store_true", dest="table", help="column aligment display") oparser.add_option("-l", action="store_true", dest="align", help="line aligment display") (options, args) = oparser.parse_args(argv[1:]) except SystemExit: return Loading @@ -184,11 +187,13 @@ class Command(object): raise cmdError("RPCError: %s"%str(e)) if len(objs) == 0: return if options.table: if options.align: self._list_align(objs) elif options.table: self._list_table(objs) else: self._list(objs) cmd_list.usage = "list [-t] [--help] <tql>" cmd_list.usage = "list [-t] [-a] [--help] <tql>" def _list(self, objs): for o in objs: Loading @@ -196,6 +201,22 @@ class Command(object): 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 %s"%(color["green"], color["yellow"], id, color["reset"], tags)) def _list_align(self, objs): # 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)))) for o in objs: id = str(o.pop("id")) line = "%sid:%s%s%s"%(color["green"], color["yellow"], id.ljust(tags["id"] + 2), color["reset"]) taglist = o.keys() taglist.sort() for tagname in taglist: line += "%s%s:%s%s"%(color["green"], tagname, color["reset"], str(o[tagname]).ljust(tags[tagname] + 1)) self.printer.out(line) def _list_table(self, objs): # get all tag list tags = dict() Loading