diff --git a/boot.py b/boot.py index 65ff06d..8f3adbc 100644 --- a/boot.py +++ b/boot.py @@ -1,12 +1,13 @@ import os import importlib import pkgutil +import types COMMANDS_PACKAGE = 'commands' -def load_commands(): - commands = {} +def load_commands() -> dict[str, types.ModuleType]: + commands: dict[str, types.ModuleType] = {} package = importlib.import_module(COMMANDS_PACKAGE) for loader, name, is_pkg in pkgutil.iter_modules(package.__path__): if name.startswith('_'): @@ -17,7 +18,7 @@ def load_commands(): return commands -def main(): +def main() -> None: os.system('cls' if os.name == 'nt' else 'clear') print('Booting PyOS...') commands = load_commands() diff --git a/commands/cat.py b/commands/cat.py index a210f17..d57f0ee 100644 --- a/commands/cat.py +++ b/commands/cat.py @@ -1,13 +1,14 @@ -# WAFCAT :heart: +import typing -help = "Print file contents. Usage: cat " +command_help: str = 'Print file contents. Usage: cat ' -def run(args): + +def run(args: typing.Any) -> None: if not args: - print("Usage: cat ") + print('Usage: cat ') return try: with open(args[0], 'r') as f: print(f.read()) except Exception as e: - print(f"Error: {e}") \ No newline at end of file + print(f'Error: {e}') diff --git a/commands/cd.py b/commands/cd.py index edeac91..bcee7c7 100644 --- a/commands/cd.py +++ b/commands/cd.py @@ -1,11 +1,14 @@ -help = "Change directory. Usage: cd " +import typing -def run(args): +command_help: str = 'Change directory. Usage: cd ' + + +def run(args: typing.Any) -> None: import os if not args: - print("Usage: cd ") + print('Usage: cd ') return try: os.chdir(args[0]) except Exception as e: - print(f"Error: {e}") \ No newline at end of file + print(f'Error: {e}') diff --git a/commands/clear.py b/commands/clear.py index 81a82cb..976c908 100644 --- a/commands/clear.py +++ b/commands/clear.py @@ -1,5 +1,8 @@ -help = "Clear the screen." +import typing -def run(args): +command_help: str = 'Clear the screen.' + + +def run(_args: typing.Any) -> None: import os - os.system('cls' if os.name == 'nt' else 'clear') \ No newline at end of file + os.system('cls' if os.name == 'nt' else 'clear') diff --git a/commands/del.py b/commands/del.py index 6dcd741..a02e5bc 100644 --- a/commands/del.py +++ b/commands/del.py @@ -1,18 +1,21 @@ -help = "Delete file or directory. Usage: del " +import typing -def run(args): +command_help: str = 'Delete file or directory. Usage: del ' + + +def run(args: typing.Any) -> None: import os if not args: - print("Usage: del ") + print('Usage: del ') return target = args[0] if os.path.isdir(target): try: os.rmdir(target) except Exception as e: - print(f"Error: {e}") + print(f'Error: {e}') else: try: os.remove(target) except Exception as e: - print(f"Error: {e}") \ No newline at end of file + print(f'Error: {e}') diff --git a/commands/exit.py b/commands/exit.py index b7543ca..e09a0dd 100644 --- a/commands/exit.py +++ b/commands/exit.py @@ -1,5 +1,8 @@ -help = "Exit PyOS." +import typing -def run(args): - print("Goodbye!") - exit(0) \ No newline at end of file +command_help: str = 'Exit PyOS.' + + +def run(_args: typing.Any) -> None: + print('Goodbye!') + exit(0) diff --git a/commands/help.py b/commands/help.py index b35a63b..5ce2a5d 100644 --- a/commands/help.py +++ b/commands/help.py @@ -1,12 +1,13 @@ -import os +import typing -help = """Show help for all commands.""" +command_help: str = 'Show help for all commands.' -def run(args): + +def run(_args: typing.Any) -> None: from boot import load_commands commands = load_commands() - print("Available commands:") + print('Available commands:') for name in sorted(commands): mod = commands[name] - doc = getattr(mod, "help", "") - print(f" {name:<10} {doc}") \ No newline at end of file + doc = getattr(mod, 'command_help', '') + print(f' {name:<10} {doc}') diff --git a/commands/ls.py b/commands/ls.py index 5362f56..6a8044d 100644 --- a/commands/ls.py +++ b/commands/ls.py @@ -1,6 +1,9 @@ -help = "List files in current directory." +import typing -def run(args): +command_help: str = 'List files in current directory.' + + +def run(_args: typing.Any) -> None: import os for f in os.listdir(): - print(f) \ No newline at end of file + print(f) diff --git a/commands/mkdir.py b/commands/mkdir.py index 3292439..2656e8a 100644 --- a/commands/mkdir.py +++ b/commands/mkdir.py @@ -1,11 +1,14 @@ -help = "Create a directory. Usage: mkdir " +import typing -def run(args): +command_help: str = 'Create a directory. Usage: mkdir ' + + +def run(args: typing.Any) -> None: import os if not args: - print("Usage: mkdir ") + print('Usage: mkdir ') return try: os.mkdir(args[0]) except Exception as e: - print(f"Error: {e}") \ No newline at end of file + print(f'Error: {e}') diff --git a/commands/mkfil.py b/commands/mkfil.py index b9518b5..07ba5ea 100644 --- a/commands/mkfil.py +++ b/commands/mkfil.py @@ -1,11 +1,13 @@ -help = "Create an empty file. Usage: mkfil " +import typing +command_help: str = 'Create an empty file. Usage: mkfil ' -def run(args): + +def run(args: typing.Any) -> None: if not args: - print("Usage: mkfil ") + print('Usage: mkfil ') return try: open(args[0], 'a').close() except Exception as e: - print(f"Error: {e}") + print(f'Error: {e}') diff --git a/commands/printdir.py b/commands/printdir.py index 0f7f281..593e255 100644 --- a/commands/printdir.py +++ b/commands/printdir.py @@ -1,5 +1,8 @@ -help = "Print working directory." +import typing -def run(args): +command_help: str = 'Print working directory.' + + +def run(_args: typing.Any) -> None: import os - print(os.getcwd()) \ No newline at end of file + print(os.getcwd()) diff --git a/commands/rename.py b/commands/rename.py index e69de29..f198c5a 100644 --- a/commands/rename.py +++ b/commands/rename.py @@ -0,0 +1,19 @@ +import os +import typing + +command_help: str = 'Rename a file. Usage: rename ' + + +def run(args: typing.Any) -> None: + if not args: + print('Usage: rename ') + return + + if len(args) != 2: + print('Usage: rename ') + return + + try: + os.rename(args[0], args[1]) + except Exception as e: + print(f'Error: {e}') diff --git a/commands/whoami.py b/commands/whoami.py index 045050a..8c7a72c 100644 --- a/commands/whoami.py +++ b/commands/whoami.py @@ -1,3 +1,8 @@ -def run(args): - import getpass - print(getpass.getuser()) +import typing + +command_help: str = 'Get current user' + + +def run(_args: typing.Any) -> None: + import getpass + print(getpass.getuser())