Soft Patch Panel
 help / color / mirror / Atom feed
From: yasufum.o@gmail.com
To: spp@dpdk.org, ferruh.yigit@intel.com, yasufum.o@gmail.com
Subject: [spp] [PATCH 2/2] cli: fix bug of completion in del command
Date: Thu, 17 Oct 2019 21:58:36 +0900
Message-ID: <20191017125836.29365-3-yasufum.o@gmail.com> (raw)
In-Reply-To: <20191017125836.29365-1-yasufum.o@gmail.com>

From: Yasufumi Ogawa <yasufum.o@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@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


      parent reply	other threads:[~2019-10-17 12:58 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-17 12:58 [spp] [PATCH 0/2] Add completion for forwarder in primary yasufum.o
2019-10-17 12:58 ` [spp] [PATCH 1/2] cli: add compl for new commands in spp_primary yasufum.o
2019-10-17 12:58 ` yasufum.o [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191017125836.29365-3-yasufum.o@gmail.com \
    --to=yasufum.o@gmail.com \
    --cc=ferruh.yigit@intel.com \
    --cc=spp@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Soft Patch Panel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://inbox.dpdk.org/spp/0 spp/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 spp spp/ https://inbox.dpdk.org/spp \
		spp@dpdk.org
	public-inbox-index spp

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://inbox.dpdk.org/inbox.dpdk.spp


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git