The following is a CLI used to be able to run a python callable on a remote machine. Its purpose is the be the recieving end of a list of key=value pairs=:) and will inject this into the **kwargs of the specified callable.
This function was used after deploying code to the remote machine and configurations had been marshalled into the form given above.
The main CLI would construct this class by passing in a subparser named run to the parser value. With the following line, this class is automatically pointing the main CLI towards the do_it function when the run subparser is used.
self.parser.set_defaults(func=self.do_it)
An example usage is cli run python.py my=arg hello=bye where run would cause argparse to load the subparser and thus the func. The main CLI would have the following logic to run whatever code is associated with the subparser.
def main():
args = parser.parse_args()
# If no sub command is specified, print help and exit
if not hasattr(args, 'func'):
print("Error: please use at least one positional argument\n", file=sys.stderr)
parser.print_help()
exit(1)
# Otherwise trigger sub command
args.func(args)