11import argparse
22import typing as t
3+ from pathlib import Path
4+ from datetime import datetime
35
46
57class ArgNamespace (argparse .Namespace ):
8+ command : t .Literal ["init" , "build" ]
69 path : str
10+ output : str
711
812
913def main () -> None :
@@ -14,10 +18,36 @@ def main() -> None:
1418 "gh: https://github.com/scratch-api/sb2git" ,
1519 )
1620
17- parser .add_argument ("path" , type = str )
21+ if command := parser .add_subparsers (dest = "command" , required = True ):
22+ if init := command .add_parser ("init" , help = "Set up a sb2git.toml file" ):
23+ init .add_argument ("path" , nargs = "?" , default = "." , type = str )
24+ if build := command .add_parser (
25+ "build" , help = "Build a sb2git input directory into an output directory"
26+ ):
27+ build .add_argument (
28+ "-o" , "--output" , type = str , default = "build" , help = "Output directory"
29+ )
1830 args = parser .parse_args (namespace = ArgNamespace ())
1931 run (args )
2032
2133
2234def run (args : ArgNamespace ):
23- print (f"Hello from sb2git! { args } " )
35+ match args .command :
36+ case "init" :
37+ init (args )
38+ case "build" :
39+ ...
40+
41+
42+ def init (args : ArgNamespace ):
43+ path = Path (args .path ).resolve ()
44+ if not path .exists ():
45+ raise ValueError (f"{ path } does not exist" )
46+
47+ print (f"Walking { args .path } " )
48+ for file in path .iterdir ():
49+ created_at = datetime .fromtimestamp (file .stat ().st_mtime )
50+ print (file , created_at )
51+
52+
53+ def build (args : ArgNamespace ): ...
0 commit comments