diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-03-08 01:10:31 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-08 01:10:31 +0100 |
commit | 833508908486f8ff5747d914e945afed5f0eb896 (patch) | |
tree | 43a2a320b5358460d950fb116f9cc751bd2fa0da /scripts/ping | |
parent | 77b4dc894551a6ff52d825799ea75ec0f3603074 (diff) | |
parent | 29db0d04ceec3ef4a869d8809f06b89051a3d430 (diff) | |
download | vyatta-op-833508908486f8ff5747d914e945afed5f0eb896.tar.gz vyatta-op-833508908486f8ff5747d914e945afed5f0eb896.zip |
Merge pull request #35 from thomas-mangin/current
ping: T31: fix vrf and autocomplete
Diffstat (limited to 'scripts/ping')
-rwxr-xr-x | scripts/ping | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/scripts/ping b/scripts/ping index 969e968..e41e334 100755 --- a/scripts/ping +++ b/scripts/ping @@ -1,5 +1,6 @@ #! /usr/bin/env python3 -# Copyright (C) 2018 VyOS maintainers and contributors + +# Copyright (C) 2020 VyOS maintainers and contributors # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 or later as @@ -114,7 +115,7 @@ options = { 'help': 'Maximum packet lifetime' }, 'vrf': { - 'ping': 'ip vrf exec {value} {command}', + 'ping': 'sudo ip vrf exec {value} {command}', 'type': '<vrf>', 'help': 'Use specified VRF table' }, @@ -137,6 +138,9 @@ class List (list): def last(self): return self.pop() if self else '' + def prepend(self,value): + self.insert(0,value) + def expension_failure(option, completions): reason = 'Ambiguous' if completions else 'Invalid' @@ -179,21 +183,29 @@ if __name__ == '__main__': sys.exit("ping: Missing host") if host == '--get-options': - option = args.first() - value = args.first() - - matched = complete(option) - - if not value: - sys.stdout.write(' '.join(matched)) - sys.exit(0) - - if len(matched) != 1: - sys.exit(0) - - sys.stdout.write(options[matched[0]]['type']) - sys.exit(0) - + args.first() # pop ping + args.first() # pop IP + while args: + option = args.first() + + matched = complete(option) + if not args: + sys.stdout.write(' '.join(matched)) + sys.exit(0) + + if len(matched) > 1 : + sys.stdout.write(' '.join(matched)) + sys.exit(0) + + if options[matched[0]]['type'] == 'noarg': + continue + + value = args.first() + if not args: + matched = complete(option) + sys.stdout.write(options[matched[0]]['type']) + sys.exit(0) + try: version = ipaddress.ip_address(host).version except ValueError: @@ -203,3 +215,4 @@ if __name__ == '__main__': # print(f'{command} {host}') os.system(f'{command} {host}') + |