Restructure to have commands be a subpackage.
This commit is contained in:
parent
e9d7f5f2b6
commit
7ac4dfe562
@ -1,7 +1,7 @@
|
|||||||
from psh.commands import registered_cmds
|
from psh.commands.core import registered_cmds
|
||||||
|
|
||||||
# Import the exported commands
|
# Import the exported commands
|
||||||
from psh.example_cmd import *
|
from psh.commands import *
|
||||||
|
|
||||||
# Instantiate the registered commands
|
# Instantiate the registered commands
|
||||||
for name, cls in registered_cmds.items():
|
for name, cls in registered_cmds.items():
|
||||||
|
3
psh/commands/__init__.py
Normal file
3
psh/commands/__init__.py
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
from psh.commands.echo import *
|
||||||
|
from psh.commands.example import *
|
||||||
|
from psh.commands.raw import *
|
@ -1,20 +1,8 @@
|
|||||||
from psh.commands import BaseCommand, register_cmd
|
from psh.commands.core import BaseCommand, register_cmd
|
||||||
|
|
||||||
from psh.tree import TreeNode
|
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")
|
@register_cmd("echo")
|
||||||
class Echo(BaseCommand):
|
class Echo(BaseCommand):
|
||||||
"""Echoes anything from the command line arguments as well as input
|
"""Echoes anything from the command line arguments as well as input
|
15
psh/commands/example.py
Normal file
15
psh/commands/example.py
Normal file
@ -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
|
@ -1,4 +1,4 @@
|
|||||||
from psh.commands import BaseCommand
|
from psh.commands.core import BaseCommand
|
||||||
|
|
||||||
|
|
||||||
class Printer(BaseCommand):
|
class Printer(BaseCommand):
|
@ -1,6 +1,6 @@
|
|||||||
import shlex
|
import shlex
|
||||||
|
|
||||||
from psh.formatters import Printer
|
from psh.commands.formatters import Printer
|
||||||
from psh.commands import BaseCommand
|
from psh.commands import BaseCommand
|
||||||
from psh.tree import TreeNode
|
from psh.tree import TreeNode
|
||||||
|
|
@ -3,7 +3,7 @@ import code
|
|||||||
import os
|
import os
|
||||||
import readline
|
import readline
|
||||||
|
|
||||||
from psh.commands import registered_cmds
|
from psh.commands.core import registered_cmds
|
||||||
|
|
||||||
DEFAULT_HISTORY_FILE = "~/.psh_history"
|
DEFAULT_HISTORY_FILE = "~/.psh_history"
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
from psh.formatters import *
|
from psh.commands.formatters import Printer
|
||||||
|
|
||||||
from psh.example_cmd import Echo, Example
|
from psh.commands import Echo, Example, RawCommand
|
||||||
from psh.raw_commands import RawCommand
|
|
||||||
|
|
||||||
# Load all of the commands in the path into the global namespace as raw
|
# Load all of the commands in the path into the global namespace as raw
|
||||||
# commands.
|
# commands.
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from psh.commands import BaseCommand
|
from psh.commands.core import BaseCommand
|
||||||
|
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user