microsoft / knack

Knack - A Python command line interface framework
https://pypi.python.org/pypi/knack
MIT License
348 stars 95 forks source link

interest in passing functions, not strings for commands? #195

Open bmc-msft opened 4 years ago

bmc-msft commented 4 years ago

Having found myself frustrated with argparse, I started looking into Knack for argument parsing.

One of the choices that I'm wondering about in Knack is the choice to specify the command groups with strings, which when used are passed to import_module & a python version independent inspect to get the implementation of the command.

This makes it difficult to use static analysis to verify code using this module, since it's roughly akin to eval.

Additionally, it makes it difficult to programmatically generate a CLI from classes, as it requires going from object instance back to strings for the module and function paths.

Is there any interest in supporting functions rather than strings?

Something akin to:

with CommandGroup(self, "hello") as g:
    g.command("world", hello_world_handler)
yonzhan commented 4 years ago

@jiasli please take a look