summaryrefslogtreecommitdiff
path: root/gitlab/cli.py
diff options
context:
space:
mode:
authorMax Wittig <max.wittig95@gmail.com>2019-05-16 18:00:34 +0200
committerMax Wittig <max.wittig95@gmail.com>2019-05-16 18:03:56 +0200
commit318d2770cbc90ae4d33170274e214b9d828bca43 (patch)
treec5b6d6d9b57f6642dca83ea33956a4d5ae15e5eb /gitlab/cli.py
parentef32990347d0ab9145b8919d25269766dc2ce445 (diff)
downloadgitlab-refactor/black.tar.gz
refactor: format everything blackrefactor/black
Diffstat (limited to 'gitlab/cli.py')
-rw-r--r--gitlab/cli.py109
1 files changed, 67 insertions, 42 deletions
diff --git a/gitlab/cli.py b/gitlab/cli.py
index b573c7f..0433a81 100644
--- a/gitlab/cli.py
+++ b/gitlab/cli.py
@@ -26,7 +26,7 @@ import sys
import gitlab.config
-camel_re = re.compile('(.)([A-Z])')
+camel_re = re.compile("(.)([A-Z])")
# custom_actions = {
# cls: {
@@ -46,20 +46,21 @@ def register_custom_action(cls_names, mandatory=tuple(), optional=tuple()):
in_obj = True
classes = cls_names
if type(cls_names) != tuple:
- classes = (cls_names, )
+ classes = (cls_names,)
for cls_name in classes:
final_name = cls_name
- if cls_name.endswith('Manager'):
- final_name = cls_name.replace('Manager', '')
+ if cls_name.endswith("Manager"):
+ final_name = cls_name.replace("Manager", "")
in_obj = False
if final_name not in custom_actions:
custom_actions[final_name] = {}
- action = f.__name__.replace('_', '-')
+ action = f.__name__.replace("_", "-")
custom_actions[final_name][action] = (mandatory, optional, in_obj)
return wrapped_f
+
return wrap
@@ -75,38 +76,57 @@ def what_to_cls(what):
def cls_to_what(cls):
- return camel_re.sub(r'\1-\2', cls.__name__).lower()
+ return camel_re.sub(r"\1-\2", cls.__name__).lower()
def _get_base_parser(add_help=True):
parser = argparse.ArgumentParser(
- add_help=add_help,
- description="GitLab API Command Line Interface")
- parser.add_argument("--version", help="Display the version.",
- action="store_true")
- parser.add_argument("-v", "--verbose", "--fancy",
- help="Verbose mode (legacy format only)",
- action="store_true")
- parser.add_argument("-d", "--debug",
- help="Debug mode (display HTTP requests)",
- action="store_true")
- parser.add_argument("-c", "--config-file", action='append',
- help=("Configuration file to use. Can be used "
- "multiple times."))
- parser.add_argument("-g", "--gitlab",
- help=("Which configuration section should "
- "be used. If not defined, the default selection "
- "will be used."),
- required=False)
- parser.add_argument("-o", "--output",
- help="Output format (v4 only): json|legacy|yaml",
- required=False,
- choices=['json', 'legacy', 'yaml'],
- default="legacy")
- parser.add_argument("-f", "--fields",
- help=("Fields to display in the output (comma "
- "separated). Not used with legacy output"),
- required=False)
+ add_help=add_help, description="GitLab API Command Line Interface"
+ )
+ parser.add_argument("--version", help="Display the version.", action="store_true")
+ parser.add_argument(
+ "-v",
+ "--verbose",
+ "--fancy",
+ help="Verbose mode (legacy format only)",
+ action="store_true",
+ )
+ parser.add_argument(
+ "-d", "--debug", help="Debug mode (display HTTP requests)", action="store_true"
+ )
+ parser.add_argument(
+ "-c",
+ "--config-file",
+ action="append",
+ help=("Configuration file to use. Can be used " "multiple times."),
+ )
+ parser.add_argument(
+ "-g",
+ "--gitlab",
+ help=(
+ "Which configuration section should "
+ "be used. If not defined, the default selection "
+ "will be used."
+ ),
+ required=False,
+ )
+ parser.add_argument(
+ "-o",
+ "--output",
+ help="Output format (v4 only): json|legacy|yaml",
+ required=False,
+ choices=["json", "legacy", "yaml"],
+ default="legacy",
+ )
+ parser.add_argument(
+ "-f",
+ "--fields",
+ help=(
+ "Fields to display in the output (comma "
+ "separated). Not used with legacy output"
+ ),
+ required=False,
+ )
return parser
@@ -117,7 +137,7 @@ def _get_parser(cli_module):
def _parse_value(v):
- if isinstance(v, str) and v.startswith('@'):
+ if isinstance(v, str) and v.startswith("@"):
# If the user-provided value starts with @, we try to read the file
# path provided after @ as the real value. Exit on any error.
try:
@@ -142,16 +162,13 @@ def main():
# any subparser setup
(options, args) = parser.parse_known_args(sys.argv)
try:
- config = gitlab.config.GitlabConfigParser(
- options.gitlab,
- options.config_file
- )
+ config = gitlab.config.GitlabConfigParser(options.gitlab, options.config_file)
except gitlab.config.ConfigError as e:
if "--help" in sys.argv or "-h" in sys.argv:
parser.print_help()
sys.exit(0)
sys.exit(e)
- cli_module = importlib.import_module('gitlab.v%s.cli' % config.api_version)
+ cli_module = importlib.import_module("gitlab.v%s.cli" % config.api_version)
# Now we build the entire set of subcommands and do the complete parsing
parser = _get_parser(cli_module)
@@ -163,15 +180,23 @@ def main():
output = args.output
fields = []
if args.fields:
- fields = [x.strip() for x in args.fields.split(',')]
+ fields = [x.strip() for x in args.fields.split(",")]
debug = args.debug
action = args.action
what = args.what
args = args.__dict__
# Remove CLI behavior-related args
- for item in ('gitlab', 'config_file', 'verbose', 'debug', 'what', 'action',
- 'version', 'output'):
+ for item in (
+ "gitlab",
+ "config_file",
+ "verbose",
+ "debug",
+ "what",
+ "action",
+ "version",
+ "output",
+ ):
args.pop(item)
args = {k: _parse_value(v) for k, v in args.items() if v is not None}