From e87560939fedac05ac16f1162c5769e6fd2fa169 Mon Sep 17 00:00:00 2001 From: Richard Mwewa <74001397+rly0nheart@users.noreply.github.com> Date: Sun, 25 Dec 2022 02:32:28 +0200 Subject: [PATCH] Update main.py --- octosuite/main.py | 44 ++++++++++++++++++++++++++++---------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/octosuite/main.py b/octosuite/main.py index fe6fea9..b09bd73 100644 --- a/octosuite/main.py +++ b/octosuite/main.py @@ -1,34 +1,46 @@ # import everything from the octosuite.py file -from octosuite.octosuite import * # I drifted away from the 'pythonic way' here +from octosuite.octosuite import * # I drifted away from the 'pythonic way' here def octosuite(): try: run = Octosuite() - run.path_finder() - run.clear_screen() - run.configure_logging() - run.check_updates() - xprint(ascii_banner()[1], ascii_banner()[0]) - + path_finder() + clear_screen() + configure_logging() + check_updates() + if args: + """ + Iterate over the argument_map and check if the passed command line argument matches any argument in it [argument_map], + if there's a match, we return its method. If no match is found, we do nothing (which will return the usage). + """ + for argument, method in run.argument_map: + if args.method == argument: + method() + print("\n") + """ Main loop keeps octosuite running, this will break if Octosuite detects a KeyboardInterrupt (Ctrl+C) or if the 'exit' command is entered. """ + xprint(banner()[0], banner()[1]) while True: - xprint(f"{white}┌──({red}{getpass.getuser()}{white}@{red}octosuite{white})\n├──[~{green}{os.getcwd()}{white}]\n└╼ {reset}",end="") - command_input = input().lower() - print("\n") + command_input = Prompt.ask(f"{white}┌──({red}{getpass.getuser()}{white}@{red}octosuite{white})\n├──[~{green}{os.getcwd()}{white}]\n└╼ {reset}") """ Iterate over the command_map and check if the user input matches any command in it [command_map], if there's a match, we return its method. If no match is found, we ignore it. """ - for command, method in run.command_map: - if command_input == command: - method() - print("\n") - else: - pass + if command_input[:2] == 'cd': + os.chdir(command_input[3:]) + elif command_input[:2] == 'ls': + os.system(f'dir {command_input[3:]}' if os.name == 'nt' else f'ls {command_input[3:]}') + else: + for command, method in run.command_map: + if command_input == command: + method() + print("\n") + else: + pass except KeyboardInterrupt: logging.warning(ctrl_c)