From da523b96449516b1d35c832c5d021ea3fdc1e6af Mon Sep 17 00:00:00 2001 From: max Date: Wed, 3 Jul 2024 12:38:20 +1000 Subject: [PATCH] Fully implement cat --- main.py | 14 ++++++++++++-- main.py! | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 main.py! diff --git a/main.py b/main.py index 0f5ca83..2e2a26d 100644 --- a/main.py +++ b/main.py @@ -1,16 +1,26 @@ import os import subprocess +import re initDirectory = os.path.dirname(os.path.realpath(__file__)) currentDirectory = initDirectory version = "0.0.1" +def grabArgument(fullCommand, commandRan): + fullCommand.replace(commandRan, "") + while True: command = input(currentDirectory + " > ") if command == "pwd": print(currentDirectory) - elif command == "cat *": - print("You ran cat") + elif command == ("cat"): + try: + + catFile = input("File to catalog: ") + catFileOpened = open(catFile) + print(catFileOpened.read()) + except Exception: + print("File", catFile, "either doesn't exist or isn't in this directory.") elif command == "version": print(version) else: diff --git a/main.py! b/main.py! new file mode 100644 index 0000000..a81093d --- /dev/null +++ b/main.py! @@ -0,0 +1,20 @@ +import os +import subprocess + +initDirectory = os.path.dirname(os.path.realpath(__file__)) +currentDirectory = initDirectory +version = "0.0.1" + +def grabArgument(fullCommand, commandRan): + fullCommand.replace(commandRan, "") + +while True: + command = input(currentDirectory + " > ") + if command == "pwd": + print(currentDirectory) + elif command == ("cat", *): + grabArgument(command, cat ) + elif command == "version": + print(version) + else: + subprocess.run(command)