new: Add a --terse option

This causes `xfstestsdb new` to only print out the new runid, making it
easier for scripting.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2024-04-25 17:05:51 -04:00
parent 79fae64f37
commit 4600258721
2 changed files with 14 additions and 3 deletions

View File

@ -29,6 +29,12 @@ class TestNew(unittest.TestCase):
r"created run #1 with test device '/dev/vdb1' "
r"\[[\d\-\: ]+\]\n")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
def test_new_terse(self, mock_stdout: io.StringIO):
"""Test running `xfstestsdb new --terse`."""
self.xfstestsdb.run(["new", "--terse", "/dev/vdb1"])
self.assertEqual(mock_stdout.getvalue(), "1\n")
@unittest.mock.patch("sys.stderr", new_callable=io.StringIO)
def test_new_error(self, mock_stderr: io.StringIO):
"""Test running the `xfstestsdb new` command with invalid input."""

View File

@ -16,6 +16,8 @@ class Command(commands.Command):
self.parser.add_argument("device", metavar="device", nargs=1,
help="the test device used for"
"this xfstests run")
self.parser.add_argument("--terse", action="store_true",
help="output only the new runid")
def do_command(self, args: argparse.Namespace) -> None:
"""Create a new row in the xfstestsdb_runs table."""
@ -24,6 +26,9 @@ class Command(commands.Command):
datetime(timestamp, 'localtime') as timestamp""",
args.device[0])
row = cur.fetchone()
print(f"created run #{row['runid']}", end=" ")
print(f"with test device '{row['device']}'", end=" ")
print(f"[{row['timestamp']}]")
if args.terse:
print(row['runid'])
else:
print(f"created run #{row['runid']}", end=" ")
print(f"with test device '{row['device']}'", end=" ")
print(f"[{row['timestamp']}]")