Ruby command-line parsing (update)
The issues with optiflag and choice: regarding determining unparsed arguments seems to have been posted in their respective forums a year or 2 back. But no response from authors. Are these 2 projects abandoned ?
I dipped into the source code of choice (parser.rb) to see if i could figure out how to extract the args, but after trying out variations on the command line, and print statements, it does not look like an easy task – not for me at least (a newbie). The author is a big-shot and busy (and very cool looking), so I guess he won’t be reading my mail for some time (http://www.youtube.com/watch?v=-Reg0yhJw4s !).
The comments on this page led me to some excellent options such as:
– Thor: by whycat’s (yehuda katz). It’s a great tool, maps commands on the CL to ruby methods. It is executed like rake: thor prog options. Something definitely to use in the near future.
– clip: This one does state in its help that it allows the remainder args to be accessed. It seems to simplest of all.
– I once again looked at trollop. It does not do any validations, and I am not sure whether the remainder args are accessible or not. What i can see is that I would have to have a separate switch case for all the options.
– I once again looked at Commandline. It begins to look more appealing after the issues I have faced with the others.
– I gave a much closer look at cmdparse : looks great for commands and subcommands as in rake and webgen (its written by the webgen author who is very active and responds immediately). Could not figure out whether it will give me the remainder or not.
As can be seen from my sig on git, I looked at the tutorials of several revision control systems such as bazaar, mercurial, git and subversion and finally decided to try out git after all. Have been using rcs until now.
I’m an egotistical bastard, and I name all my projects after myself. First Linux, now git.
— Linus Torvalds
# print file except for blank lines
$ cat | ruby -pe ‘next if $_ =~ /^\s*$/’