Skip to content

Commit

Permalink
Adding kwargs support
Browse files Browse the repository at this point in the history
  • Loading branch information
adamkerz committed Aug 2, 2020
1 parent 15c20df commit 1d5fc2c
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions pie.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Enables a user to execute predefined tasks that may accept parameters and options from the command line without any other required packages.
Great for bootstrapping a development environment, and then interacting with it.
"""
__VERSION__='0.3.0h'
__VERSION__='0.3.0i'


import inspect
Expand Down Expand Up @@ -261,6 +261,7 @@ def cmd(cls,c,i=None):
errorcode=CmdExecutor.cmd_fn(c)
if errorcode!=0:
raise cls.CmdError(errorcode,c)
return errorcode

@classmethod
def exit(cls):
Expand Down Expand Up @@ -656,16 +657,32 @@ def parseArguments(args):
i+=1
else:
raise Exception('Unknown argument: {}'.format(arg))
i+=1
else:
mo=TASK_RE.match(arg)
if mo:
taskArgs=mo.group('args')
taskArgs=taskArgs.split(',') if taskArgs else []
taskKwArgs={}
# and consume following -- args
i+=1
while i<len(args):
arg=args[i]
# kwargs must start with --
if not arg.startswith('--'): break
arg=arg[2:]
if '=' in arg:
name,value=arg.split('=')
else:
name=arg
value=True
name=name.replace('-','_')
taskKwArgs[name]=value
i+=1
# TODO: add further parsing to handle keyword arguments
parsed.append(TaskCall(mo.group('name'),args=taskArgs,kwargs={}))
parsed.append(TaskCall(mo.group('name'),args=taskArgs,kwargs=taskKwArgs))
else:
raise Exception('Unknown task format: {}'.format(arg))
i+=1
return parsed


Expand Down

0 comments on commit 1d5fc2c

Please sign in to comment.