Open deadbits opened 5 years ago
Since many of the commands will accept artifacts as an argument, we'll also add a generic parser that will handle these more standard args of -l, --last
for last created artifact, -n, --name
for artifact by name, and -i, --id
for artifact by session ID like seen in the last comment for tags.
Generic parser example
def parse_identifier(self, args):
"""Parse artifact name out of argparse arguments"""
identifier = None
if args.last:
if args.name or args.id:
error('Only one argument can be specified: --last, --name, --id')
return None
identifier = self.session.receive('artifacts')
elif args.id:
is_key, value = lookup_key(self.session, args.id)
if is_key and value is None:
error('Unable to find artifact key in session (%s)' % args.id)
return None
elif is_key and value is not None:
identifier = value
elif args.name:
identifier = args.name.strip()
else:
error('Must specify one of: --last, --name, --id')
return None
return identifier
By leveraging cmd2's support for argparse we can get rid of a lot of commands and add argument support to many existing ones. For example, we'll now have support for commands like:
tags --view inquest.net
,tags --add inquest.net these are my tags, https://inquest.net
,artifact --new inquest.net
,artifact --view inquest.net
, etc etc.The parsers will go in their own library that we import into omnibus-cli so it doesn't look like garbage inside that script. lets add them to
lib/parsers.py
Example of the tags parser:
and we'd port tags to look something like this: