# Copyright 2023 (c) Anna Schumaker. """The `xfstestsdb tag` command.""" import argparse import errno import sys from . import commands from . import sqlite class Command(commands.Command): """The `xfstestsdb tag` command.""" def __init__(self, subparser: argparse.Action, sql: sqlite.Connection) -> None: """Set up the tag command.""" super().__init__(subparser, sql, "tag", help="tag an xfstests run") self.parser.add_argument("runid", metavar="runid", nargs=1, type=int, help="runid of the xfstests run to tag") self.parser.add_argument("tag", metavar="tag", nargs=1, help="tag to add to the xfstests run") def do_command(self, args: argparse.Namespace) -> None: """Create a new row in the xfstestsdb_tags table.""" if self.sql("SELECT rowid FROM xfstests_runs WHERE rowid=?", args.runid[0]).fetchone() is None: print(f"error: run #{args.runid[0]} does not exist", file=sys.stderr) sys.exit(errno.ENOENT) cur = self.sql("INSERT INTO tags (runid, tag) VALUES (?, ?)", args.runid[0], args.tag[0]) if cur is not None: print(f"tag '{args.tag[0]}' added to run #{args.runid[0]}")