Pi66

merodi
A markdown-based static site generator.
git clone https://git.pi66.xyz/merodi

← back to log

feat: add global version option and show help by default

author: pi66
date: 2026-07-21 18:38
hash: b8ff9cf28ab632e421b77ad1dc9da09088ac6b07

Diffstat:

M

src/main.py
13 ++++++++++++++++++++++++++++--
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
diff --git a/src/main.py b/src/main.py
index 0a08d51..73b78a1 100755
--- a/src/main.py
+++ b/src/main.py
@@ -14,7 +14,8 @@ def main():
     common.add_argument("--no-color", action="store_true")

     parser = ArgumentParser()
-    sub_parser = parser.add_subparsers(dest="command",required=True)
+    parser.add_argument("--version", action="store_true")
+    sub_parser = parser.add_subparsers(dest="command")

     init_parser = sub_parser.add_parser("init", parents=[common])
     init_parser.add_argument("path", nargs="?")
@@ -32,6 +33,16 @@ def main():
     build_parser.add_argument("--file", nargs=2, metavar=("SRC", "DEST"))

     args = parser.parse_args()
+
+    if args.version:
+        from importlib.metadata import version
+        info(version("merodi"), title="VERSION")
+        return
+
+    if args.command is None:
+        parser.print_help()
+        return
+
     settings.VERBOSE  =  args.verbose  or ( environ.get("VERBOSE")  in ["true", "1"])
     settings.NO_COLOR =  args.no_color or ( environ.get("NO_COLOR") in ["true", "1"])