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

commands tags use TqlCommand

parent 24b00270
No related branches found
No related tags found
No related merge requests found
......@@ -8,31 +8,22 @@ CloudControl tag releated commands
from cccli.exception import *
from sjrpc.core.exceptions import *
from cccli.printer import Printer, color
from cccli.command.command import OptionCommand, TqlCommand
from cccli.command.command import TqlCommand
from optparse import OptionParser
class Command_tags(OptionCommand):
'''List static tags on an account'''
class Command_tags(TqlCommand):
'''List only static tags'''
def __init__(self, cli, argv0):
OptionCommand.__init__(self, cli, argv0)
TqlCommand.__init__(self, cli, argv0)
self.set_usage("%prog [options] [tql]")
self.add_option("--raw", action="store_true", dest="raw",
help="Don't append filter on request")
self.add_option("-n", "--no-tagdisplay", action="store_false", dest="tagdisplay", default=True,
help="No tag display system")
def __call__(self, argv):
# Parse argline
self.parse_args(argv)
# handle tagdisplay
if self.options.tagdisplay:
self.td = self.cli.tagdisplay.resolve
self.tc = self.cli.tagdisplay.color
else:
self.td = lambda tagname, tagvalue: unicode(tagvalue)
self.tc = lambda tagname: color["reset"]
# append current login if nothing asked
if len(self.args) == 0:
tql = "a=%s"%self.cli.settings["login"]
......@@ -43,18 +34,18 @@ class Command_tags(OptionCommand):
tql += "&a"
# ask server
try:
objs = self.cli.rpc.call("tags", tql)
objs = self.rpccall("tags", tql, _status=False)
except RpcError as e:
raise cmdError("RPCError: %s"%str(e))
# display answer
for o in objs:
id = self.td("id", o.pop("id"))
tags = " ".join([ "%s%s:%s%s"%(color["reset"],
tid = self.tdr("id", o.pop("id"))
tags = " ".join([ "%s%s:%s%s"%(self.tdtc(t),
t,
self.tc(t),
self.td(t, v))
self.tdc(t),
self.tdr(t, v))
for (t,v) in o.items() ])
self.printer.out("%sid:%s%s %s%s"%(color["reset"], color["lblue"], id, tags, color["reset"]))
self.printer.out("%sid=%s%s %s%s"%(self.tdtc("id"), self.tdc("id"), tid, tags, color["reset"]))
class Command_addtag(TqlCommand):
......
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