diff --git a/commands.py b/commands.py index 9071680..b672a00 100644 --- a/commands.py +++ b/commands.py @@ -3,7 +3,8 @@ from io import StringIO class BaseCommand(object): - + def __init__(self, args): + self.cmd_args = args def __call__(self, *args, **kwargs): raise NotImplementedError( "BaseCommands must be callable and return a generator") diff --git a/example_cmd.py b/example_cmd.py index 75385a8..aa704c4 100644 --- a/example_cmd.py +++ b/example_cmd.py @@ -2,7 +2,6 @@ from commands import BaseCommand, register_cmd @register_cmd class example_cmd(BaseCommand): - def __call__(self, *args, **kwargs): def output_generator(): yield b'example' @@ -12,9 +11,9 @@ class example_cmd(BaseCommand): @register_cmd class echo(BaseCommand): - - def __call__(self, *args, **kwargs): + def __call__(self,*args,**kwargs): def output_generator(): - for line in self.input_cmd(): - yield line + for line in self.cmd_args: + yield line.encode('utf-8') return output_generator() + diff --git a/main.py b/main.py index 0e12c94..db8689b 100644 --- a/main.py +++ b/main.py @@ -10,7 +10,8 @@ for path in os.environ['PATH'].split(':'): if os.path.exists(path): binaries = os.listdir(path) for binary in binaries: - globals()[binary] = RawCommand(binary) + if binary not in globals(): + globals()[binary] = RawCommand(binary) def parse_cmd(potential_cmd): @@ -29,7 +30,7 @@ def parse_cmd(potential_cmd): if cmd_name not in registered_cmds: return "RawCommand({})".format(shlex.split(potential_cmd)) else: - return "{}()".format(cmd_name) + return "{0}({1})".format(cmd_name,str(args)) def parse_cmds(raw):