list: Don't show empty xunits or tags

Up until now, we've been appending an extra column to the listed output
but allowing it to have empty entries. I'm changing this to filter out
NULL entries, since it turns out that's what I want when I use the
--tags option. I also updated the --xunits option to be consistent.

Signed-off-by: Anna Schumaker <anna@nowheycreamery.com>
This commit is contained in:
Anna Schumaker 2023-11-07 15:13:09 -05:00
parent 7e6f944cde
commit 2e85870c87
2 changed files with 11 additions and 8 deletions

View File

@ -30,6 +30,7 @@ class TestList(unittest.TestCase):
self.xfstestsdb.run(["tag", "1", "mytag1"])
self.xfstestsdb.run(["tag", "1", "mytag2"])
self.xfstestsdb.run(["tag", "3", "mytag3"])
self.xfstestsdb.run(["tag", "3", "othertag"])
self.xfstestsdb.sql.executemany("""UPDATE xfstests_runs SET timestamp=?
WHERE rowid=?""", (timestamp, 1),
@ -116,13 +117,12 @@ class TestList(unittest.TestCase):
self.xfstestsdb.run(["list", "--color", "none", "--tags"])
self.assertEqual(mock_stdout.getvalue(),
"""
+-----+---------------------+-----------+---------------+
| run | timestamp | device | tags |
+-----+---------------------+-----------+---------------+
| 1 | 2023-01-01 12:59:59 | /dev/vda1 | mytag1,mytag2 |
| 2 | 2023-01-02 12:59:59 | /dev/vda2 | |
| 3 | 2023-01-03 12:59:59 | /dev/vdb1 | mytag3 |
+-----+---------------------+-----------+---------------+
+-----+---------------------+-----------+-----------------+
| run | timestamp | device | tags |
+-----+---------------------+-----------+-----------------+
| 1 | 2023-01-01 12:59:59 | /dev/vda1 | mytag1,mytag2 |
| 3 | 2023-01-03 12:59:59 | /dev/vdb1 | mytag3,othertag |
+-----+---------------------+-----------+-----------------+
""")
@unittest.mock.patch("sys.stdout", new_callable=io.StringIO)
@ -170,7 +170,6 @@ class TestList(unittest.TestCase):
| run | timestamp | device | xunits |
+-----+---------------------+-----------+---------------+
| 1 | 2023-01-01 12:59:59 | /dev/vda1 | test-1,test-2 |
| 2 | 2023-01-02 12:59:59 | /dev/vda2 | |
| 3 | 2023-01-03 12:59:59 | /dev/vdb1 | test-3 |
+-----+---------------------+-----------+---------------+
""")

View File

@ -52,6 +52,8 @@ class Command(commands.Command):
if isinstance(args.tags, str):
filter.append("tag GLOB ?")
sql_args.append(args.tags)
else:
filter.append("tag IS NOT NULL")
if args.timestamp:
filter.append("timestamp GLOB ?")
@ -62,6 +64,8 @@ class Command(commands.Command):
if isinstance(args.xunits, str):
filter.append("xunit GLOB ?")
sql_args.append(args.xunits)
else:
filter.append("xunit IS NOT NULL")
if len(filter) > 0:
sql_where = " WHERE " + " AND ".join(filter) + " "