aboutsummaryrefslogtreecommitdiff
path: root/src/suite
diff options
context:
space:
mode:
authorCharles Cabergs <me@cacharle.xyz>2020-09-12 02:22:56 +0200
committerCharles Cabergs <me@cacharle.xyz>2020-09-12 02:22:56 +0200
commit387fe3441d2f1f02b8ff85e798eb1295f95b7e7f (patch)
treeaf7c4f3449e3a4a23b813a0d9d42255b8c302c2b /src/suite
parent958c410ba8b621a8a4d8caf04012028e7f151e0f (diff)
downloadminishell_test-387fe3441d2f1f02b8ff85e798eb1295f95b7e7f.tar.gz
minishell_test-387fe3441d2f1f02b8ff85e798eb1295f95b7e7f.tar.bz2
minishell_test-387fe3441d2f1f02b8ff85e798eb1295f95b7e7f.zip
Added suite name autocompletion
Diffstat (limited to 'src/suite')
-rw-r--r--src/suite/suite.py32
1 files changed, 29 insertions, 3 deletions
diff --git a/src/suite/suite.py b/src/suite/suite.py
index 2ac64e4..b81205e 100644
--- a/src/suite/suite.py
+++ b/src/suite/suite.py
@@ -6,10 +6,12 @@
# By: charles <charles.cabergs@gmail.com> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2020/07/15 18:24:29 by charles #+# #+# #
-# Updated: 2020/09/11 20:35:13 by charles ### ########.fr #
+# Updated: 2020/09/12 02:14:58 by charles ### ########.fr #
# #
# ############################################################################ #
+import sys
+
import config
@@ -27,15 +29,39 @@ class Suite:
"""Remove not asked suite from available suites"""
if len(asked_names) == 0:
asked_names = [s.name for s in cls.available]
+
if not config.BONUS:
cls.available = [s for s in cls.available if not s.bonus]
+
+ names = []
+ for i, name in enumerate(asked_names):
+ matches = [s.name for s in cls.available
+ if s.name.find("/") != -1
+ and s.name[s.name.find("/") + 1:].startswith(name)
+ or s.name.startswith(name)]
+ if len(matches) == 1:
+ names.append(matches[0])
+ elif all([n.startswith(name) for n in matches]):
+ names.extend(matches)
+ elif len(matches) > 2:
+ print(("Ambiguous name `{}` match the following suites\n\t{}\n"
+ "Try to run with -l to see the available suites")
+ .format(name, ', '.join(matches)))
+ sys.exit(1)
+ elif len(matches) == 0:
+ print(("No suite named `{}` found\n\t{}\n"
+ "Try to run with -l to see the available suites")
+ .format(name, ', '.join(matches)))
+ sys.exit(1)
+
cls.available = list(set(
- [s for s in cls.available if s.name in asked_names]
- + [s for s in cls.available if any([g for g in s.groups if g in asked_names])]
+ [s for s in cls.available if s.name in names]
+ + [s for s in cls.available if any([g for g in s.groups if g in names])]
))
for s in cls.available:
s.generator_func()
+
@classmethod
def available_names(cls) -> [str]:
"""List of available suites names"""