office: every subcommand answers --help, and delete refuses a system folder like /tmp or /home

This commit is contained in:
Sam
2026-11-13 17:27:14 +11:00
parent 0717697f03
commit 33a06da232
7 changed files with 23 additions and 1 deletions

View File

@@ -64,6 +64,9 @@ def pages(cfg, folder):
def main(): def main():
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
h.say(__doc__.strip())
return 0
opts = parse(sys.argv[1:]) opts = parse(sys.argv[1:])
folder = os.path.abspath(os.path.expanduser(opts["folder"])) folder = os.path.abspath(os.path.expanduser(opts["folder"]))
cfg = pj.load(folder) cfg = pj.load(folder)

View File

@@ -33,7 +33,7 @@ def exists(root):
def load(root): def load(root):
p = path(root) p = path(root)
if not os.path.isfile(p): if not os.path.isfile(p):
raise h.Refused(2, "no %s here; run bin/office %s first" % (REL, root)) raise h.Refused(2, "no %s here; run: office %s" % (REL, root))
with open(p, "rb") as f: with open(p, "rb") as f:
return tomllib.load(f) return tomllib.load(f)

View File

@@ -29,6 +29,9 @@ LOCK = "/tmp/paperclip-harness-merge.lock"
def main(): def main():
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
h.say(__doc__.strip())
return 0
args = [a for a in sys.argv[1:]] args = [a for a in sys.argv[1:]]
check_only = "--check" in args check_only = "--check" in args
args = [a for a in args if not a.startswith("--")] args = [a for a in args if not a.startswith("--")]

View File

@@ -81,6 +81,13 @@ def main():
if not os.path.isdir(folder): if not os.path.isdir(folder):
raise h.Refused(2, "no folder at %s" % folder) raise h.Refused(2, "no folder at %s" % folder)
# A project folder is a leaf, not a place where other things live. Refusing
# these is the difference between a mistake and a disaster.
forbidden = {"/", "/home", "/tmp", "/var", "/etc", "/usr", "/nix",
os.path.expanduser("~")}
if folder.rstrip("/") in forbidden:
raise h.Refused(2, "%s is not a project folder; give the folder of one project" % folder)
cfg = {} cfg = {}
if pj.exists(folder): if pj.exists(folder):
try: try:

View File

@@ -33,6 +33,9 @@ PAGES = ["tree", "reply", "log", "new"]
def main(): def main():
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
h.say(__doc__.strip())
return 0
argv = sys.argv[1:] argv = sys.argv[1:]
args = [a for a in argv if not a.startswith("--")] args = [a for a in argv if not a.startswith("--")]
if not args: if not args:

View File

@@ -17,6 +17,9 @@ import harness as h # noqa: E402
def main(): def main():
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
h.say(__doc__.strip())
return 0
args = [a for a in sys.argv[1:] if not a.startswith("--")] args = [a for a in sys.argv[1:] if not a.startswith("--")]
post = "--post" in sys.argv post = "--post" in sys.argv
if len(args) != 1: if len(args) != 1:

View File

@@ -83,6 +83,9 @@ def ask(state, question):
def main(): def main():
if "-h" in sys.argv[1:] or "--help" in sys.argv[1:]:
h.say(__doc__.strip())
return 0
args = [a for a in sys.argv[1:] if not a.startswith("--")] args = [a for a in sys.argv[1:] if not a.startswith("--")]
if not args: if not args:
h.say("usage: office triage <task> [--ask next|failure]") h.say("usage: office triage <task> [--ask next|failure]")