diff --git a/psh/__init__.py b/psh/__init__.py index 6bd963c..7588d80 100644 --- a/psh/__init__.py +++ b/psh/__init__.py @@ -1,7 +1,7 @@ -from psh.commands import registered_cmds +from psh.commands.core import registered_cmds # Import the exported commands -from psh.example_cmd import * +from psh.commands import * # Instantiate the registered commands for name, cls in registered_cmds.items(): diff --git a/psh/commands/__init__.py b/psh/commands/__init__.py new file mode 100644 index 0000000..184516b --- /dev/null +++ b/psh/commands/__init__.py @@ -0,0 +1,3 @@ +from psh.commands.echo import * +from psh.commands.example import * +from psh.commands.raw import * diff --git a/psh/commands.py b/psh/commands/core.py similarity index 100% rename from psh/commands.py rename to psh/commands/core.py diff --git a/psh/example_cmd.py b/psh/commands/echo.py similarity index 61% rename from psh/example_cmd.py rename to psh/commands/echo.py index e91de76..4daf8a8 100644 --- a/psh/example_cmd.py +++ b/psh/commands/echo.py @@ -1,20 +1,8 @@ -from psh.commands import BaseCommand, register_cmd +from psh.commands.core import BaseCommand, register_cmd from psh.tree import TreeNode -@register_cmd("example") -class Example(BaseCommand): - """Simple command that just returns 'example' and 'command'. Does - nothing at all with the input.""" - - def call(self, *args, **kwargs): - def output_generator(): - yield TreeNode(b'example') - yield TreeNode(b'command') - return output_generator - - @register_cmd("echo") class Echo(BaseCommand): """Echoes anything from the command line arguments as well as input diff --git a/psh/commands/example.py b/psh/commands/example.py new file mode 100644 index 0000000..ad517a0 --- /dev/null +++ b/psh/commands/example.py @@ -0,0 +1,15 @@ +from psh.commands.core import BaseCommand, register_cmd + +from psh.tree import TreeNode + + +@register_cmd("example") +class Example(BaseCommand): + """Simple command that just returns 'example' and 'command'. Does + nothing at all with the input.""" + + def call(self, *args, **kwargs): + def output_generator(): + yield TreeNode(b'example') + yield TreeNode(b'command') + return output_generator diff --git a/psh/formatters.py b/psh/commands/formatters.py similarity index 89% rename from psh/formatters.py rename to psh/commands/formatters.py index 436d75c..45f4d37 100644 --- a/psh/formatters.py +++ b/psh/commands/formatters.py @@ -1,4 +1,4 @@ -from psh.commands import BaseCommand +from psh.commands.core import BaseCommand class Printer(BaseCommand): diff --git a/psh/raw_commands.py b/psh/commands/raw.py similarity index 96% rename from psh/raw_commands.py rename to psh/commands/raw.py index e6787c1..e883d41 100644 --- a/psh/raw_commands.py +++ b/psh/commands/raw.py @@ -1,6 +1,6 @@ import shlex -from psh.formatters import Printer +from psh.commands.formatters import Printer from psh.commands import BaseCommand from psh.tree import TreeNode diff --git a/psh/console.py b/psh/console.py index 491440f..4a20ca8 100644 --- a/psh/console.py +++ b/psh/console.py @@ -3,7 +3,7 @@ import code import os import readline -from psh.commands import registered_cmds +from psh.commands.core import registered_cmds DEFAULT_HISTORY_FILE = "~/.psh_history" diff --git a/psh/run.py b/psh/run.py index a8b79a7..596ea85 100644 --- a/psh/run.py +++ b/psh/run.py @@ -1,10 +1,9 @@ import os import os.path -from psh.formatters import * +from psh.commands.formatters import Printer -from psh.example_cmd import Echo, Example -from psh.raw_commands import RawCommand +from psh.commands import Echo, Example, RawCommand # Load all of the commands in the path into the global namespace as raw # commands. diff --git a/test/utils.py b/test/utils.py index 5228c55..58e7046 100644 --- a/test/utils.py +++ b/test/utils.py @@ -1,4 +1,4 @@ -from psh.commands import BaseCommand +from psh.commands.core import BaseCommand from io import StringIO