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:
parent
80ac53e72e
commit
2ed55a58d2
@ -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")
|
||||
|
@ -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()
|
||||
|
||||
|
5
main.py
5
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):
|
||||
|
Reference in New Issue
Block a user