Skip to content

Commit b5802ee

Browse files
tox fixes
1 parent cede8f8 commit b5802ee

File tree

12 files changed

+42
-34
lines changed

12 files changed

+42
-34
lines changed

SoftLayer/CLI/block/replication/disaster_recovery_failover.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from SoftLayer.CLI import formatting
99

1010

11-
@click.command(cls=SoftLayer.CLI.command.SLCommand, epilog="""Failover an inaccessible block volume to its available replicant volume.
11+
@click.command(cls=SoftLayer.CLI.command.SLCommand,
12+
epilog="""Failover an inaccessible block volume to its available replicant volume.
1213
If a volume (with replication) becomes inaccessible due to a disaster event, this method can be used to immediately
1314
failover to an available replica in another location. This method does not allow for failback via API.
1415
After using this method, to failback to the original volume, please open a support ticket.

SoftLayer/CLI/command.py

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,36 @@
1-
import click
2-
import types
1+
"""
2+
SoftLayer.CLI.command
3+
~~~~~~~~~~~~~~~~~~~~~
4+
Command interface for the SoftLayer CLI. Basically the Click commands, with fancy help text
5+
6+
:license: MIT, see LICENSE for more details.
7+
"""
38
import inspect
9+
import types
10+
11+
import click
412

513
from rich import box
6-
from rich.console import Console, RenderableType
7-
from rich.markup import escape
8-
from rich.text import Text
14+
from rich.console import Console
915
from rich.highlighter import RegexHighlighter
10-
from rich.panel import Panel
1116
from rich.table import Table
17+
from rich.text import Text
1218
from rich.theme import Theme
1319

14-
1520
from SoftLayer.CLI import environment
1621

22+
1723
class OptionHighlighter(RegexHighlighter):
24+
"""Provides highlighter regex for the Command help"""
1825
highlights = [
19-
r"(?P<switch>\-\w)", # single options like -v
20-
r"(?P<option>\-\-[\w\-]+)", # long options like --verbose
21-
r"(?P<default_option>\[[^\]]+\])", # anything between [], usually default options
26+
r"(?P<switch>\-\w)", # single options like -v
27+
r"(?P<option>\-\-[\w\-]+)", # long options like --verbose
28+
r"(?P<default_option>\[[^\]]+\])", # anything between [], usually default options
2229

2330
]
2431

25-
# Colors defined in https://rich.readthedocs.io/en/latest/_modules/rich/color.html#ColorType
32+
33+
# Colors defined in https://rich.readthedocs.io/en/latest/_modules/rich/color.html#ColorType
2634
SLCLI_THEME = Theme(
2735
{
2836
"option": "bold cyan",
@@ -86,7 +94,7 @@ def format_help_text(self, ctx: click.Context, formatter: click.formatting.HelpF
8694
text = self.help if self.help is not None else ""
8795

8896
if self.deprecated:
89-
text = _("(Deprecated) {text}").format(text=text)
97+
text = f"(Deprecated) {text}"
9098

9199
if text:
92100
text = inspect.cleandoc(text).partition("\f")[0]
@@ -100,7 +108,6 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm
100108
self.console.print(epilog)
101109
self.format_commands(ctx, formatter)
102110

103-
104111
def format_options(self, ctx, formatter):
105112
"""Prints out the options in a table format"""
106113

@@ -151,17 +158,17 @@ def format_commands(self, ctx, formatter):
151158
self.console.print("\n[bold orange1]Commands:[/]")
152159
self.console.print(command_table)
153160

161+
154162
class SLCommand(click.Command):
155163
"""Overloads click.Command to control how the help message is formatted."""
156164

157-
def __init__(self, *path, **attrs):
165+
def __init__(self, **attrs):
158166
click.Command.__init__(self, **attrs)
159167
self.highlighter = OptionHighlighter()
160168
self.console = Console(
161169
theme=SLCLI_THEME
162170
)
163171

164-
165172
def format_usage(self, ctx: click.Context, formatter: click.formatting.HelpFormatter) -> None:
166173
"""Formats and colorizes the usage information."""
167174
pieces = self.collect_usage_pieces(ctx)
@@ -178,7 +185,7 @@ def format_help_text(self, ctx: click.Context, formatter: click.formatting.HelpF
178185
text = self.help if self.help is not None else ""
179186

180187
if self.deprecated:
181-
text = _("(Deprecated) {text}").format(text=text)
188+
text = f"(Deprecated) {text}"
182189

183190
if text:
184191
text = inspect.cleandoc(text)
@@ -195,8 +202,8 @@ def format_epilog(self, ctx: click.Context, formatter: click.formatting.HelpForm
195202
def format_options(self, ctx, formatter):
196203
"""Prints out the options in a table format"""
197204

198-
## TODO support binary options --yes/--no
199-
## SUPPORT color for IDENTIFIER and such
205+
# NEXT support binary options --yes/--no
206+
# NEXT SUPPORT color for IDENTIFIER and such
200207
options_table = Table(highlight=True, box=box.SQUARE, show_header=False)
201208

202209
for param in self.get_params(ctx):

SoftLayer/CLI/config/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def get_api_key(client, username, secret): # pylint: disable=inconsistent-retur
4747
return api_keys[0]['authenticationKey']
4848

4949

50-
@click.command()
50+
@click.command(cls=SLCommand)
5151
@click.option('-a', '--auth', type=click.Choice(['ibmid', 'cloud_key', 'classic_key', 'sso']),
5252
help="Select a method of authentication.", default='classic_key', show_default=True)
5353
@environment.pass_env

SoftLayer/CLI/core.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,14 @@
55
66
:license: MIT, see LICENSE for more details.
77
"""
8-
import click
9-
108
import logging
119
import os
12-
import requests
1310
import sys
1411
import time
1512
import traceback
16-
import types
13+
14+
import click
15+
import requests
1716

1817
import SoftLayer
1918
from SoftLayer.CLI.command import CommandLoader
@@ -57,6 +56,8 @@ def get_latest_version():
5756
auto_envvar_prefix='SLCLI',
5857
max_content_width=999
5958
)
59+
60+
6061
def get_version_message(ctx, param, value):
6162
"""Gets current and latest release versions message."""
6263
if not value or ctx.resilient_parsing:

SoftLayer/CLI/dedicatedhost/create.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
from SoftLayer.CLI import template
1111

1212

13-
@click.command(cls=SoftLayer.CLI.command.SLCommand,
14-
epilog="See 'slcli dedicatedhost create-options' for valid options.")
13+
@click.command(cls=SoftLayer.CLI.command.SLCommand,
14+
epilog="See 'slcli dedicatedhost create-options' for valid options.")
1515
@click.option('--hostname', '-H',
1616
help="Host portion of the FQDN",
1717
required=True,

SoftLayer/CLI/file/replication/disaster_recovery_failover.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
from SoftLayer.CLI import formatting
99

1010

11-
@click.command(cls=SoftLayer.CLI.command.SLCommand, epilog="""Failover an inaccessible file volume to its available replicant volume.
11+
@click.command(cls=SoftLayer.CLI.command.SLCommand,
12+
epilog="""Failover an inaccessible file volume to its available replicant volume.
1213
If a volume (with replication) becomes inaccessible due to a disaster event, this method can be used to immediately
1314
failover to an available replica in another location. This method does not allow for failback via API.
1415
After using this method, to failback to the original volume, please open a support ticket.

SoftLayer/CLI/globalip/assign.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
@click.command(cls=SoftLayer.CLI.command.SLCommand, epilog="More information about types and identifiers "
16-
"on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
16+
"on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
1717
@click.argument('identifier')
1818
@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']),
1919
help='choose the type. vlan, ip, hardware, vsi')

SoftLayer/CLI/subnet/route.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414

1515
@click.command(cls=SoftLayer.CLI.command.SLCommand, epilog="More information about types and identifiers "
16-
"on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
16+
"on https://sldn.softlayer.com/reference/services/SoftLayer_Network_Subnet/route/")
1717
@click.argument('identifier')
1818
@click.option('--target', type=click.Choice(['vlan', 'ip', 'hardware', 'vsi']),
1919
help='choose the type. vlan, ip, hardware, vsi')

SoftLayer/CLI/virt/capacity/create.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""Create a Reserved Capacity instance."""
22

33
import click
4-
from rich.text import Text
54

65
from SoftLayer.CLI.command import SLCommand as SLCommand
76
from SoftLayer.CLI import environment

SoftLayer/CLI/virt/capacity/detail.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import click
44

5-
from SoftLayer.CLI.command import SLCommand as SLCommand
65
from SoftLayer.CLI import columns as column_helper
6+
from SoftLayer.CLI.command import SLCommand as SLCommand
77
from SoftLayer.CLI import environment
88
from SoftLayer.CLI import formatting
99
from SoftLayer.managers.vs_capacity import CapacityManager as CapacityManager

0 commit comments

Comments
 (0)