fix(kvb-org-operator): list only runnable rows in the bash block
Legacy register rows carry a prose title and no directory. They stay in the table but no longer land in the copy-paste bash block as if they were commands; with no runnable row the block is omitted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b4c4cefadd
commit
997a01ccfa
2 files changed
+18
-8
No files matched your search
@@ -226,14 +226,15 @@ def cmd_list(rasci: ModuleType, args: argparse.Namespace) -> int:
|
||||
for number, row in enumerate(listed, 1):
|
||||
values = (number, row["directory"] or "-", row["command"] or "-", row["why"] or "-", row["check"])
|
||||
print("| " + " | ".join(cell(v) for v in values) + " |")
|
||||
print()
|
||||
print("```bash")
|
||||
for row in listed:
|
||||
if row["directory"]:
|
||||
# Trip-wire: legacy rows carry a prose title and no directory; only rows recorded by `add` are commands.
|
||||
runnable = [row for row in listed if row["directory"] and row["command"]]
|
||||
if runnable:
|
||||
print()
|
||||
print("```bash")
|
||||
for row in runnable:
|
||||
print(f"cd {shlex.quote(row['directory'])}")
|
||||
if row["command"]:
|
||||
print(row["command"])
|
||||
print("```")
|
||||
print("```")
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
+11
-2
@@ -194,8 +194,17 @@ class TestOperator(unittest.TestCase):
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertEqual(
|
||||
self._out("list"),
|
||||
[HEADER, "|---|---|---|---|---|", "| 1 | - | sudo reboot | - | manual |", "", "```bash",
|
||||
"sudo reboot", "```"],
|
||||
[HEADER, "|---|---|---|---|---|", "| 1 | - | sudo reboot | - | manual |"],
|
||||
)
|
||||
|
||||
def test_bash_block_skips_legacy_rows_without_directory(self):
|
||||
result = self._run("set", "operator/legacy", "--title", "Rotate leaked credentials", "--status", "queued",
|
||||
script=RASCI)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self._add("reboot", self.base, "sudo reboot", "kernel", "manual")
|
||||
self.assertEqual(
|
||||
self._out("list")[-4:],
|
||||
["```bash", f"cd {self.base}", "sudo reboot", "```"],
|
||||
)
|
||||
|
||||
def test_invalid_input_exits_2(self):
|
||||
|
||||
Reference in new issue
Block a user