Hacker News new | ask | show | jobs
by knuckle_cake 5878 days ago
I'm writing a monitor for an emulator I'm working on, so your first example is what I am doing.

I was wanting for something that lets me add commands, with aliasing, and arguments (maybe with optional regex validation) - e.g. breakpoint add $BEEF, etc. Writing a DSL is one solution and will probably end up being the way I go once I take a second iteration at this. Right now I'm just using regex parsing, but I only have a few commands I need to worry about now.

cmdparse is frustratingly close but makes a few assumptions that you want to parse ARGV or something that looks like it.

1 comments

Did you come across a project named Boson (I think), it allows aliasing of commands, and various other options. Check this: http://tagaholic.me/2009/10/14/boson-command-your-ruby-unive...
Interesting, but it looks to require irb, heavily pollutes the global namespace with commands, and assumes I want to use --options-with-dashes. This is another 'close, but not quite' example.

The current implementation is that I have a hardware instance (like a CPU) that I want to monitor. To do that, I create a new monitor object, and tell it to monitor the hardware instance, and the monitor will mix itself in from there. It's not good if extra methods show up in the global namespace just for command parsing within a single module of the app. The monitor is just a part of this application, and a part that will not be used often by most users.

Everything I see feels like it's inches from what I really need. So close yet so far :)

Another option that comes to mind is Thor by yehuda katz (took me ten minutes to recall the name!): http://yehudakatz.com/2008/05/12/by-thors-hammer/

otoh, there are some simple ones you could possible customize: i once studied and modified Choice (by Chris Wainstrath).

I'd really like to know if you find something that helps you, or what you did eventually.

I looked at both already. Both assume ARGV-like command strings with --long-switches with no way to get around that without significant rewriting/additional feature work.

Of everything, cmdparse is closest to what I want (by a significant margin,) but it's GPL (not LGPL :( ) so I'm not even sure I can use it in a non-GPL app. If cmdparse were under less-restrictive licensing I would have just hacked it up and released it already. I had already started doing so until I saw the license.

Right now, just writing a DSL is likely going to be my solution. I can bind an irb session to the monitor to keep scope from running away I think. Writing my own command parsing library just isn't interesting enough to me and I don't think I would ever finish it. This itch isn't quite that strong, at least not now.

What I really should do and am going to do later is look into irc clients written in ruby to see how they are doing it. They would probably run into this same problem.

Looking into said IRC clients, they all look to use regexps like I'm also doing. buh.