Command Line Libraries

thoughts python cli

Python Command Line Libraries

I really don’t like any of the cli libraries out there. The one I like best is docopt and mainly because it is simple to understand and use. The problem with docopt is that it only does command line parsing. It does not handle argument type conversion or validation, nor does it do dispatching. It does leave your cli interface decoupled from your application, whereas some of these other convience libraries, such as click, couple the building of cli commands and arguments to functions and tend to make heavy use of decorators - a style I don’t find appealing. They also tend toward being application frameworks - something I don’t mind, but I’d rather have more choice over how things are implemented.

In an ideal world it would be nice to see a cli framework that:

1. managed parsing cli arguments (they all do this)

2. auto-dispatch without tight coupling (docopt vs click).

3. validate and convert arguments.

4. provide hooks to common application type events:

    a. logging set up

    b. config file integration (cli arg overrides)

    c. top level error handling