summaryrefslogtreecommitdiff
path: root/scripts/ping
diff options
context:
space:
mode:
authorThomas Mangin <thomas.mangin@exa.net.uk>2020-03-07 23:17:31 +0000
committerThomas Mangin <thomas.mangin@exa.net.uk>2020-03-07 23:17:31 +0000
commit6c180312ef9ea9a22727e8dd01cdf0553df6028f (patch)
treefff2c3cb3ac5de02ecc3d29e4ac6befb78def009 /scripts/ping
parentcc97c7b02c251c64e11de34ff8ec8f535c3efdac (diff)
downloadvyatta-op-6c180312ef9ea9a22727e8dd01cdf0553df6028f.tar.gz
vyatta-op-6c180312ef9ea9a22727e8dd01cdf0553df6028f.zip
ping: T31: fix and improve autocomplete
Diffstat (limited to 'scripts/ping')
-rwxr-xr-xscripts/ping65
1 files changed, 37 insertions, 28 deletions
diff --git a/scripts/ping b/scripts/ping
index e84ddd9..5be9b82 100755
--- a/scripts/ping
+++ b/scripts/ping
@@ -1,22 +1,19 @@
#! /usr/bin/env python3
-# Wrapper around the base Linux ping command to provide
-# nicer API (ie no flag arguments)
+# Copyright 2020 VyOS maintainers and contributors <maintainers@vyos.io>
#
-# **** License ****
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License version 2 as
-# published by the Free Software Foundation.
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# This code was originally developed by Vyatta, Inc.
-# Portions created by Vyatta are Copyright (C) 2012 Vyatta, Inc.
-# All Rights Reserved.
+# Lesser General Public License for more details.
#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library. If not, see <http://www.gnu.org/licenses/>.
#
# Syntax
# ping HOST
@@ -162,6 +159,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'
@@ -204,21 +204,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:
@@ -228,3 +236,4 @@ if __name__ == '__main__':
# print(f'{command} {host}')
os.system(f'{command} {host}')
+