11import argparse
2+ import json
23
4+ import actionman
35from loggerman import logger
46
57from proman import script
@@ -18,14 +20,96 @@ def get_recursive(parts, current_object):
1820 return get_recursive (parts , script )
1921
2022 initialize_logger ()
23+ args = _read_args ()
24+ logger .debug ("Input Arguments" , args )
25+ endpoint = get_endpoint (args .endpoint )
26+ endpoint (args )
27+ return
28+
29+
30+ def _read_args () -> argparse .Namespace :
31+ """Read inputs and return them as a namespace object."""
32+ args = _parse_args ()
33+ _set_github_context (args )
34+ _set_github_token (args )
35+ _set_github_admin_token (args )
36+ _set_zenodo_token (args )
37+ _set_zenodo_sandbox_token (args )
38+ return args
39+
40+
41+ def _set_github_context (args : argparse .Namespace ) -> None :
42+ args .github_context = json .loads (
43+ args .github_context
44+ ) if "github_context" in args else actionman .env_var .read ("GITHUB_CONTEXT" , typ = dict , remove = args .remove_tokens )
45+ if args .github_context :
46+ github_token = args .github_context .pop ("token" )
47+ if github_token :
48+ args .github_token = github_token
49+ return
50+
51+
52+ def _set_github_token (args : argparse .Namespace ) -> None :
53+ if "github_token" in args :
54+ return
55+ for env_var_name in ("GITHUB_TOKEN" , "GITHUB_ADMIN_TOKEN" ):
56+ token = actionman .env_var .read (env_var_name , typ = str , remove = args .remove_tokens )
57+ if token :
58+ args .github_token = token
59+ return
60+ token = _pyshellman .run (
61+ command = ["gh" , "auth" , "token" ],
62+ logger = logger ,
63+ raise_execution = False ,
64+ raise_exit_code = False ,
65+ raise_stderr = False ,
66+ ).out
67+ if token :
68+ args .github_token = token
69+ return
70+
71+
72+ def _set_github_admin_token (args : argparse .Namespace ) -> None :
73+ if "github_admin_token" in args :
74+ return
75+ for env_var_name in ("GITHUB_ADMIN_TOKEN" , ):
76+ token = actionman .env_var .read (env_var_name , typ = str , remove = args .remove_tokens )
77+ if token :
78+ args .github_admin_token = token
79+ return
80+ if "github_token" in args :
81+ args .github_admin_token = args .github_token
82+ return
83+
84+
85+ def _set_zenodo_token (args : argparse .Namespace ) -> None :
86+ if "zenodo_token" in args :
87+ return
88+ args .zenodo_token = actionman .env_var .read ("ZENODO_TOKEN" , typ = str , remove = args .remove_tokens )
89+ return
90+
91+
92+ def _set_zenodo_sandbox_token (args : argparse .Namespace ) -> None :
93+ if "zenodo_sandbox_token" in args :
94+ return
95+ args .zenodo_sandbox_token = actionman .env_var .read ("ZENODO_SANDBOX_TOKEN" , typ = str , remove = args .remove_tokens )
96+ return
2197
98+
99+ def _parse_args () -> argparse .Namespace :
100+ """Generate the command line interface for the project manager and parse input arguments.
101+
102+ Notes
103+ -----
104+ The code for this function is automatically generated by the control center.
105+ """
22106 # begin auto-generated parser
23107 parser = argparse .ArgumentParser (description = "Project Manager CLI" )
24108 parser .add_argument ("--repo" , type = str , help = "Local path to the repository root directory." , default = "./" )
25109 # Sub-parsers for parser
26110 subparsers_main = parser .add_subparsers (dest = "command" , required = True )
27111 subparser_cca = subparsers_main .add_parser ("cca" , help = "Run Continuous Configuration Automation on the repository." )
28- subparser_cca .add_argument ("-t" , "--token" , type = str , help = "GitHub token for accessing the repository." )
112+ subparser_cca .add_argument ("-t" , "--github- token" , type = str , help = "GitHub token for accessing the repository." )
29113 subparser_cca .add_argument ("-b" , "--branch-version" , help = "Branch-name to version mappings (e.g., -b main=0.0.0 dev=1.0.0a1) to use instead of git tags." , type = str , nargs = "*" , metavar = "BRNACH=VERSION" )
30114 subparser_cca .add_argument ("-c" , "--control-center" , help = "Path to the control center directory containing configuration files." , type = str )
31115 subparser_cca .add_argument ("-d" , "--dry-run" , help = "Perform a dry run without making any changes." , action = "store_true" )
@@ -89,11 +173,7 @@ def get_recursive(parts, current_object):
89173 if (args .from_ref and not args .to_ref ) or (args .to_ref and not args .from_ref ):
90174 parser .error ("Both --from-ref and --to-ref must be provided together." )
91175 # end auto-generated parser
92-
93- logger .debug ("Input Arguments" , args )
94- endpoint = get_endpoint (args .endpoint )
95- endpoint (args )
96- return
176+ return args
97177
98178
99179if __name__ == "__main__" :
0 commit comments