Skip to content

Commit f57b487

Browse files
authored
Remove dependency on click-default-group package (sonic-net#903)
1 parent 45eb491 commit f57b487

File tree

10 files changed

+98
-166
lines changed

10 files changed

+98
-166
lines changed

clear/bgp_frr_v6.py

+16-27
Original file line numberDiff line numberDiff line change
@@ -14,33 +14,23 @@ def bgp():
1414
"""Clear IPv6 BGP (Border Gateway Protocol) information"""
1515
pass
1616

17-
18-
# Default 'bgp' command (called if no subcommands or their aliases were passed)
19-
@bgp.command(default=True)
20-
def default():
21-
"""Clear all BGP peers"""
22-
command = 'sudo vtysh -c "clear bgp ipv6 *"'
23-
run_command(command)
24-
25-
2617
@bgp.group()
2718
def neighbor():
2819
"""Clear specific BGP peers"""
2920
pass
3021

31-
32-
@neighbor.command(default=True)
22+
# 'all' subcommand
23+
@neighbor.command('all')
3324
@click.argument('ipaddress', required=False)
34-
def default(ipaddress):
25+
def neigh_all(ipaddress):
3526
"""Clear all BGP peers"""
3627

3728
if ipaddress is not None:
38-
command = 'sudo vtysh -c "clear bgp ipv6 {} "'.format(ipaddress)
29+
command = 'sudo vtysh -c "clear bgp ipv6 {}"'.format(ipaddress)
3930
else:
4031
command = 'sudo vtysh -c "clear bgp ipv6 *"'
4132
run_command(command)
4233

43-
4434
# 'in' subcommand
4535
@neighbor.command('in')
4636
@click.argument('ipaddress', required=False)
@@ -72,19 +62,6 @@ def soft():
7262
"""Soft reconfig BGP's inbound/outbound updates"""
7363
pass
7464

75-
76-
@soft.command(default=True)
77-
@click.argument('ipaddress', required=False)
78-
def default(ipaddress):
79-
"""Clear BGP neighbors soft configuration"""
80-
81-
if ipaddress is not None:
82-
command = 'sudo vtysh -c "clear bgp ipv6 {} soft "'.format(ipaddress)
83-
else:
84-
command = 'sudo vtysh -c "clear bgp ipv6 * soft"'
85-
run_command(command)
86-
87-
8865
# 'soft in' subcommand
8966
@soft.command('in')
9067
@click.argument('ipaddress', required=False)
@@ -98,6 +75,18 @@ def soft_in(ipaddress):
9875
run_command(command)
9976

10077

78+
# 'soft all' subcommand
79+
@neighbor.command('all')
80+
@click.argument('ipaddress', required=False)
81+
def soft_all(ipaddress):
82+
"""Clear BGP neighbors soft configuration"""
83+
84+
if ipaddress is not None:
85+
command = 'sudo vtysh -c "clear bgp ipv6 {} soft"'.format(ipaddress)
86+
else:
87+
command = 'sudo vtysh -c "clear bgp ipv6 * soft"'
88+
run_command(command)
89+
10190
# 'soft out' subcommand
10291
@soft.command('out')
10392
@click.argument('ipaddress', required=False)

clear/bgp_quagga_v4.py

+6-14
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,19 @@ def bgp():
1515
pass
1616

1717

18-
# Default 'bgp' command (called if no subcommands or their aliases were passed)
19-
@bgp.command(default=True)
20-
def default():
21-
"""Clear all BGP peers"""
22-
command = 'sudo vtysh -c "clear ip bgp *"'
23-
run_command(command)
24-
25-
2618
@bgp.group()
2719
def neighbor():
2820
"""Clear specific BGP peers"""
2921
pass
3022

3123

32-
@neighbor.command(default=True)
24+
@neighbor.command('all')
3325
@click.argument('ipaddress', required=False)
34-
def default(ipaddress):
26+
def neigh_all(ipaddress):
3527
"""Clear all BGP peers"""
3628

3729
if ipaddress is not None:
38-
command = 'sudo vtysh -c "clear ip bgp {} "'.format(ipaddress)
30+
command = 'sudo vtysh -c "clear ip bgp {}"'.format(ipaddress)
3931
else:
4032
command = 'sudo vtysh -c "clear ip bgp *"'
4133
run_command(command)
@@ -73,13 +65,13 @@ def soft():
7365
pass
7466

7567

76-
@soft.command(default=True)
68+
@soft.command('all')
7769
@click.argument('ipaddress', required=False)
78-
def default(ipaddress):
70+
def soft_all(ipaddress):
7971
"""Clear BGP neighbors soft configuration"""
8072

8173
if ipaddress is not None:
82-
command = 'sudo vtysh -c "clear ip bgp {} soft "'.format(ipaddress)
74+
command = 'sudo vtysh -c "clear ip bgp {} soft"'.format(ipaddress)
8375
else:
8476
command = 'sudo vtysh -c "clear ip bgp * soft"'
8577
run_command(command)

clear/bgp_quagga_v6.py

+6-16
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,18 @@ def bgp():
1414
"""Clear IPv6 BGP (Border Gateway Protocol) information"""
1515
pass
1616

17-
18-
# Default 'bgp' command (called if no subcommands or their aliases were passed)
19-
@bgp.command(default=True)
20-
def default():
21-
"""Clear all BGP peers"""
22-
command = 'sudo vtysh -c "clear ipv6 bgp *"'
23-
run_command(command)
24-
25-
2617
@bgp.group()
2718
def neighbor():
2819
"""Clear specific BGP peers"""
2920
pass
3021

31-
32-
@neighbor.command(default=True)
22+
@neighbor.command('all')
3323
@click.argument('ipaddress', required=False)
34-
def default(ipaddress):
24+
def neigh_all(ipaddress):
3525
"""Clear all BGP peers"""
3626

3727
if ipaddress is not None:
38-
command = 'sudo vtysh -c "clear ipv6 bgp {} "'.format(ipaddress)
28+
command = 'sudo vtysh -c "clear ipv6 bgp {}"'.format(ipaddress)
3929
else:
4030
command = 'sudo vtysh -c "clear ipv6 bgp *"'
4131
run_command(command)
@@ -73,13 +63,13 @@ def soft():
7363
pass
7464

7565

76-
@soft.command(default=True)
66+
@soft.command('all')
7767
@click.argument('ipaddress', required=False)
78-
def default(ipaddress):
68+
def soft_all(ipaddress):
7969
"""Clear BGP neighbors soft configuration"""
8070

8171
if ipaddress is not None:
82-
command = 'sudo vtysh -c "clear ipv6 bgp {} soft "'.format(ipaddress)
72+
command = 'sudo vtysh -c "clear ipv6 bgp {} soft"'.format(ipaddress)
8373
else:
8474
command = 'sudo vtysh -c "clear ipv6 bgp * soft"'
8575
run_command(command)

clear/main.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import click
44
import os
55
import subprocess
6-
from click_default_group import DefaultGroup
76

87
try:
98
# noinspection PyPep8Naming
@@ -35,12 +34,10 @@ def read_config(self, filename):
3534
_config = None
3635

3736

38-
# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group.
39-
# DefaultFroup is a superclass of click.Group which calls a default subcommand instead of showing
40-
# a help message if no subcommand is passed
41-
class AliasedGroup(DefaultGroup):
42-
"""This subclass of a DefaultGroup supports looking up aliases in a config
43-
file and with a bit of magic.
37+
38+
class AliasedGroup(click.Group):
39+
"""This subclass of click.Group supports abbreviations and
40+
looking up aliases in a config file with a bit of magic.
4441
"""
4542

4643
def get_command(self, ctx, cmd_name):
@@ -71,12 +68,9 @@ def get_command(self, ctx, cmd_name):
7168
matches = [x for x in self.list_commands(ctx)
7269
if x.lower().startswith(cmd_name.lower())]
7370
if not matches:
74-
# No command name matched. Issue Default command.
75-
ctx.arg0 = cmd_name
76-
cmd_name = self.default_cmd_name
77-
return DefaultGroup.get_command(self, ctx, cmd_name)
71+
return None
7872
elif len(matches) == 1:
79-
return DefaultGroup.get_command(self, ctx, matches[0])
73+
return click.Group.get_command(self, ctx, matches[0])
8074
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
8175

8276

@@ -384,7 +378,7 @@ def line(linenum):
384378
# 'nat' group ("clear nat ...")
385379
#
386380

387-
@cli.group(cls=AliasedGroup, default_if_no_args=False)
381+
@cli.group(cls=AliasedGroup)
388382
def nat():
389383
"""Clear the nat info"""
390384
pass

config/main.py

+5-13
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import ipaddress
1515
from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig
1616
from minigraph import parse_device_desc_xml
17-
from click_default_group import DefaultGroup
1817

1918
import aaa
2019
import mlnx
@@ -63,12 +62,8 @@ def log_error(msg):
6362
syslog.closelog()
6463

6564

66-
# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group.
67-
# DefaultGroup is a superclass of click.Group which calls a default subcommand instead of showing
68-
# a help message if no subcommand is passed
69-
class AbbreviationGroup(DefaultGroup):
70-
"""This subclass of a DefaultGroup supports looking up aliases in a config
71-
file and with a bit of magic.
65+
class AbbreviationGroup(click.Group):
66+
"""This subclass of click.Group supports abbreviated subgroup/subcommand names
7267
"""
7368

7469
def get_command(self, ctx, cmd_name):
@@ -93,18 +88,15 @@ def get_command(self, ctx, cmd_name):
9388
shortest = x
9489

9590
if not matches:
96-
# No command name matched. Issue Default command.
97-
ctx.arg0 = cmd_name
98-
cmd_name = self.default_cmd_name
99-
return DefaultGroup.get_command(self, ctx, cmd_name)
91+
return None
10092
elif len(matches) == 1:
101-
return DefaultGroup.get_command(self, ctx, matches[0])
93+
return click.Group.get_command(self, ctx, matches[0])
10294
else:
10395
for x in matches:
10496
if not x.startswith(shortest):
10597
break
10698
else:
107-
return DefaultGroup.get_command(self, ctx, shortest)
99+
return click.Group.get_command(self, ctx, shortest)
108100

109101
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
110102

connect/main.py

+5-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import click
44
import os
55
import pexpect
6-
from click_default_group import DefaultGroup
76

87
try:
98
# noinspection PyPep8Naming
@@ -35,12 +34,9 @@ def read_config(self, filename):
3534
_config = None
3635

3736

38-
# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group.
39-
# DefaultGroup is a superclass of click.Group which calls a default subcommand instead of showing
40-
# a help message if no subcommand is passed
41-
class AliasedGroup(DefaultGroup):
42-
"""This subclass of a DefaultGroup supports looking up aliases in a config
43-
file and with a bit of magic.
37+
class AliasedGroup(click.Group):
38+
"""This subclass of click.Group supports abbreviations and
39+
looking up aliases in a config file with a bit of magic.
4440
"""
4541

4642
def get_command(self, ctx, cmd_name):
@@ -71,12 +67,9 @@ def get_command(self, ctx, cmd_name):
7167
matches = [x for x in self.list_commands(ctx)
7268
if x.lower().startswith(cmd_name.lower())]
7369
if not matches:
74-
# No command name matched. Issue Default command.
75-
ctx.arg0 = cmd_name
76-
cmd_name = self.default_cmd_name
77-
return DefaultGroup.get_command(self, ctx, cmd_name)
70+
return None
7871
elif len(matches) == 1:
79-
return DefaultGroup.get_command(self, ctx, matches[0])
72+
return click.Group.get_command(self, ctx, matches[0])
8073
ctx.fail('Too many matches: %s' % ', '.join(sorted(matches)))
8174

8275
def run_command(command, display_cmd=False):

debug/main.py

+7-12
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import click
55
import subprocess
6-
from click_default_group import DefaultGroup
76

87
def run_command(command, pager=False):
98
click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green'))
@@ -192,17 +191,13 @@ def vxlan():
192191
#
193192
# 'bgp' group for quagga ###
194193
#
195-
@cli.group(cls=DefaultGroup, default_if_no_args=True)
196-
#@cli.group()
197-
def bgp():
198-
"""debug bgp on """
199-
pass
200-
201-
@bgp.command(default=True)
202-
def default():
203-
"""debug bgp"""
204-
command = 'sudo vtysh -c "debug bgp"'
205-
run_command(command)
194+
@cli.group(invoke_without_command=True)
195+
@click.pass_context
196+
def bgp(ctx):
197+
"""debug bgp on"""
198+
if ctx.invoked_subcommand is None:
199+
command = 'sudo vtysh -c "debug bgp"'
200+
run_command(command)
206201

207202
@bgp.command()
208203
def events():

setup.py

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@
144144
# - swsssdk
145145
# - tabulate
146146
install_requires=[
147-
'click-default-group',
148147
'click',
149148
'natsort'
150149
],

0 commit comments

Comments
 (0)