News for hackers. Stuff that matters.
Re:Explainshell – match command-line arguments to their help... by idank on Thursday August 29, 2013 @02:27PM (#6297603)
Author here, thanks for the feedback guys!

- adding support for shell syntax is definitely the next thing on my todo list. It's a bit tricky since Python's shlex (which I'm using to parse the command line) is fairly limited in functionality and pretty much only handles quotes. So I'll have to write a mini bash parser which isn't trivial.

- the automatic options extractor isn't perfect and requires manual corrections here and there

- add an API for command line tools

I'll be happy to answer any questions you might have.

Re:Explainshell – match command-line arguments to their help... by riskable on Thursday August 29, 2013 @06:23PM (#6299005)
I wrote a very sophisticated iptables command line argument parser a while back and found shlex to be too limited. Instead I used Pythons OptionParser module--in reverse! It worked out great:

http://sourceforge.net/apps/trac/pyci/browser/iptables.py

The mechanism used by that code may or may not be helpful for you but feel free to email me (daniel.mcdougall at liftoff software dot com) if you want to collaborate. I'd love to put together a module that anyone can import to interpret/explain commands that can perform man page lookups and whatnot.

Re:Explainshell – match command-line arguments to their help... by idank on Friday August 30, 2013 @07:51AM (#6301215)
Re:Explainshell – match command-line arguments to their help... by DEinspanjer on Thursday August 29, 2013 @03:07PM (#6297891)
I'm a pretty fair hand with regexes, if you would like any assistance, please feel free to drop me a line.
Re:Explainshell – match command-line arguments to their help... by idank on Thursday August 29, 2013 @03:37PM (#6298113)
The regex is already getting out of hand ;) https://gist.github.com/idank/6382427

At some point I wanted to convert it to a DFA because I thought it will give me more control and flexibility and be more maintainable over time. The thing to look out for is not make it too permissive so it starts catching things that aren't really options.

Re:Explainshell – match command-line arguments to their help... by fudged71 on Thursday August 29, 2013 @05:17PM (#6298676)
It's funny that a similar tool to your service can be used to build it! http://www.debuggex.com/
Re:Explainshell – match command-line arguments to their help... by mtdewcmu on Thursday August 29, 2013 @09:20PM (#6299691)
The occasional tool, like find, is beyond the capabilities of a DFA, because it's based on a context free grammar (e.g., it counts parentheses).
Re:Explainshell – match command-line arguments to their help... by JelteF on Friday August 30, 2013 @06:40AM (#6301046)
True for official regular expressions, but not for the ones used in most programming languages. http://nikic.github.io/2012/06/15/The-true-power-of-regular-...
Re:Explainshell – match command-line arguments to their help... by mtdewcmu on Friday August 30, 2013 @03:55PM (#6303839)
True. Perl-style regexes have grown capabilities far beyond regexes in formal language theory. Note that I was referring to DFAs.
Re:Explainshell – match command-line arguments to their help... by idank on Friday August 30, 2013 @04:18AM (#6300743)
This regex is the one I used to extract options from man pages, not to parse the command line (which is simply a wrapper around Python's shlex).
Re:Explainshell – match command-line arguments to their help... by mtdewcmu on Friday August 30, 2013 @04:11PM (#6303921)
I see. I started doing almost the exact same thing at one time. My goal was to create autocomplete rules. I think I used the output from the tool's --help or -? rather than manpages, and I would have been using awk and sed, since I never learned Python.

Bash autocomplete specifications are messy, but you can sidestep a lot of the mess. You're allowed to run an arbitrary command to generate the completion list. I was envisioning some kind of standard option grammar that the autocomplete program would interpret for a given tool. The grammar would be partly generated automatically, but would likely need hand-tuning.

Re:Explainshell – match command-line arguments to their help... by hyperpape on Thursday August 29, 2013 @03:02PM (#6297858)
This is great.

I would love an easily found example for find. Fucking find...

Re:Explainshell – match command-line arguments to their help... by unnuun on Thursday August 29, 2013 @10:26PM (#6299891)
Are you aware of [http://www.shellcheck.net/]? Its pretty slick, and you may be able to work wit tat a little bit.