- Notifications
You must be signed in to change notification settings - Fork673
feat(cli): allow options from CLI args or environment variables#1296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -19,6 +19,7 @@ | ||
import argparse | ||
import functools | ||
import os | ||
import re | ||
import sys | ||
from types import ModuleType | ||
@@ -112,17 +113,25 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser: | ||
"-v", | ||
"--verbose", | ||
"--fancy", | ||
help="Verbose mode (legacy format only) [env var: GITLAB_VERBOSE]", | ||
action="store_true", | ||
default=os.getenv("GITLAB_VERBOSE"), | ||
) | ||
parser.add_argument( | ||
"-d", | ||
"--debug", | ||
help="Debug mode (display HTTP requests) [env var: GITLAB_DEBUG]", | ||
action="store_true", | ||
default=os.getenv("GITLAB_DEBUG"), | ||
) | ||
parser.add_argument( | ||
"-c", | ||
"--config-file", | ||
action="append", | ||
help=( | ||
"Configuration file to use. Can be used multiple times. " | ||
"[env var: PYTHON_GITLAB_CFG]" | ||
), | ||
) | ||
parser.add_argument( | ||
"-g", | ||
@@ -151,7 +160,86 @@ def _get_base_parser(add_help: bool = True) -> argparse.ArgumentParser: | ||
), | ||
required=False, | ||
) | ||
parser.add_argument( | ||
"--server-url", | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
help=("GitLab server URL [env var: GITLAB_URL]"), | ||
required=False, | ||
default=os.getenv("GITLAB_URL"), | ||
) | ||
parser.add_argument( | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
"--ssl-verify", | ||
help=( | ||
"Whether SSL certificates should be validated. [env var: GITLAB_SSL_VERIFY]" | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
), | ||
required=False, | ||
default=os.getenv("GITLAB_SSL_VERIFY"), | ||
) | ||
parser.add_argument( | ||
"--timeout", | ||
help=( | ||
"Timeout to use for requests to the GitLab server. " | ||
"[env var: GITLAB_TIMEOUT]" | ||
), | ||
required=False, | ||
default=os.getenv("GITLAB_TIMEOUT"), | ||
) | ||
parser.add_argument( | ||
"--api-version", | ||
help=("GitLab API version [env var: GITLAB_API_VERSION]"), | ||
required=False, | ||
default=os.getenv("GITLAB_API_VERSION"), | ||
) | ||
parser.add_argument( | ||
"--per-page", | ||
help=( | ||
"Number of entries to return per page in the response. " | ||
"[env var: GITLAB_PER_PAGE]" | ||
), | ||
required=False, | ||
default=os.getenv("GITLAB_PER_PAGE"), | ||
) | ||
parser.add_argument( | ||
"--pagination", | ||
help=( | ||
"Whether to use keyset or offset pagination [env var: GITLAB_PAGINATION]" | ||
), | ||
required=False, | ||
default=os.getenv("GITLAB_PAGINATION"), | ||
) | ||
parser.add_argument( | ||
"--order-by", | ||
help=("Set order_by globally [env var: GITLAB_ORDER_BY]"), | ||
required=False, | ||
default=os.getenv("GITLAB_ORDER_BY"), | ||
) | ||
parser.add_argument( | ||
"--user-agent", | ||
help=( | ||
"The user agent to send to GitLab with the HTTP request. " | ||
"[env var: GITLAB_USER_AGENT]" | ||
), | ||
required=False, | ||
default=os.getenv("GITLAB_USER_AGENT"), | ||
) | ||
tokens = parser.add_mutually_exclusive_group() | ||
tokens.add_argument( | ||
"--private-token", | ||
help=("GitLab private access token [env var: GITLAB_PRIVATE_TOKEN]"), | ||
required=False, | ||
default=os.getenv("GITLAB_PRIVATE_TOKEN"), | ||
) | ||
tokens.add_argument( | ||
"--oauth-token", | ||
help=("GitLab OAuth token [env var: GITLAB_OAUTH_TOKEN]"), | ||
required=False, | ||
default=os.getenv("GITLAB_OAUTH_TOKEN"), | ||
) | ||
tokens.add_argument( | ||
"--job-token", | ||
help=("GitLab CI job token [env var: CI_JOB_TOKEN]"), | ||
required=False, | ||
) | ||
return parser | ||
@@ -243,13 +331,23 @@ def main() -> None: | ||
"whaction", | ||
"version", | ||
"output", | ||
"fields", | ||
"server_url", | ||
"ssl_verify", | ||
"timeout", | ||
"api_version", | ||
"pagination", | ||
"user_agent", | ||
"private_token", | ||
"oauth_token", | ||
"job_token", | ||
): | ||
args_dict.pop(item) | ||
args_dict = {k: _parse_value(v) for k, v in args_dict.items() if v is not None} | ||
try: | ||
gl = gitlab.Gitlab.merge_config(vars(options),gitlab_id, config_files) | ||
if gl.private_token or gl.oauth_token: | ||
nejch marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
gl.auth() | ||
except Exception as e: | ||
die(str(e)) | ||
Uh oh!
There was an error while loading.Please reload this page.