|
19 | 19 |
|
20 | 20 | importargparse
|
21 | 21 | importfunctools
|
| 22 | +importos |
22 | 23 | importre
|
23 | 24 | importsys
|
24 | 25 | fromtypesimportModuleType
|
@@ -112,17 +113,22 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
|
112 | 113 | "-v",
|
113 | 114 | "--verbose",
|
114 | 115 | "--fancy",
|
115 |
| -help="Verbose mode (legacy format only)", |
| 116 | +help="Verbose mode (legacy format only) [env var: GITLAB_VERBOSE]", |
116 | 117 | action="store_true",
|
| 118 | +default=os.getenv("GITLAB_VERBOSE"), |
117 | 119 | )
|
118 | 120 | parser.add_argument(
|
119 |
| -"-d","--debug",help="Debug mode (display HTTP requests)",action="store_true" |
| 121 | +"-d", |
| 122 | +"--debug", |
| 123 | +help="Debug mode (display HTTP requests) [env var: GITLAB_DEBUG]", |
| 124 | +action="store_true", |
| 125 | +default=os.getenv("GITLAB_DEBUG"), |
120 | 126 | )
|
121 | 127 | parser.add_argument(
|
122 | 128 | "-c",
|
123 | 129 | "--config-file",
|
124 | 130 | action="append",
|
125 |
| -help="Configuration file to use. Can be used multiple times.", |
| 131 | +help="Configuration file to use. Can be used multiple times. [env var: PYTHON_GITLAB_CFG]", |
126 | 132 | )
|
127 | 133 | parser.add_argument(
|
128 | 134 | "-g",
|
@@ -151,7 +157,86 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser:
|
151 | 157 | ),
|
152 | 158 | required=False,
|
153 | 159 | )
|
154 |
| - |
| 160 | +# TODO: deduplicate everything by providing some data struct to loop over |
| 161 | +parser.add_argument( |
| 162 | +"--url", |
| 163 | +help=("GitLab server URL [env var: GITLAB_URL]"), |
| 164 | +required=False, |
| 165 | +default=os.getenv("GITLAB_URL"), |
| 166 | + ) |
| 167 | +parser.add_argument( |
| 168 | +"--private-token", |
| 169 | +help=("GitLab private token [env var: GITLAB_PRIVATE_TOKEN]"), |
| 170 | +required=False, |
| 171 | +default=os.getenv("GITLAB_PRIVATE_TOKEN"), |
| 172 | + ) |
| 173 | +parser.add_argument( |
| 174 | +"--oauth-token", |
| 175 | +help=("GitLab OAuth token [env var: GITLAB_OAUTH_TOKEN]"), |
| 176 | +required=False, |
| 177 | +default=os.getenv("GITLAB_OAUTH_TOKEN"), |
| 178 | + ) |
| 179 | +parser.add_argument( |
| 180 | +"--job-token", |
| 181 | +help=( |
| 182 | +"GitLab CI job token. Explicitly providing this is usually not needed.\n" |
| 183 | +"[env var, only if explicitly overriding CI_JOB_TOKEN: GITLAB_JOB_TOKEN]" |
| 184 | + ), |
| 185 | +required=False, |
| 186 | +default=os.getenv("GITLAB_JOB_TOKEN"), |
| 187 | + ) |
| 188 | +parser.add_argument( |
| 189 | +"--ssl-verify", |
| 190 | +help=( |
| 191 | +"Whether SSL certificates should be validated. [env var: GITLAB_SSL_VERIFY]" |
| 192 | + ), |
| 193 | +required=False, |
| 194 | +default=os.getenv("GITLAB_SSL_VERIFY"), |
| 195 | + ) |
| 196 | +parser.add_argument( |
| 197 | +"--timeout", |
| 198 | +help=( |
| 199 | +"Timeout to use for requests to the GitLab server. [env var: GITLAB_TIMEOUT]" |
| 200 | + ), |
| 201 | +required=False, |
| 202 | +default=os.getenv("GITLAB_TIMEOUT"), |
| 203 | + ) |
| 204 | +parser.add_argument( |
| 205 | +"--api-version", |
| 206 | +help=("GitLab API version [env var: GITLAB_API_VERSION]"), |
| 207 | +required=False, |
| 208 | +default=os.getenv("GITLAB_API_VERSION"), |
| 209 | + ) |
| 210 | +parser.add_argument( |
| 211 | +"--per-page", |
| 212 | +help=( |
| 213 | +"Number of entries to return per page in the response. [env var: GITLAB_PER_PAGE]" |
| 214 | + ), |
| 215 | +required=False, |
| 216 | +default=os.getenv("GITLAB_PER_PAGE"), |
| 217 | + ) |
| 218 | +parser.add_argument( |
| 219 | +"--pagination", |
| 220 | +help=( |
| 221 | +"Whether to use keyset or offset pagination [env var: GITLAB_PAGINATION]" |
| 222 | + ), |
| 223 | +required=False, |
| 224 | +default=os.getenv("GITLAB_PAGINATION"), |
| 225 | + ) |
| 226 | +parser.add_argument( |
| 227 | +"--order-by", |
| 228 | +help=("Set order_by globally [env var: GITLAB_ORDER_BY]"), |
| 229 | +required=False, |
| 230 | +default=os.getenv("GITLAB_ORDER_BY"), |
| 231 | + ) |
| 232 | +parser.add_argument( |
| 233 | +"--user-agent", |
| 234 | +help=( |
| 235 | +"The user agent to send to GitLab with the HTTP request. [env var: GITLAB_USER_AGENT]" |
| 236 | + ), |
| 237 | +required=False, |
| 238 | +default=os.getenv("GITLAB_USER_AGENT"), |
| 239 | + ) |
155 | 240 | returnparser
|
156 | 241 |
|
157 | 242 |
|
@@ -248,7 +333,7 @@ def main() -> None:
|
248 | 333 | args_dict= {k:_parse_value(v)fork,vinargs_dict.items()ifvisnotNone}
|
249 | 334 |
|
250 | 335 | try:
|
251 |
| -gl=gitlab.Gitlab.from_config(gitlab_id,config_files) |
| 336 | +gl=gitlab.Gitlab.merge_config(options,gitlab_id,config_files) |
252 | 337 | ifgl.private_tokenorgl.oauth_tokenorgl.job_token:
|
253 | 338 | gl.auth()
|
254 | 339 | exceptExceptionase:
|
|