diff --git a/clear/bgp_frr_v6.py b/clear/bgp_frr_v6.py index 58c50e28d9..1ebb6c92cd 100644 --- a/clear/bgp_frr_v6.py +++ b/clear/bgp_frr_v6.py @@ -14,33 +14,23 @@ def bgp(): """Clear IPv6 BGP (Border Gateway Protocol) information""" pass - -# Default 'bgp' command (called if no subcommands or their aliases were passed) -@bgp.command(default=True) -def default(): - """Clear all BGP peers""" - command = 'sudo vtysh -c "clear bgp ipv6 *"' - run_command(command) - - @bgp.group() def neighbor(): """Clear specific BGP peers""" pass - -@neighbor.command(default=True) +# 'all' subcommand +@neighbor.command('all') @click.argument('ipaddress', required=False) -def default(ipaddress): +def neigh_all(ipaddress): """Clear all BGP peers""" if ipaddress is not None: - command = 'sudo vtysh -c "clear bgp ipv6 {} "'.format(ipaddress) + command = 'sudo vtysh -c "clear bgp ipv6 {}"'.format(ipaddress) else: command = 'sudo vtysh -c "clear bgp ipv6 *"' run_command(command) - # 'in' subcommand @neighbor.command('in') @click.argument('ipaddress', required=False) @@ -72,19 +62,6 @@ def soft(): """Soft reconfig BGP's inbound/outbound updates""" pass - -@soft.command(default=True) -@click.argument('ipaddress', required=False) -def default(ipaddress): - """Clear BGP neighbors soft configuration""" - - if ipaddress is not None: - command = 'sudo vtysh -c "clear bgp ipv6 {} soft "'.format(ipaddress) - else: - command = 'sudo vtysh -c "clear bgp ipv6 * soft"' - run_command(command) - - # 'soft in' subcommand @soft.command('in') @click.argument('ipaddress', required=False) @@ -98,6 +75,18 @@ def soft_in(ipaddress): run_command(command) +# 'soft all' subcommand +@neighbor.command('all') +@click.argument('ipaddress', required=False) +def soft_all(ipaddress): + """Clear BGP neighbors soft configuration""" + + if ipaddress is not None: + command = 'sudo vtysh -c "clear bgp ipv6 {} soft"'.format(ipaddress) + else: + command = 'sudo vtysh -c "clear bgp ipv6 * soft"' + run_command(command) + # 'soft out' subcommand @soft.command('out') @click.argument('ipaddress', required=False) diff --git a/clear/bgp_quagga_v4.py b/clear/bgp_quagga_v4.py index 56675953ca..4ebc5a1f95 100644 --- a/clear/bgp_quagga_v4.py +++ b/clear/bgp_quagga_v4.py @@ -15,27 +15,19 @@ def bgp(): pass -# Default 'bgp' command (called if no subcommands or their aliases were passed) -@bgp.command(default=True) -def default(): - """Clear all BGP peers""" - command = 'sudo vtysh -c "clear ip bgp *"' - run_command(command) - - @bgp.group() def neighbor(): """Clear specific BGP peers""" pass -@neighbor.command(default=True) +@neighbor.command('all') @click.argument('ipaddress', required=False) -def default(ipaddress): +def neigh_all(ipaddress): """Clear all BGP peers""" if ipaddress is not None: - command = 'sudo vtysh -c "clear ip bgp {} "'.format(ipaddress) + command = 'sudo vtysh -c "clear ip bgp {}"'.format(ipaddress) else: command = 'sudo vtysh -c "clear ip bgp *"' run_command(command) @@ -73,13 +65,13 @@ def soft(): pass -@soft.command(default=True) +@soft.command('all') @click.argument('ipaddress', required=False) -def default(ipaddress): +def soft_all(ipaddress): """Clear BGP neighbors soft configuration""" if ipaddress is not None: - command = 'sudo vtysh -c "clear ip bgp {} soft "'.format(ipaddress) + command = 'sudo vtysh -c "clear ip bgp {} soft"'.format(ipaddress) else: command = 'sudo vtysh -c "clear ip bgp * soft"' run_command(command) diff --git a/clear/bgp_quagga_v6.py b/clear/bgp_quagga_v6.py index ad6758d2af..fcfe3ed1fb 100644 --- a/clear/bgp_quagga_v6.py +++ b/clear/bgp_quagga_v6.py @@ -14,28 +14,18 @@ def bgp(): """Clear IPv6 BGP (Border Gateway Protocol) information""" pass - -# Default 'bgp' command (called if no subcommands or their aliases were passed) -@bgp.command(default=True) -def default(): - """Clear all BGP peers""" - command = 'sudo vtysh -c "clear ipv6 bgp *"' - run_command(command) - - @bgp.group() def neighbor(): """Clear specific BGP peers""" pass - -@neighbor.command(default=True) +@neighbor.command('all') @click.argument('ipaddress', required=False) -def default(ipaddress): +def neigh_all(ipaddress): """Clear all BGP peers""" if ipaddress is not None: - command = 'sudo vtysh -c "clear ipv6 bgp {} "'.format(ipaddress) + command = 'sudo vtysh -c "clear ipv6 bgp {}"'.format(ipaddress) else: command = 'sudo vtysh -c "clear ipv6 bgp *"' run_command(command) @@ -73,13 +63,13 @@ def soft(): pass -@soft.command(default=True) +@soft.command('all') @click.argument('ipaddress', required=False) -def default(ipaddress): +def soft_all(ipaddress): """Clear BGP neighbors soft configuration""" if ipaddress is not None: - command = 'sudo vtysh -c "clear ipv6 bgp {} soft "'.format(ipaddress) + command = 'sudo vtysh -c "clear ipv6 bgp {} soft"'.format(ipaddress) else: command = 'sudo vtysh -c "clear ipv6 bgp * soft"' run_command(command) diff --git a/clear/main.py b/clear/main.py index 669c87567a..eec3a62b8f 100755 --- a/clear/main.py +++ b/clear/main.py @@ -3,7 +3,6 @@ import click import os import subprocess -from click_default_group import DefaultGroup try: # noinspection PyPep8Naming @@ -35,12 +34,10 @@ def read_config(self, filename): _config = None -# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group. -# DefaultFroup is a superclass of click.Group which calls a default subcommand instead of showing -# a help message if no subcommand is passed -class AliasedGroup(DefaultGroup): - """This subclass of a DefaultGroup supports looking up aliases in a config - file and with a bit of magic. + +class AliasedGroup(click.Group): + """This subclass of click.Group supports abbreviations and + looking up aliases in a config file with a bit of magic. """ def get_command(self, ctx, cmd_name): @@ -71,12 +68,9 @@ def get_command(self, ctx, cmd_name): matches = [x for x in self.list_commands(ctx) if x.lower().startswith(cmd_name.lower())] if not matches: - # No command name matched. Issue Default command. - ctx.arg0 = cmd_name - cmd_name = self.default_cmd_name - return DefaultGroup.get_command(self, ctx, cmd_name) + return None elif len(matches) == 1: - return DefaultGroup.get_command(self, ctx, matches[0]) + return click.Group.get_command(self, ctx, matches[0]) ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) @@ -384,7 +378,7 @@ def line(linenum): # 'nat' group ("clear nat ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def nat(): """Clear the nat info""" pass diff --git a/config/main.py b/config/main.py index 709688cdf9..c3c9b6a62d 100755 --- a/config/main.py +++ b/config/main.py @@ -14,7 +14,6 @@ import ipaddress from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig from minigraph import parse_device_desc_xml -from click_default_group import DefaultGroup import aaa import mlnx @@ -63,12 +62,8 @@ def log_error(msg): syslog.closelog() -# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group. -# DefaultGroup is a superclass of click.Group which calls a default subcommand instead of showing -# a help message if no subcommand is passed -class AbbreviationGroup(DefaultGroup): - """This subclass of a DefaultGroup supports looking up aliases in a config - file and with a bit of magic. +class AbbreviationGroup(click.Group): + """This subclass of click.Group supports abbreviated subgroup/subcommand names """ def get_command(self, ctx, cmd_name): @@ -93,18 +88,15 @@ def get_command(self, ctx, cmd_name): shortest = x if not matches: - # No command name matched. Issue Default command. - ctx.arg0 = cmd_name - cmd_name = self.default_cmd_name - return DefaultGroup.get_command(self, ctx, cmd_name) + return None elif len(matches) == 1: - return DefaultGroup.get_command(self, ctx, matches[0]) + return click.Group.get_command(self, ctx, matches[0]) else: for x in matches: if not x.startswith(shortest): break else: - return DefaultGroup.get_command(self, ctx, shortest) + return click.Group.get_command(self, ctx, shortest) ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) diff --git a/connect/main.py b/connect/main.py index b34ee11aab..ef40af3bbb 100755 --- a/connect/main.py +++ b/connect/main.py @@ -3,7 +3,6 @@ import click import os import pexpect -from click_default_group import DefaultGroup try: # noinspection PyPep8Naming @@ -35,12 +34,9 @@ def read_config(self, filename): _config = None -# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group. -# DefaultGroup is a superclass of click.Group which calls a default subcommand instead of showing -# a help message if no subcommand is passed -class AliasedGroup(DefaultGroup): - """This subclass of a DefaultGroup supports looking up aliases in a config - file and with a bit of magic. +class AliasedGroup(click.Group): + """This subclass of click.Group supports abbreviations and + looking up aliases in a config file with a bit of magic. """ def get_command(self, ctx, cmd_name): @@ -71,12 +67,9 @@ def get_command(self, ctx, cmd_name): matches = [x for x in self.list_commands(ctx) if x.lower().startswith(cmd_name.lower())] if not matches: - # No command name matched. Issue Default command. - ctx.arg0 = cmd_name - cmd_name = self.default_cmd_name - return DefaultGroup.get_command(self, ctx, cmd_name) + return None elif len(matches) == 1: - return DefaultGroup.get_command(self, ctx, matches[0]) + return click.Group.get_command(self, ctx, matches[0]) ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) def run_command(command, display_cmd=False): diff --git a/debug/main.py b/debug/main.py index b72394b22d..cbcca05064 100755 --- a/debug/main.py +++ b/debug/main.py @@ -3,7 +3,6 @@ import click import subprocess -from click_default_group import DefaultGroup def run_command(command, pager=False): click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) @@ -192,17 +191,13 @@ def vxlan(): # # 'bgp' group for quagga ### # - @cli.group(cls=DefaultGroup, default_if_no_args=True) - #@cli.group() - def bgp(): - """debug bgp on """ - pass - - @bgp.command(default=True) - def default(): - """debug bgp""" - command = 'sudo vtysh -c "debug bgp"' - run_command(command) + @cli.group(invoke_without_command=True) + @click.pass_context + def bgp(ctx): + """debug bgp on""" + if ctx.invoked_subcommand is None: + command = 'sudo vtysh -c "debug bgp"' + run_command(command) @bgp.command() def events(): diff --git a/setup.py b/setup.py index 2924566c7d..a1fece9118 100644 --- a/setup.py +++ b/setup.py @@ -144,7 +144,6 @@ # - swsssdk # - tabulate install_requires=[ - 'click-default-group', 'click', 'natsort' ], diff --git a/show/main.py b/show/main.py index 05d0e37864..5c19ce6167 100755 --- a/show/main.py +++ b/show/main.py @@ -11,7 +11,6 @@ from pkg_resources import parse_version import click -from click_default_group import DefaultGroup from natsort import natsorted from tabulate import tabulate @@ -119,12 +118,9 @@ def alias_to_name(self, interface_alias): _config = None -# This aliased group has been modified from click examples to inherit from DefaultGroup instead of click.Group. -# DefaultGroup is a superclass of click.Group which calls a default subcommand instead of showing -# a help message if no subcommand is passed -class AliasedGroup(DefaultGroup): - """This subclass of a DefaultGroup supports looking up aliases in a config - file and with a bit of magic. +class AliasedGroup(click.Group): + """This subclass of click.Group supports abbreviations and + looking up aliases in a config file with a bit of magic. """ def get_command(self, ctx, cmd_name): @@ -155,12 +151,9 @@ def get_command(self, ctx, cmd_name): matches = [x for x in self.list_commands(ctx) if x.lower().startswith(cmd_name.lower())] if not matches: - # No command name matched. Issue Default command. - ctx.arg0 = cmd_name - cmd_name = self.default_cmd_name - return DefaultGroup.get_command(self, ctx, cmd_name) + return None elif len(matches) == 1: - return DefaultGroup.get_command(self, ctx, matches[0]) + return click.Group.get_command(self, ctx, matches[0]) ctx.fail('Too many matches: %s' % ', '.join(sorted(matches))) @@ -685,7 +678,7 @@ def mgmt_vrf(ctx,routes): # 'management_interface' group ("show management_interface ...") # -@cli.group(name='management_interface', cls=AliasedGroup, default_if_no_args=False) +@cli.group(name='management_interface', cls=AliasedGroup) def management_interface(): """Show management interface parameters""" pass @@ -751,7 +744,7 @@ def snmptrap (ctx): # 'interfaces' group ("show interfaces ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def interfaces(): """Show details of the network interfaces""" pass @@ -796,7 +789,7 @@ def alias(interfacename): # # 'neighbor' group ### # -@interfaces.group(cls=AliasedGroup, default_if_no_args=False) +@interfaces.group(cls=AliasedGroup) def neighbor(): """Show neighbor related information""" pass @@ -853,7 +846,7 @@ def expected(interfacename): click.echo(tabulate(body, header)) -@interfaces.group(cls=AliasedGroup, default_if_no_args=False) +@interfaces.group(cls=AliasedGroup) def transceiver(): """Show SFP Transceiver information""" pass @@ -1016,7 +1009,7 @@ def portchannel(verbose): # 'subinterfaces' group ("show subinterfaces ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def subinterfaces(): """Show details of the sub port interfaces""" pass @@ -1047,7 +1040,7 @@ def status(subinterfacename, verbose): # 'pfc' group ("show pfc ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def pfc(): """Show details of the priority-flow-control (pfc) """ pass @@ -1089,7 +1082,7 @@ def asymmetric(interface): run_command(cmd) # 'pfcwd' subcommand ("show pfcwd...") -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def pfcwd(): """Show details of the pfc watchdog """ pass @@ -1125,7 +1118,7 @@ def naming_mode(verbose): # 'watermark' group ("show watermark telemetry interval") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def watermark(): """Show details of watermark """ pass @@ -1146,7 +1139,7 @@ def show_tm_interval(): # 'queue' group ("show queue ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def queue(): """Show details of the queues """ pass @@ -1220,7 +1213,7 @@ def pwm_q_multi(): # 'priority-group' group ("show priority-group ...") # -@cli.group(name='priority-group', cls=AliasedGroup, default_if_no_args=False) +@cli.group(name='priority-group', cls=AliasedGroup) def priority_group(): """Show details of the PGs """ @@ -1263,7 +1256,7 @@ def pwm_pg_shared(): # 'buffer_pool' group ("show buffer_pool ...") # -@cli.group(name='buffer_pool', cls=AliasedGroup, default_if_no_args=False) +@cli.group(name='buffer_pool', cls=AliasedGroup) def buffer_pool(): """Show details of the buffer pools""" @@ -1321,7 +1314,7 @@ def route_map(route_map_name, verbose): # # This group houses IP (i.e., IPv4) commands and subgroups -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def ip(): """Show IP (IPv4) commands""" pass @@ -1504,7 +1497,7 @@ def protocol(verbose): # # This group houses IPv6-related commands and subgroups -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def ipv6(): """Show IPv6 commands""" pass @@ -1622,7 +1615,7 @@ def protocol(verbose): # 'lldp' group ("show lldp ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def lldp(): """LLDP (Link Layer Discovery Protocol) information""" pass @@ -1676,7 +1669,7 @@ def get_hw_info_dict(): hw_info_dict['asic_type'] = asic_type return hw_info_dict -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def platform(): """Show platform-specific hardware info""" pass @@ -1825,7 +1818,7 @@ def environment(verbose): # 'processes' group ("show processes ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def processes(): """Display process information""" pass @@ -1888,7 +1881,7 @@ def techsupport(since, verbose): # 'runningconfiguration' group ("show runningconfiguration") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def runningconfiguration(): """Show current running configuration information""" pass @@ -2002,7 +1995,7 @@ def syslog(verbose): # 'startupconfiguration' group ("show startupconfiguration ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def startupconfiguration(): """Show startup configuration information""" pass @@ -2074,7 +2067,7 @@ def system_memory(verbose): cmd = "free -m" run_command(cmd, display_cmd=verbose) -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def vlan(): """Show VLAN information""" pass @@ -2082,7 +2075,7 @@ def vlan(): # # 'kdump command ("show kdump ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=True, ) +@cli.group(cls=AliasedGroup) def kdump(): """Show kdump configuration, status and information """ pass @@ -2105,7 +2098,7 @@ def enabled(): else: click.echo("kdump is disabled") -@kdump.command('status', default=True) +@kdump.command('status') def status(): """Show kdump status""" run_command("sonic-kdump-config --status") @@ -2478,7 +2471,7 @@ def show_sflow_global(config_db): # 'acl' group ### # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def acl(): """Show ACL related information""" pass @@ -2520,7 +2513,7 @@ def table(table_name, verbose): # 'dropcounters' group ### # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def dropcounters(): """Show drop counter related information""" pass @@ -2631,7 +2624,7 @@ def line(): return -@cli.group(name='warm_restart', cls=AliasedGroup, default_if_no_args=False) +@cli.group(name='warm_restart', cls=AliasedGroup) def warm_restart(): """Show warm restart configuration and state""" pass @@ -2757,7 +2750,7 @@ def tablelize(keys, data, enable_table_keys, prefix): # 'nat' group ("show nat ...") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def nat(): """Show details of the nat """ pass @@ -2928,7 +2921,7 @@ def autorestart(container_name): # # 'vnet' command ("show vnet") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def vnet(): """Show vnet related information""" pass @@ -3153,7 +3146,7 @@ def tunnel(): # # 'vxlan' command ("show vxlan") # -@cli.group(cls=AliasedGroup, default_if_no_args=False) +@cli.group(cls=AliasedGroup) def vxlan(): """Show vxlan related information""" pass diff --git a/undebug/main.py b/undebug/main.py index a148445f73..313c551cb6 100644 --- a/undebug/main.py +++ b/undebug/main.py @@ -3,7 +3,6 @@ import click import subprocess -from click_default_group import DefaultGroup def run_command(command, pager=False): click.echo(click.style("Command: ", fg='cyan') + click.style(command, fg='green')) @@ -192,57 +191,53 @@ def vxlan(): # # 'bgp' group for quagga ### # - @cli.group(cls=DefaultGroup, default_if_no_args=True) - #@cli.group() - def bgp(): - """debug bgp on """ - pass - - @bgp.command(default=True) - def default(): - """debug bgp""" - command = 'sudo vtysh -c "no debug bgp"' - run_command(command) + @cli.group(invoke_without_command=True) + @click.pass_context + def bgp(ctx): + """debug bgp off""" + if ctx.invoked_subcommand is None: + command = 'sudo vtysh -c "no debug bgp"' + run_command(command) @bgp.command() def events(): - """debug bgp events on""" + """debug bgp events off""" command = 'sudo vtysh -c "no debug bgp events"' run_command(command) @bgp.command() def updates(): - """debug bgp updates on""" + """debug bgp updates off""" command = 'sudo vtysh -c "no debug bgp updates"' run_command(command) @bgp.command() def as4(): - """debug bgp as4 actions on""" + """debug bgp as4 actions off""" command = 'sudo vtysh -c "no debug bgp as4"' run_command(command) @bgp.command() def filters(): - """debug bgp filters on""" + """debug bgp filters off""" command = 'sudo vtysh -c "no debug bgp filters"' run_command(command) @bgp.command() def fsm(): - """debug bgp finite state machine on""" + """debug bgp finite state machine off""" command = 'sudo vtysh -c "no debug bgp fsm"' run_command(command) @bgp.command() def keepalives(): - """debug bgp keepalives on""" + """debug bgp keepalives off""" command = 'sudo vtysh -c "no debug bgp keepalives"' run_command(command) @bgp.command() def zebra(): - """debug bgp zebra messages on""" + """debug bgp zebra messages off""" command = 'sudo vtysh -c "no debug bgp zebra"' run_command(command)