Browse Source

Restructure to have commands be a subpackage.

Ian Adam Naval 4 years ago
parent
commit
7ac4dfe562

+ 2
- 2
psh/__init__.py View File

@@ -1,7 +1,7 @@
1
-from psh.commands import registered_cmds
1
+from psh.commands.core import registered_cmds
2 2
 
3 3
 # Import the exported commands
4
-from psh.example_cmd import *
4
+from psh.commands import *
5 5
 
6 6
 # Instantiate the registered commands
7 7
 for name, cls in registered_cmds.items():

+ 3
- 0
psh/commands/__init__.py View File

@@ -0,0 +1,3 @@
1
+from psh.commands.echo import *
2
+from psh.commands.example import *
3
+from psh.commands.raw import *

psh/commands.py → psh/commands/core.py View File


psh/example_cmd.py → psh/commands/echo.py View File

@@ -1,20 +1,8 @@
1
-from psh.commands import BaseCommand, register_cmd
1
+from psh.commands.core import BaseCommand, register_cmd
2 2
 
3 3
 from psh.tree import TreeNode
4 4
 
5 5
 
6
-@register_cmd("example")
7
-class Example(BaseCommand):
8
-    """Simple command that just returns 'example' and 'command'. Does
9
-    nothing at all with the input."""
10
-
11
-    def call(self, *args, **kwargs):
12
-        def output_generator():
13
-            yield TreeNode(b'example')
14
-            yield TreeNode(b'command')
15
-        return output_generator
16
-
17
-
18 6
 @register_cmd("echo")
19 7
 class Echo(BaseCommand):
20 8
     """Echoes anything from the command line arguments as well as input

+ 15
- 0
psh/commands/example.py View File

@@ -0,0 +1,15 @@
1
+from psh.commands.core import BaseCommand, register_cmd
2
+
3
+from psh.tree import TreeNode
4
+
5
+
6
+@register_cmd("example")
7
+class Example(BaseCommand):
8
+    """Simple command that just returns 'example' and 'command'. Does
9
+    nothing at all with the input."""
10
+
11
+    def call(self, *args, **kwargs):
12
+        def output_generator():
13
+            yield TreeNode(b'example')
14
+            yield TreeNode(b'command')
15
+        return output_generator

psh/formatters.py → psh/commands/formatters.py View File

@@ -1,4 +1,4 @@
1
-from psh.commands import BaseCommand
1
+from psh.commands.core import BaseCommand
2 2
 
3 3
 
4 4
 class Printer(BaseCommand):

psh/raw_commands.py → psh/commands/raw.py View File

@@ -1,6 +1,6 @@
1 1
 import shlex
2 2
 
3
-from psh.formatters import Printer
3
+from psh.commands.formatters import Printer
4 4
 from psh.commands import BaseCommand
5 5
 from psh.tree import TreeNode
6 6
 

+ 1
- 1
psh/console.py View File

@@ -3,7 +3,7 @@ import code
3 3
 import os
4 4
 import readline
5 5
 
6
-from psh.commands import registered_cmds
6
+from psh.commands.core import registered_cmds
7 7
 
8 8
 DEFAULT_HISTORY_FILE = "~/.psh_history"
9 9
 

+ 2
- 3
psh/run.py View File

@@ -1,10 +1,9 @@
1 1
 import os
2 2
 import os.path
3 3
 
4
-from psh.formatters import *
4
+from psh.commands.formatters import Printer
5 5
 
6
-from psh.example_cmd import Echo, Example
7
-from psh.raw_commands import RawCommand
6
+from psh.commands import Echo, Example, RawCommand
8 7
 
9 8
 # Load all of the commands in the path into the global namespace as raw
10 9
 # commands.

+ 1
- 1
test/utils.py View File

@@ -1,4 +1,4 @@
1
-from psh.commands import BaseCommand
1
+from psh.commands.core import BaseCommand
2 2
 
3 3
 from io import StringIO
4 4
 

Loading…
Cancel
Save