From 6c180312ef9ea9a22727e8dd01cdf0553df6028f Mon Sep 17 00:00:00 2001
From: Thomas Mangin <thomas.mangin@exa.net.uk>
Date: Sat, 7 Mar 2020 23:17:31 +0000
Subject: ping: T31: fix and improve autocomplete

---
 scripts/ping | 65 ++++++++++++++++++++++++++++++++++--------------------------
 1 file changed, 37 insertions(+), 28 deletions(-)

(limited to 'scripts')

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}')
+
-- 
cgit v1.2.3


From 2c1d2a03e950112bff995e6070020a7f74912b35 Mon Sep 17 00:00:00 2001
From: Thomas Mangin <thomas.mangin@exa.net.uk>
Date: Sat, 7 Mar 2020 23:25:58 +0000
Subject: ping: T31: using vrf requires sudo

---
 scripts/ping | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

(limited to 'scripts')

diff --git a/scripts/ping b/scripts/ping
index 5be9b82..60430d6 100755
--- a/scripts/ping
+++ b/scripts/ping
@@ -136,7 +136,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'
     },
-- 
cgit v1.2.3