Restructure to have commands be a subpackage.

This commit is contained in:
Ian Adam Naval 2015-03-03 12:36:59 -05:00
parent e9d7f5f2b6
commit 7ac4dfe562
10 changed files with 27 additions and 22 deletions

View File

@ -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
View File

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

View File

@ -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
View 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

View File

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

View File

@ -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

View File

@ -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"

View File

@ -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.

View File

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