Looking to select a CLI framework.

From: Brian G.
Sent on: Monday, March 12, 2012 2:56 PM
For my first few CLI tools that I wrote I just used OptionParser (optparse), and it worked fine for my needs. Here is one example. https://github.com/theforeman/foreman/blob/0.4-stable/extras/cli/foremancli

I getting ready to rewrite foremancli as a git style command/subcommand tool, and found a number of tools that support this, including but not limited to subcommand, thor, boson, gli, trollop, Commander, etc. Here is a partial list that I found, for those that are interested: http://stackoverflow.com/questions/9577718/what-ruby-libraries-should-i-use-for-building-a-console-based-application

In my evaluation, I have a few requirements:

1) Allows me to directly call my cli command without having to call the framework explicitly from the commandline. e.g. - I don't want my users to have to type "boson task"
2) Does the help and syntax checking for me (Assuming I correctly define things in a DSL, Classes or etc.)
3) Supports more than one level of subcommand.. ( If I am using more than one level deep, one can assume the levels higher than the last level are more akin to namespaces, rather than a standalone command. e.g. - hammer hosts list/create/delete)
4) Supports subcommand options (These are specific to the subcommand, although some may be applicable to more than one subcommand.)
5) Supports global flags/options that can come before the subcommand on the command line. e.g. command --debug --server servername --config filename subcomand. (I think it's intuitive that global flags come before the subcommands, and really want to write my command to follow that convention, just as git does.)

I have found that Thor is fairly easy to use, but doesn't support #4. Boson, seems to support most of what I want except #1. Gli, doesn't seem to support #3. I have been picking through these, and the search is starting to become a bit tedious, so I figured, I'd ask the group, and see if anyone knows the answers.

Please feel free to ask if you need more information, or if my intent is unclear. (This is the wiki page for the command I am working on, in case folks are curious: http://theforeman.org/projects/foreman/wiki/Hammer ).

Thanks,
Brian

--


People in this
Meetup are also in:

Sign up

Meetup members, Log in

By clicking "Sign up" or "Sign up using Facebook", you confirm that you accept our Terms of Service & Privacy Policy