Johan Rong 1 日 前
親
コミット
cc565230ea
2 ファイル変更、34 行追加、7 行削除
  1. 7 0
      flake.nix
  2. 27 7
      src/zelkelbt/__main__.py

+ 7 - 0
flake.nix

@@ -16,11 +16,17 @@
       pythonEnv = pkgs.python3.withPackages (ps: with ps; [
         rich
       ]);
+
+      zk = pkgs.writeShellScriptBin "zk" ''
+        export PYTHONPATH="${builtins.toString ./.}:$PYTHONPATH"
+        exec ${pythonEnv}/bin/python -m src.zelkelbt "$@"
+      '';
     in
     {
       devShells.${system}.default = pkgs.mkShell {
         packages = with pkgs; [
           pythonEnv
+          zk
           ruff
           llvmPackages_latest.llvm
           clang
@@ -28,6 +34,7 @@
 
         shellHook = ''
           export LD_LIBRARY_PATH="${pkgs.stdenv.cc.cc.lib}/lib:$LD_LIBRARY_PATH"
+          export PYTHONPATH="${builtins.toString ./.}:$PYTHONPATH"
         '';
       };
     };

+ 27 - 7
src/zelkelbt/__main__.py

@@ -1,6 +1,7 @@
 import argparse
+import shutil
 import subprocess
-import sys
+from pathlib import Path
 
 from src.zelkelbt.build import build_package
 from src.zelkelbt.config import get_config
@@ -15,7 +16,7 @@ if __name__ == "__main__":
     )
 
     parser.add_argument(
-        "-V",
+        "-v",
         "--version",
         action="version",
         version="zk 1.0.0",
@@ -49,7 +50,7 @@ if __name__ == "__main__":
         help="Enable release build mode",
     )
 
-    clean_parser = subparsers.add_parser("clean", help="Remove the build/ directory")
+    clean_parser = subparsers.add_parser("clean", help="Remove the 'target/' directory")
 
     run_parser = subparsers.add_parser(
         "run", aliases=["r"], help="Compile and run the current package"
@@ -59,6 +60,22 @@ if __name__ == "__main__":
         action="store_true",
         help="Enable debug output while running the package",
     )
+    run_group = run_parser.add_mutually_exclusive_group()
+    run_group.add_argument(
+        "--debug",
+        dest="run_mode",
+        action="store_const",
+        const="debug",
+        default="debug",
+        help="Enable debug run mode",
+    )
+    run_group.add_argument(
+        "--release",
+        dest="run_mode",
+        action="store_const",
+        const="release",
+        help="Enable release run mode",
+    )
 
     parser.usage = "zk [COMMAND] [OPTIONS]"
 
@@ -68,11 +85,14 @@ if __name__ == "__main__":
         config = get_config()
         build_package(args.build_mode, config, args.debug_info)
     elif args.command == "clean":
-        print("TODO: implement clean command")
-        sys.exit(1)
+        get_config()
+
+        target_dir = Path("target")
+        if target_dir.exists():
+            shutil.rmtree(target_dir)
     elif args.command in ["run", "r"]:
         config = get_config()
-        build_package("debug", config, args.debug_info)
+        build_package(args.run_mode, config, args.debug_info)
         subprocess.run([f"./target/debug/{config['package']['name']}"], check=True)
     else:
-        parser.print_help()
+        parser.print_help()