File tree Expand file tree Collapse file tree 2 files changed +29
-9
lines changed
Expand file tree Collapse file tree 2 files changed +29
-9
lines changed Original file line number Diff line number Diff line change 1+ import argparse
2+ import sys
3+
4+ import argcomplete
5+
6+
7+ def setup_root_parser (root_parser : argparse .ArgumentParser ):
8+ args = sys .argv [1 :]
9+ if "--" in args :
10+ idx = args .index ("--" )
11+ pre_args = args [:idx ]
12+ post_args = args [idx + 1 :]
13+ else :
14+ pre_args = args
15+ post_args = []
16+
17+ argcomplete .autocomplete (root_parser )
18+ args , unknown_args = root_parser .parse_known_args (pre_args )
19+
20+ if unknown_args :
21+ root_parser .error (f"Unknown arguments before '--': { unknown_args } " )
22+
23+ if not args .command :
24+ root_parser .print_help ()
25+ sys .exit (1 )
26+
27+ args .func (** vars (args ), extra_args = post_args )
Original file line number Diff line number Diff line change 55import shutil
66import sys
77
8- import argcomplete
9-
108from adit_radis_shared .cli import helper as cli_helper
119from adit_radis_shared .cli import parsers
10+ from adit_radis_shared .cli .setup import setup_root_parser
1211
1312
1413def copy_statics (** kwargs ):
@@ -69,10 +68,4 @@ def copy_file(file: str, filename: str | None = None):
6968 parser = subparsers .add_parser ("copy_statics" , help = "Copy statics for the project" )
7069 parser .set_defaults (func = copy_statics )
7170
72- argcomplete .autocomplete (root_parser )
73- args , extra_args = root_parser .parse_known_args ()
74- if not args .command :
75- root_parser .print_help ()
76- sys .exit (1 )
77-
78- args .func (** vars (args ), extra_args = extra_args )
71+ setup_root_parser (root_parser )
You can’t perform that action at this time.
0 commit comments