@@ -17,7 +17,10 @@ def main():
1717 args = get_command_line_arguments ()
1818 get_dependencies ()
1919
20- root_path = args .path .absolute ()
20+ root_path = args .path .absolute () if args .path else pathlib .Path .cwd ().absolute ()
21+ app_name = root_path .name if args .path else args .app_name
22+ if args .path and args .app_name :
23+ logging .warning ('Ignoring app_name flag because path was provided' )
2124
2225 # Check if applications folder exists, if not, go up until it's found
2326 while not (root_path / 'applications' ).exists ():
@@ -32,11 +35,10 @@ def main():
3235 generate_models (root_path , should_generate )
3336
3437 if args .generate_servers :
35- generate_servers (root_path , should_generate , args . app_name )
38+ generate_servers (root_path , should_generate , app_name )
3639
3740 if args .generate_clients :
38- assert args .client_name is not None
39- generate_clients (root_path , should_generate , args .app_name , args .client_name , args .client_types )
41+ generate_clients (root_path , should_generate , app_name , args .client_name , args .client_types )
4042
4143
4244class GenerationMode (enum .Flag ):
@@ -46,7 +48,7 @@ class GenerationMode(enum.Flag):
4648
4749 @classmethod
4850 def all (cls ):
49- return functools .reduce (operator .or_ , cls )
51+ return functools .reduce (operator .or_ , [ cls . CLIENTS , cls . SERVERS ] )
5052
5153
5254@dataclass (frozen = True )
@@ -72,18 +74,18 @@ class CommandLineArguments:
7274
7375
7476def get_command_line_arguments () -> CommandLineArguments :
75- parser = argparse .ArgumentParser (description = 'Walks filesystem inside ./applications to create and update application scaffolding based on API specifications .' )
77+ parser = argparse .ArgumentParser (description = 'Walks the filesystem inside the ./applications folder to create and update applications scaffolding.' )
7678
7779 common_arguments = argparse .ArgumentParser (add_help = False )
78- common_arguments .add_argument ('path' , metavar = 'path' , nargs = '?' , default = pathlib . Path . cwd () , type = pathlib .Path ,
79- help = 'Base path of the application.' )
80+ common_arguments .add_argument ('path' , metavar = 'path' , nargs = '?' , default = None , type = pathlib .Path ,
81+ help = 'Base path of the application. If used, the -a/--app_name flag is ignored. ' )
8082 common_arguments .add_argument ('-i' , '--interactive' , dest = 'is_interactive' , action = "store_true" ,
8183 help = 'Asks before generate' )
8284 common_arguments .add_argument ('-a' , '--app-name' , dest = 'app_name' , action = "store" , default = None ,
8385 help = 'Generate only for a specific application' )
8486
8587 clients_arguments = argparse .ArgumentParser (add_help = False )
86- clients_arguments .add_argument ('-cn' , '--client-name' , dest = 'client_name' , action = 'store' , default = LIB_NAME ,
88+ clients_arguments .add_argument ('-cn' , '--client-name' , dest = 'client_name' , action = 'store' , default = None ,
8789 help = 'specify client prefix name' )
8890 client_type_group = clients_arguments .add_mutually_exclusive_group (required = False )
8991 client_type_group .add_argument ('-t' , '--ts-only' , dest = 'client_types' , action = 'store_const' , const = ClientType .TS_CLIENT ,
@@ -95,20 +97,20 @@ def get_command_line_arguments() -> CommandLineArguments:
9597 subparsers = parser .add_subparsers (title = 'generation modes' , required = True )
9698
9799 all_parser = subparsers .add_parser ('all' , parents = [common_arguments , clients_arguments ],
98- help = 'Generate models, server stubs and client libraries' )
100+ help = 'Generate server stubs and client libraries' )
99101 all_parser .set_defaults (generation_mode = GenerationMode .all ())
100102
101- models_parser = subparsers .add_parser ('models ' , parents = [common_arguments ],
102- help = 'Generate only model library ' )
103- models_parser .set_defaults (generation_mode = GenerationMode .MODELS )
103+ clients_parser = subparsers .add_parser ('clients ' , parents = [common_arguments , clients_arguments ],
104+ help = 'Generate only client libraries ' )
105+ clients_parser .set_defaults (generation_mode = GenerationMode .CLIENTS )
104106
105107 servers_parser = subparsers .add_parser ('servers' , parents = [common_arguments ],
106108 help = 'Generate only server stubs' )
107109 servers_parser .set_defaults (generation_mode = GenerationMode .SERVERS )
108110
109- clients_parser = subparsers .add_parser ('clients ' , parents = [common_arguments , clients_arguments ],
110- help = 'Generate only client libraries' )
111- clients_parser .set_defaults (generation_mode = GenerationMode .CLIENTS )
111+ models_parser = subparsers .add_parser ('models ' , parents = [common_arguments ],
112+ help = 'Special flag, used to regenerate only model libraries' )
113+ models_parser .set_defaults (generation_mode = GenerationMode .MODELS )
112114
113115 args = parser .parse_args ()
114116
0 commit comments