Skip to content

Commit 1cbc4b2

Browse files
Fix lint
1 parent 06be224 commit 1cbc4b2

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

linodecli/__init__.py

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,7 @@
4646

4747
# if any of these arguments are given, we don't need to prompt for configuration
4848
skip_config = (
49-
any(
50-
c in argv
51-
for c in ["--skip-config", "--version", "completion"]
52-
)
49+
any(c in argv for c in ["--skip-config", "--version", "completion"])
5350
or TEST_MODE
5451
)
5552

@@ -110,24 +107,34 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
110107
# if not spec was found and we weren't baking, we're doomed
111108
sys.exit(ExitCodes.ARGUMENT_ERROR)
112109

113-
if parsed.command == "set-custom-alias" or parsed.command == "remove-custom-alias":
110+
if parsed.command in ("set-custom-alias", "remove-custom-alias"):
114111
# Ensure both --command and --alias are provided
115112
# TODO: Can we use argparse for these
116113
if len(args) == 4:
117114
if args[0] != "--command" or args[2] != "--alias":
118-
print("Usage: linode-cli set-custom-alias --command [COMMAND] --alias [ALIAS]", file=sys.stderr)
115+
print(
116+
"Usage: linode-cli set-custom-alias --command "
117+
"[COMMAND] --alias [ALIAS]",
118+
file=sys.stderr,
119+
)
119120
sys.exit(ExitCodes.ARGUMENT_ERROR)
120121

121122
# Get the indexes for --command and --alias
122123
try:
123124
command_index = args.index("--command") + 1
124125
alias_index = args.index("--alias") + 1
125126
except ValueError:
126-
print("Both --command and --alias arguments are required.", file=sys.stderr)
127+
print(
128+
"Both --command and --alias arguments are required.",
129+
file=sys.stderr,
130+
)
127131
sys.exit(ExitCodes.ARGUMENT_ERROR)
128132

129133
if command_index >= len(args) or alias_index >= len(args):
130-
print("Both --command and --alias arguments must have valid values.", file=sys.stderr)
134+
print(
135+
"Both --command and --alias arguments must have valid values.",
136+
file=sys.stderr,
137+
)
131138
sys.exit(ExitCodes.ARGUMENT_ERROR)
132139

133140
# Retrieve the command and alias from arguments
@@ -136,7 +143,9 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
136143

137144
# Check if the command is valid
138145
if command not in cli.ops:
139-
print(f"Error: '{command}' is not a valid command.", file=sys.stderr)
146+
print(
147+
f"Error: '{command}' is not a valid command.", file=sys.stderr
148+
)
140149
sys.exit(ExitCodes.ARGUMENT_ERROR)
141150

142151
# Set the alias if it does not already exist
@@ -145,15 +154,19 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
145154
cli.config.set_custom_alias(alias, command)
146155
print(f"Custom alias '{alias}' set for command '{command}'")
147156
else:
148-
print(f"Custom alias '{alias}' already set for command '{command}'")
157+
print(
158+
f"Custom alias '{alias}' already set for command '{command}'"
159+
)
149160

150161
# Remove the alias if it already exists
151162
if parsed.command == "remove-custom-alias":
152163
if (alias, command) in cli.config.get_custom_aliases().items():
153164
cli.config.remove_custom_alias(alias, command)
154165
print(f"Custom alias '{alias}' removed for command '{command}'")
155166
else:
156-
print(f"Custom alias '{alias}' does not exist for command '{command}'")
167+
print(
168+
f"Custom alias '{alias}' does not exist for command '{command}'"
169+
)
157170

158171
sys.exit(ExitCodes.SUCCESS)
159172

@@ -271,20 +284,23 @@ def main(): # pylint: disable=too-many-branches,too-many-statements
271284
sys.exit(ExitCodes.UNRECOGNIZED_COMMAND)
272285

273286
# handle a help for a command - either --help or no action triggers this
274-
if (
275-
parsed.command is not None
276-
and parsed.action is None
277-
):
287+
if parsed.command is not None and parsed.action is None:
278288
if parsed.command in cli.ops:
279289
print_help_command_actions(cli.ops, parsed.command)
280290
sys.exit(ExitCodes.SUCCESS)
281291
if parsed.command in cli.config.get_custom_aliases().keys():
282-
print_help_command_actions(cli.ops, cli.config.get_custom_aliases()[parsed.command])
292+
print_help_command_actions(
293+
cli.ops, cli.config.get_custom_aliases()[parsed.command]
294+
)
283295

284296
if parsed.command is not None and parsed.action is not None:
285297
if parsed.help:
286298
if parsed.command in cli.config.get_custom_aliases().keys():
287-
print_help_action(cli, cli.config.get_custom_aliases()[parsed.command], parsed.action)
299+
print_help_action(
300+
cli,
301+
cli.config.get_custom_aliases()[parsed.command],
302+
parsed.action,
303+
)
288304
else:
289305
print_help_action(cli, parsed.command, parsed.action)
290306
sys.exit(ExitCodes.SUCCESS)

linodecli/configuration/config.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,17 +619,24 @@ def remove_custom_alias(self, alias: str, command: str):
619619
:param command: The command the alias is mapped to.
620620
"""
621621
if not self.config.has_section("custom_aliases"):
622-
print(f"Error: No custom aliases have been set.", file=sys.stderr)
622+
print("Error: No custom aliases have been set.", file=sys.stderr)
623623
return
624624

625625
if not self.config.has_option("custom_aliases", alias):
626-
print(f"Error: Custom alias '{alias}' does not exist.", file=sys.stderr)
626+
print(
627+
f"Error: Custom alias '{alias}' does not exist.",
628+
file=sys.stderr,
629+
)
627630
return
628631

629632
# Check if the alias maps to the given command
630633
existing_command = self.config.get("custom_aliases", alias)
631634
if existing_command != command:
632-
print(f"Error: Custom alias '{alias}' is mapped to '{existing_command}', not '{command}'.", file=sys.stderr)
635+
print(
636+
f"Error: Custom alias '{alias}' is mapped to "
637+
f"'{existing_command}', not '{command}'.",
638+
file=sys.stderr,
639+
)
633640
return
634641

635642
# Remove the alias and update the config
@@ -642,4 +649,8 @@ def get_custom_aliases(self) -> Dict[str, str]:
642649
643650
:return: A dictionary mapping custom alias names to their respective commands.
644651
"""
645-
return dict(self.config.items("custom_aliases")) if self.config.has_section("custom_aliases") else {}
652+
return (
653+
dict(self.config.items("custom_aliases"))
654+
if (self.config.has_section("custom_aliases"))
655+
else {}
656+
)

0 commit comments

Comments
 (0)