Added help and exit
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
# BUGPY-mOS
|
# BUGPY-mOS
|
||||||
|
|
||||||
BUGS-Python Mock OS
|
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}"
|
||||||
@@ -4,15 +4,17 @@ from scripts.say_greeting import say_greeting
|
|||||||
from scripts.make_file import make_file
|
from scripts.make_file import make_file
|
||||||
from scripts.touch_file import touch_file
|
from scripts.touch_file import touch_file
|
||||||
from scripts.remove import remove
|
from scripts.remove import remove
|
||||||
|
from scripts.help import help
|
||||||
|
from scripts.exit import exit
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
# Shitty test
|
# Shitty test
|
||||||
# list_files.main()
|
# list_files.main()
|
||||||
|
|
||||||
verbose = 1
|
if_verbose = 0
|
||||||
|
|
||||||
def verbose(strings):
|
def verbose(strings):
|
||||||
if verbose == 1:
|
if if_verbose == 1:
|
||||||
print(str(strings))
|
print(str(strings))
|
||||||
|
|
||||||
|
|
||||||
@@ -21,6 +23,7 @@ def get_config_line(keyword):
|
|||||||
# Adjust the number of .parent calls based on where this function lives!
|
# Adjust the number of .parent calls based on where this function lives!
|
||||||
# If this is in main.py, it's just Path(__file__).parent
|
# If this is in main.py, it's just Path(__file__).parent
|
||||||
base_dir = Path(__file__).resolve().parent
|
base_dir = Path(__file__).resolve().parent
|
||||||
|
verbose(f"base_dir: {base_dir}")
|
||||||
config_file = base_dir / "config" / "pointerfile.txt"
|
config_file = base_dir / "config" / "pointerfile.txt"
|
||||||
|
|
||||||
if not config_file.exists():
|
if not config_file.exists():
|
||||||
@@ -47,12 +50,17 @@ def match_command(command, args_list):
|
|||||||
make_file.main(args_list)
|
make_file.main(args_list)
|
||||||
elif command == "remove":
|
elif command == "remove":
|
||||||
remove.main(args_list)
|
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
|
# use if else if else if else if to match the output
|
||||||
|
|
||||||
def cmdrun(keyword):
|
def cmdrun(keyword):
|
||||||
parsed = keyword.split()
|
parsed = keyword.split()
|
||||||
|
verbose(parsed)
|
||||||
get_config_result = get_config_line(parsed[0])
|
get_config_result = get_config_line(parsed[0])
|
||||||
print(get_config_result)
|
verbose(get_config_result)
|
||||||
if not get_config_result == None:
|
if not get_config_result == None:
|
||||||
match_command(get_config_result[1], parsed[1:])
|
match_command(get_config_result[1], parsed[1:])
|
||||||
return True
|
return True
|
||||||
@@ -62,6 +70,7 @@ def cmdrun(keyword):
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("BUGPy-mOS 0 \"Devvie\"")
|
print("BUGPy-mOS 0 \"Devvie\"")
|
||||||
while True:
|
while True:
|
||||||
inputs = input("BUGS > ")
|
inputs = input("\nBUGS > ")
|
||||||
|
if not inputs.strip() == "":
|
||||||
if not cmdrun(inputs):
|
if not cmdrun(inputs):
|
||||||
print("BAD COMMAND")
|
print("BAD COMMAND")
|
||||||
@@ -1,15 +1,28 @@
|
|||||||
dir: list_files
|
dir: list_files
|
||||||
ls: list_files
|
ls: list_files
|
||||||
list_files: list_files
|
list_files: list_files
|
||||||
|
|
||||||
hi: say_greeting
|
hi: say_greeting
|
||||||
hello: say_greeting
|
hello: say_greeting
|
||||||
greeting: say_greeting
|
greeting: say_greeting
|
||||||
greetings: say_greeting
|
greetings: say_greeting
|
||||||
say_greeting: say_greeting
|
say_greeting: say_greeting
|
||||||
|
say_greetings: say_greeting
|
||||||
|
|
||||||
mk: make_file
|
mk: make_file
|
||||||
New-Item: make_file
|
New-Item: make_file
|
||||||
make_file: make_file
|
make_file: make_file
|
||||||
|
|
||||||
touch: touch_file
|
touch: touch_file
|
||||||
touch_file: touch_file
|
touch_file: touch_file
|
||||||
|
|
||||||
rm: remove
|
rm: remove
|
||||||
remove: remove
|
remove: remove
|
||||||
|
|
||||||
|
help: help
|
||||||
|
guide: help
|
||||||
|
man: help
|
||||||
|
|
||||||
|
exit: exit
|
||||||
|
poweroff: exit
|
||||||
|
shutdown: exit
|
||||||
|
|||||||
4
scripts/exit/exit.py
Normal file
4
scripts/exit/exit.py
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
import sys
|
||||||
|
def main(args):
|
||||||
|
print("Exiting BUGPy!")
|
||||||
|
sys.exit(0)
|
||||||
0
scripts/help/__init__.py
Normal file
0
scripts/help/__init__.py
Normal file
2
scripts/help/help.py
Normal file
2
scripts/help/help.py
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
def main(args):
|
||||||
|
print("An unfinished help section! Yay")
|
||||||
@@ -14,4 +14,6 @@ def main(args):
|
|||||||
elif entry.is_file():
|
elif entry.is_file():
|
||||||
print(f"[FILE] {entry.name}")
|
print(f"[FILE] {entry.name}")
|
||||||
elif args == ["--help"] or args == ["-h"]:
|
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?")
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
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:
|
for target in args:
|
||||||
path = Path(target)
|
path = Path(target)
|
||||||
if path.exists():
|
if path.exists():
|
||||||
print(f'"{target}" already exists.')
|
print(f'make_file: "{target}" already exists.')
|
||||||
continue
|
continue
|
||||||
|
path.write_text("")
|
||||||
path.write_text("") # Pure creation
|
|
||||||
@@ -1,5 +1,33 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import shutil
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
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:
|
for item in args:
|
||||||
Path(args).unlink(missing_ok=True) # missing_ok=True prevents error if file is missing
|
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}")
|
||||||
@@ -1,2 +1,5 @@
|
|||||||
def main(arg):
|
def main(args):
|
||||||
print("Hi!")
|
if args == []:
|
||||||
|
print("say_greeting: Hi!")
|
||||||
|
elif args == ["-h"] or args == ["--help"]:
|
||||||
|
print("say_greeting: Bro is lazy to make this pointless help section")
|
||||||
@@ -1,6 +1,11 @@
|
|||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
def main(args):
|
def main(args):
|
||||||
|
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:
|
for target in args:
|
||||||
path = Path(target)
|
path = Path(target)
|
||||||
path.touch(exist_ok=True)
|
path.touch(exist_ok=True)
|
||||||
Reference in New Issue
Block a user