Add command line interface with PyInquirer

Add update requirements.txt
This commit is contained in:
Marcel Schwarz 2019-12-16 22:51:40 +01:00
parent c47b255924
commit 79449c8ad3
2 changed files with 40 additions and 22 deletions

60
main.py
View File

@ -1,31 +1,49 @@
from CommandRunner import CommandRunnerDebug as Runner from CommandRunner import CommandRunnerDebug as Runner
from PyInquirer import prompt
import importlib import importlib
import os 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:") def transform_list_into_choices(choices_list):
for mod in modules.keys(): mapped_list = []
print(mod) for choice in choices_list:
mapped_list.append({
"name": choice
})
return mapped_list
print()
while True: def load_modules():
chosen_module = input("Please specify your module: ") print("Loading modules")
if chosen_module in modules.keys(): modules = {}
break for folder in os.listdir("./modules"):
else: try:
print("Module was not found.") 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])

View File

@ -1 +1 @@
PyInquirer==1.0.3