[spp] [PATCH 2/2] cli: fix bug of completion in del command
yasufum.o at gmail.com
yasufum.o at gmail.com
Thu Oct 17 14:58:36 CEST 2019
From: Yasufumi Ogawa <yasufum.o at gmail.com>
In `pri` and `nfv` commands, `del` subcommand supports TAB completion
for candidate ports for deleting. However, inappropriate ports are
suggested because of bug for selecting the candidates. This update is
fix this issue.
Signed-off-by: Yasufumi Ogawa <yasufum.o at gmail.com>
---
src/cli/commands/nfv.py | 19 +++++++++++--------
src/cli/commands/pri.py | 19 +++++++++++--------
2 files changed, 22 insertions(+), 16 deletions(-)
diff --git a/src/cli/commands/nfv.py b/src/cli/commands/nfv.py
index 3bf4148..6349823 100644
--- a/src/cli/commands/nfv.py
+++ b/src/cli/commands/nfv.py
@@ -227,10 +227,11 @@ class SppNfv(object):
def _compl_del(self, sub_tokens):
"""Complete `del` command."""
+ res = []
# Del command consists of two tokens max, for instance,
# `nfv 1; del ring:1`.
if len(sub_tokens) < 3:
- res = []
+ tmp_ary = []
if self.use_cache is False:
self.ports, self.patches = self._get_ports_and_patches()
@@ -241,18 +242,20 @@ class SppNfv(object):
# Remove ports already used from candidate.
for kw in self.ports:
if not (kw in patched_ports):
- if kw.startswith(sub_tokens[1]):
+ if sub_tokens[1] == '':
+ tmp_ary.append(kw)
+ elif kw.startswith(sub_tokens[1]):
if ':' in sub_tokens[1]: # exp, 'ring:' or 'ring:0'
- res.append(kw.split(':')[1])
+ tmp_ary.append(kw.split(':')[1])
else:
- res.append(kw)
+ tmp_ary.append(kw)
# Physical port cannot be removed.
- for p in res:
- if p.startswith('phy:'):
- res.remove(p)
+ for p in tmp_ary:
+ if not p.startswith('phy:'):
+ res.append(p)
- return res
+ return res
def _compl_patch(self, sub_tokens):
"""Complete `patch` command."""
diff --git a/src/cli/commands/pri.py b/src/cli/commands/pri.py
index f4cda74..bee0d81 100644
--- a/src/cli/commands/pri.py
+++ b/src/cli/commands/pri.py
@@ -569,10 +569,11 @@ class SppPrimary(object):
def _compl_del(self, sub_tokens):
"""Complete `del` command."""
+ res = []
# Del command consists of two tokens max, for instance,
# `nfv 1; del ring:1`.
if len(sub_tokens) < 3:
- res = []
+ tmp_ary = []
self.ports, self.patches = self._get_ports_and_patches()
@@ -582,18 +583,20 @@ class SppPrimary(object):
# Remove ports already used from candidate.
for kw in self.ports:
if not (kw in patched_ports):
- if kw.startswith(sub_tokens[1]):
+ if sub_tokens[1] == '':
+ tmp_ary.append(kw)
+ elif kw.startswith(sub_tokens[1]):
if ':' in sub_tokens[1]: # exp, 'ring:' or 'ring:0'
- res.append(kw.split(':')[1])
+ tmp_ary.append(kw.split(':')[1])
else:
- res.append(kw)
+ tmp_ary.append(kw)
# Physical port cannot be removed.
- for p in res:
- if p.startswith('phy:'):
- res.remove(p)
+ for p in tmp_ary:
+ if not p.startswith('phy:'):
+ res.append(p)
- return res
+ return res
# TODO(yasufum): consider to merge nfv's.
def _compl_patch(self, sub_tokens):
--
2.17.1
More information about the spp
mailing list