Commit 61fbb013 authored by Seblu's avatar Seblu
Browse files

command tags take tql

parent e4c2e492
Loading
Loading
Loading
Loading
+27 −10
Original line number Diff line number Diff line
@@ -326,16 +326,33 @@ class Command(object):

    def cmd_tags(self, argv):
        '''List static tags on an account (current by default)'''
        if len(argv) == 1:
            argv.append(self.cli.settings["login"])
        for a in argv[1:]:
        # Parse argline
        try:
            oparser = OptionParser(prog=argv[0])
            oparser.add_option("--raw", action="store_true", dest="raw",
                               help="Don't append filter on request")
            (options, args) = oparser.parse_args(argv[1:])
        except SystemExit:
            return
        # append current login if nothing asked
        if len(args) == 0:
            tql = "a=%s"%self.cli.settings["login"]
        else:
            tql = "".join(args)
        # update tql if mode
        if not options.raw:
            tql += "&a"
        # ask server
        try:
                tl = self.cli.rpc.call("tags", a)
                tags = " ".join([ "%s%s:%s%s"%(color["green"], t, color["reset"], v) for (t,v) in tl.items() ])
                self.printer.out("%sa:%s%s%s %s"%(color["green"], color["yellow"], a, color["reset"], tags))
            objs = self.cli.rpc.call("tags", tql)
        except RpcError as e:
            raise cmdError("RPCError: %s"%str(e))
    cmd_tags.usage = "tags [account]"
        # display answer
        for o in objs:
            id = o.pop("id")
            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))
    cmd_tags.usage = "tags [--raw] [--help] [account tql]"

    def cmd_addtag(self, argv):
        '''Add/Modify a static tag on an account'''