AbnormalSec / darkbox

what's in the box?! :package:
Do What The F*ck You Want To Public License
2 stars 1 forks source link

Running from repl, unit tests, and scripts - argument format? #11

Closed deadPix3l closed 5 years ago

deadPix3l commented 6 years ago

In order to support running tools programmatically, you can pass arguments as a list of strings to parse_args() (or via get_args() in this case). Passing None will default to usual commandline behavior.

When should this list be passed?

from commands import xxd

c = xxd( here? ) # __init__()
# c.custom_args(Here?) # custom function?
c.run( Here? )

Note: this will not effect how the command line parsing operates. only how it is called from repl and unit tests.

the first option would require init() to save the args, and has the added benefit/curse that rerunning the object will run again with the same arguments. changing the arguments requires creating a new instance

vesche commented 6 years ago

A quick google search turned up this: https://stackoverflow.com/a/49838142

Looks like we can just do something like this:

from commands import xxd
args = ['--arg1', 'asdf', '--arg2', 'qwer']
c = xxd()
c.get_parser().parse_args(args)