1919readme_re = re .compile (r'This is \w+ version \d+\.\d+' ).match
2020
2121
22+ def initialise_subcommands () -> None :
23+ global subcommands
24+
25+ from blurb ._add import add
26+ from blurb ._export import export
27+ from blurb ._merge import merge
28+ from blurb ._populate import populate
29+ from blurb ._release import release
30+
31+ subcommands = {
32+ 'version' : version ,
33+ 'help' : help ,
34+ 'add' : add ,
35+ 'export' : export ,
36+ 'merge' : merge ,
37+ 'populate' : populate ,
38+ 'release' : release ,
39+
40+ # Make 'blurb --help/--version/-V' work.
41+ '--help' : help ,
42+ '--version' : version ,
43+ '-V' : version ,
44+ }
45+
46+
2247def error (msg : str , / ) -> NoReturn :
2348 raise SystemExit (f'Error: { msg } ' )
2449
@@ -35,26 +60,18 @@ def require_ok(prompt: str, /) -> str:
3560 return s
3661
3762
38- def subcommand (fn : CommandFunc ):
39- global subcommands
40- subcommands [fn .__name__ ] = fn
41- return fn
42-
43-
4463def get_subcommand (subcommand : str , / ) -> CommandFunc :
4564 fn = subcommands .get (subcommand )
4665 if not fn :
4766 error (f"Unknown subcommand: { subcommand } \n Run 'blurb help' for help." )
4867 return fn
4968
5069
51- @subcommand
5270def version () -> None :
5371 """Print blurb version."""
5472 print ('blurb version' , blurb .__version__ )
5573
5674
57- @subcommand
5875def help (subcommand : str | None = None ) -> None :
5976 """Print help for subcommands.
6077
@@ -102,12 +119,6 @@ def help(subcommand: str | None = None) -> None:
102119 raise SystemExit (0 )
103120
104121
105- # Make 'blurb --help/--version/-V' work.
106- subcommands ['--help' ] = help
107- subcommands ['--version' ] = version
108- subcommands ['-V' ] = version
109-
110-
111122def _blurb_help () -> None :
112123 """Print default help for blurb."""
113124
@@ -157,6 +168,7 @@ def main() -> None:
157168 subcommand = args [0 ]
158169 args = args [1 :]
159170
171+ initialise_subcommands ()
160172 fn = get_subcommand (subcommand )
161173
162174 # hack
0 commit comments