|
20 | 20 | import argparse
|
21 | 21 | import functools
|
22 | 22 | import importlib
|
| 23 | +import os |
23 | 24 | import re
|
24 | 25 | import sys
|
25 | 26 |
|
@@ -87,17 +88,22 @@ def _get_base_parser(add_help=True):
|
87 | 88 | "-v",
|
88 | 89 | "--verbose",
|
89 | 90 | "--fancy",
|
90 |
| - help="Verbose mode (legacy format only)", |
| 91 | + help="Verbose mode (legacy format only) [env var: GITLAB_VERBOSE]", |
91 | 92 | action="store_true",
|
| 93 | + default=os.getenv("GITLAB_VERBOSE"), |
92 | 94 | )
|
93 | 95 | parser.add_argument(
|
94 |
| - "-d", "--debug", help="Debug mode (display HTTP requests)", action="store_true" |
| 96 | + "-d", |
| 97 | + "--debug", |
| 98 | + help="Debug mode (display HTTP requests) [env var: GITLAB_DEBUG]", |
| 99 | + action="store_true", |
| 100 | + default=os.getenv("GITLAB_DEBUG"), |
95 | 101 | )
|
96 | 102 | parser.add_argument(
|
97 | 103 | "-c",
|
98 | 104 | "--config-file",
|
99 | 105 | action="append",
|
100 |
| - help="Configuration file to use. Can be used multiple times.", |
| 106 | + help="Configuration file to use. Can be used multiple times. [env var: PYTHON_GITLAB_CFG]", |
101 | 107 | )
|
102 | 108 | parser.add_argument(
|
103 | 109 | "-g",
|
@@ -126,7 +132,86 @@ def _get_base_parser(add_help=True):
|
126 | 132 | ),
|
127 | 133 | required=False,
|
128 | 134 | )
|
129 |
| - |
| 135 | + # TODO: deduplicate everything by providing some data struct to loop over |
| 136 | + parser.add_argument( |
| 137 | + "--url", |
| 138 | + help=("GitLab server URL [env var: GITLAB_URL]"), |
| 139 | + required=False, |
| 140 | + default=os.getenv("GITLAB_URL"), |
| 141 | + ) |
| 142 | + parser.add_argument( |
| 143 | + "--private-token", |
| 144 | + help=("GitLab private token [env var: GITLAB_PRIVATE_TOKEN]"), |
| 145 | + required=False, |
| 146 | + default=os.getenv("GITLAB_PRIVATE_TOKEN"), |
| 147 | + ) |
| 148 | + parser.add_argument( |
| 149 | + "--oauth-token", |
| 150 | + help=("GitLab OAuth token [env var: GITLAB_OAUTH_TOKEN]"), |
| 151 | + required=False, |
| 152 | + default=os.getenv("GITLAB_OAUTH_TOKEN"), |
| 153 | + ) |
| 154 | + parser.add_argument( |
| 155 | + "--job-token", |
| 156 | + help=( |
| 157 | + "GitLab CI job token. Explicitly providing this is usually not needed.\n" |
| 158 | + "[env var, only if explicitly overriding CI_JOB_TOKEN: GITLAB_JOB_TOKEN]" |
| 159 | + ), |
| 160 | + required=False, |
| 161 | + default=os.getenv("GITLAB_JOB_TOKEN"), |
| 162 | + ) |
| 163 | + parser.add_argument( |
| 164 | + "--ssl-verify", |
| 165 | + help=( |
| 166 | + "Whether SSL certificates should be validated. [env var: GITLAB_SSL_VERIFY]" |
| 167 | + ), |
| 168 | + required=False, |
| 169 | + default=os.getenv("GITLAB_SSL_VERIFY"), |
| 170 | + ) |
| 171 | + parser.add_argument( |
| 172 | + "--timeout", |
| 173 | + help=( |
| 174 | + "Timeout to use for requests to the GitLab server. [env var: GITLAB_TIMEOUT]" |
| 175 | + ), |
| 176 | + required=False, |
| 177 | + default=os.getenv("GITLAB_TIMEOUT"), |
| 178 | + ) |
| 179 | + parser.add_argument( |
| 180 | + "--api-version", |
| 181 | + help=("GitLab API version [env var: GITLAB_API_VERSION]"), |
| 182 | + required=False, |
| 183 | + default=os.getenv("GITLAB_API_VERSION"), |
| 184 | + ) |
| 185 | + parser.add_argument( |
| 186 | + "--per-page", |
| 187 | + help=( |
| 188 | + "Number of entries to return per page in the response. [env var: GITLAB_PER_PAGE]" |
| 189 | + ), |
| 190 | + required=False, |
| 191 | + default=os.getenv("GITLAB_PER_PAGE"), |
| 192 | + ) |
| 193 | + parser.add_argument( |
| 194 | + "--pagination", |
| 195 | + help=( |
| 196 | + "Whether to use keyset or offset pagination [env var: GITLAB_PAGINATION]" |
| 197 | + ), |
| 198 | + required=False, |
| 199 | + default=os.getenv("GITLAB_PAGINATION"), |
| 200 | + ) |
| 201 | + parser.add_argument( |
| 202 | + "--order-by", |
| 203 | + help=("Set order_by globally [env var: GITLAB_ORDER_BY]"), |
| 204 | + required=False, |
| 205 | + default=os.getenv("GITLAB_ORDER_BY"), |
| 206 | + ) |
| 207 | + parser.add_argument( |
| 208 | + "--user-agent", |
| 209 | + help=( |
| 210 | + "The user agent to send to GitLab with the HTTP request. [env var: GITLAB_USER_AGENT]" |
| 211 | + ), |
| 212 | + required=False, |
| 213 | + default=os.getenv("GITLAB_USER_AGENT"), |
| 214 | + ) |
130 | 215 | return parser
|
131 | 216 |
|
132 | 217 |
|
@@ -220,7 +305,7 @@ def main():
|
220 | 305 | args = {k: _parse_value(v) for k, v in args.items() if v is not None}
|
221 | 306 |
|
222 | 307 | try:
|
223 |
| - gl = gitlab.Gitlab.from_config(gitlab_id, config_files) |
| 308 | + gl = gitlab.Gitlab.merge_config(options, gitlab_id, config_files) |
224 | 309 | if gl.private_token or gl.oauth_token or gl.job_token:
|
225 | 310 | gl.auth()
|
226 | 311 | except Exception as e:
|
|
0 commit comments