From 7b2bb509ecb08df16c655773fdee5180caab1401 Mon Sep 17 00:00:00 2001 From: p7mj Date: Mon, 27 Apr 2026 12:15:58 -0400 Subject: [PATCH] Added help and exit --- Makefile | 2 ++ README.md | 10 ++++++++- bugpy-mos-0.py | 21 ++++++++++++------ config/pointerfile.txt | 15 ++++++++++++- hi.txt => scripts/exit/__init__.py | 0 scripts/exit/exit.py | 4 ++++ scripts/help/__init__.py | 0 scripts/help/help.py | 2 ++ scripts/list_files/list_files.py | 4 +++- scripts/make_file/make_file.py | 18 ++++++++++------ scripts/remove/remove.py | 32 ++++++++++++++++++++++++++-- scripts/say_greeting/say_greeting.py | 7 ++++-- scripts/touch_file/touch_file.py | 11 +++++++--- 13 files changed, 103 insertions(+), 23 deletions(-) create mode 100644 Makefile rename hi.txt => scripts/exit/__init__.py (100%) create mode 100644 scripts/exit/exit.py create mode 100644 scripts/help/__init__.py create mode 100644 scripts/help/help.py diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ee2e0a4 --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +default: + python3 bugpy-mos-0.py diff --git a/README.md b/README.md index c3c346c..44c6122 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,11 @@ # BUGPY-mOS -BUGS-Python Mock OS \ No newline at end of file +BUGS-Python Mock OS + +Checklist: +- finish the help sections in each script function. Currently says bro is lazy +- Each function must have: + - A condition checking if args is empty + - A condition checking -h or --help + - A condition doing the primary stuff as else + - All printouts must be "{function_name}: {what_to_talk}" \ No newline at end of file diff --git a/bugpy-mos-0.py b/bugpy-mos-0.py index da01d64..fecd0d4 100644 --- a/bugpy-mos-0.py +++ b/bugpy-mos-0.py @@ -4,15 +4,17 @@ from scripts.say_greeting import say_greeting from scripts.make_file import make_file from scripts.touch_file import touch_file from scripts.remove import remove +from scripts.help import help +from scripts.exit import exit from pathlib import Path # Shitty test # list_files.main() -verbose = 1 +if_verbose = 0 def verbose(strings): - if verbose == 1: + if if_verbose == 1: print(str(strings)) @@ -21,6 +23,7 @@ def get_config_line(keyword): # Adjust the number of .parent calls based on where this function lives! # If this is in main.py, it's just Path(__file__).parent base_dir = Path(__file__).resolve().parent + verbose(f"base_dir: {base_dir}") config_file = base_dir / "config" / "pointerfile.txt" if not config_file.exists(): @@ -47,12 +50,17 @@ def match_command(command, args_list): make_file.main(args_list) elif command == "remove": remove.main(args_list) + elif command == "help": + help.main(args_list) + elif command == "exit": + exit.main(args_list) # use if else if else if else if to match the output def cmdrun(keyword): parsed = keyword.split() + verbose(parsed) get_config_result = get_config_line(parsed[0]) - print(get_config_result) + verbose(get_config_result) if not get_config_result == None: match_command(get_config_result[1], parsed[1:]) return True @@ -62,6 +70,7 @@ def cmdrun(keyword): if __name__ == "__main__": print("BUGPy-mOS 0 \"Devvie\"") while True: - inputs = input("BUGS > ") - if not cmdrun(inputs): - print("BAD COMMAND") \ No newline at end of file + inputs = input("\nBUGS > ") + if not inputs.strip() == "": + if not cmdrun(inputs): + print("BAD COMMAND") diff --git a/config/pointerfile.txt b/config/pointerfile.txt index 4f2ae3a..9ee74b3 100644 --- a/config/pointerfile.txt +++ b/config/pointerfile.txt @@ -1,15 +1,28 @@ dir: list_files ls: list_files list_files: list_files + hi: say_greeting hello: say_greeting greeting: say_greeting greetings: say_greeting say_greeting: say_greeting +say_greetings: say_greeting + mk: make_file New-Item: make_file make_file: make_file + touch: touch_file touch_file: touch_file + rm: remove -remove: remove \ No newline at end of file +remove: remove + +help: help +guide: help +man: help + +exit: exit +poweroff: exit +shutdown: exit diff --git a/hi.txt b/scripts/exit/__init__.py similarity index 100% rename from hi.txt rename to scripts/exit/__init__.py diff --git a/scripts/exit/exit.py b/scripts/exit/exit.py new file mode 100644 index 0000000..59e9522 --- /dev/null +++ b/scripts/exit/exit.py @@ -0,0 +1,4 @@ +import sys +def main(args): + print("Exiting BUGPy!") + sys.exit(0) diff --git a/scripts/help/__init__.py b/scripts/help/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/scripts/help/help.py b/scripts/help/help.py new file mode 100644 index 0000000..5fc759d --- /dev/null +++ b/scripts/help/help.py @@ -0,0 +1,2 @@ +def main(args): + print("An unfinished help section! Yay") diff --git a/scripts/list_files/list_files.py b/scripts/list_files/list_files.py index d662b7e..5bbcd52 100644 --- a/scripts/list_files/list_files.py +++ b/scripts/list_files/list_files.py @@ -14,4 +14,6 @@ def main(args): elif entry.is_file(): print(f"[FILE] {entry.name}") elif args == ["--help"] or args == ["-h"]: - print("Bro is lazy on doing this help section") + print("list_files: Bro is lazy on doing this help section") + else: + print("list_files: Invalid arguments, try using none?") diff --git a/scripts/make_file/make_file.py b/scripts/make_file/make_file.py index 2fb36e9..1bbeb82 100644 --- a/scripts/make_file/make_file.py +++ b/scripts/make_file/make_file.py @@ -1,10 +1,14 @@ from pathlib import Path def main(args): - for target in args: - path = Path(target) - if path.exists(): - print(f'"{target}" already exists.') - continue - - path.write_text("") # Pure creation \ No newline at end of file + if args == []: + print("make_file: no arguments were given.") + elif args == ["-h"] or args == ["--help"]: + print("make_file: bro is lazy do this later") + else: + for target in args: + path = Path(target) + if path.exists(): + print(f'make_file: "{target}" already exists.') + continue + path.write_text("") \ No newline at end of file diff --git a/scripts/remove/remove.py b/scripts/remove/remove.py index eb98dcc..d2d5010 100644 --- a/scripts/remove/remove.py +++ b/scripts/remove/remove.py @@ -1,5 +1,33 @@ from pathlib import Path +import shutil def main(args): - for item in args: - Path(args).unlink(missing_ok=True) # missing_ok=True prevents error if file is missing + if not args: + print("remove: no arguments were given") + return + + # Check for the -rf flag + recursive = False + if "-rf" in args: + recursive = True + args.remove("-rf") # Remove flag from list so only paths remain + + if args == ["-h"] or args == ["--help"]: + print("remove: Use -rf to delete directories and their contents.") + else: + for item in args: + path = Path(item) + + if not path.exists(): + continue # 'force' usually means ignore non-existent files + + try: + if path.is_dir(): + if recursive: + shutil.rmtree(path) # This is the "recursive" part + else: + print(f"remove: cannot remove '{item}': Is a directory") + else: + path.unlink() # Delete individual file + except Exception as e: + print(f"remove: error deleting {item}: {e}") \ No newline at end of file diff --git a/scripts/say_greeting/say_greeting.py b/scripts/say_greeting/say_greeting.py index 20c42e0..314d474 100644 --- a/scripts/say_greeting/say_greeting.py +++ b/scripts/say_greeting/say_greeting.py @@ -1,2 +1,5 @@ -def main(arg): - print("Hi!") \ No newline at end of file +def main(args): + if args == []: + print("say_greeting: Hi!") + elif args == ["-h"] or args == ["--help"]: + print("say_greeting: Bro is lazy to make this pointless help section") \ No newline at end of file diff --git a/scripts/touch_file/touch_file.py b/scripts/touch_file/touch_file.py index f9bce34..ae2cf4c 100644 --- a/scripts/touch_file/touch_file.py +++ b/scripts/touch_file/touch_file.py @@ -1,6 +1,11 @@ from pathlib import Path def main(args): - for target in args: - path = Path(target) - path.touch(exist_ok=True) \ No newline at end of file + if args == []: + print("touch_file: no arguments were given") + elif args == ["-h"] or args == ["--help"]: + print("touch_file: bro was lazy") + else: + for target in args: + path = Path(target) + path.touch(exist_ok=True) \ No newline at end of file