fixed the bullshit with the name conflict when loading commands that share names with commands being loaded from PATH. also made arguments work, basically by making BaseCommand take an aray of args in __init__ and then passing it all of the args in parse_cmd

This commit is contained in:
Sam Abradi 2015-02-24 18:00:21 -05:00
parent 80ac53e72e
commit 2ed55a58d2
3 changed files with 9 additions and 8 deletions

View File

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

View File

@ -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 output_generator():
for line in self.input_cmd():
yield line
for line in self.cmd_args:
yield line.encode('utf-8')
return output_generator()

View File

@ -10,6 +10,7 @@ for path in os.environ['PATH'].split(':'):
if os.path.exists(path):
binaries = os.listdir(path)
for binary in binaries:
if binary not in globals():
globals()[binary] = RawCommand(binary)
@ -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):