diff --git a/tests/test_new.py b/tests/test_new.py index 36fa8b7..819491b 100644 --- a/tests/test_new.py +++ b/tests/test_new.py @@ -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.""" diff --git a/xfstestsdb/new.py b/xfstestsdb/new.py index 10f6c0d..de08e94 100644 --- a/xfstestsdb/new.py +++ b/xfstestsdb/new.py @@ -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']}]")