From 79449c8ad32f66f74c59fa3d8137d5c0d6517807 Mon Sep 17 00:00:00 2001 From: Marcel Schwarz Date: Mon, 16 Dec 2019 22:51:40 +0100 Subject: [PATCH] Add command line interface with PyInquirer Add update requirements.txt --- main.py | 60 +++++++++++++++++++++++++++++++----------------- requirements.txt | 2 +- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/main.py b/main.py index c364f5a..2ffc019 100644 --- a/main.py +++ b/main.py @@ -1,31 +1,49 @@ from CommandRunner import CommandRunnerDebug as Runner +from PyInquirer import prompt import importlib import os -print("Loading modules") -modules = {} -for folder in os.listdir("./modules"): - try: - curr_module = importlib.import_module('.' + folder, package="modules") - modules[folder] = curr_module.get_module() - except AttributeError: - pass -print("Modules loaded successfully.\n") -print("Available Modules:") -for mod in modules.keys(): - print(mod) +def transform_list_into_choices(choices_list): + mapped_list = [] + for choice in choices_list: + mapped_list.append({ + "name": choice + }) + return mapped_list -print() -while True: - chosen_module = input("Please specify your module: ") - if chosen_module in modules.keys(): - break - else: - print("Module was not found.") +def load_modules(): + print("Loading modules") + modules = {} + for folder in os.listdir("./modules"): + try: + curr_module = importlib.import_module('.' + folder, package="modules") + modules[folder] = curr_module.get_module() + except AttributeError: + pass + print("Modules loaded successfully.\n") + return modules -print("\nChosen Module to run: " + chosen_module) -Runner().run(modules[chosen_module]) +def open_module_selection(modules): + print("Available Modules:") + module_selection = [ + { + 'type': 'checkbox', + 'message': 'Select modules', + 'name': 'modules', + 'choices': transform_list_into_choices( + list(modules.keys()) + ) + } + ] + return prompt(module_selection) + +modules = load_modules() + +selected_modules = open_module_selection(modules) + +for answer in selected_modules['modules']: + Runner().run(modules[answer]) diff --git a/requirements.txt b/requirements.txt index 8b13789..efa466d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1 @@ - +PyInquirer==1.0.3