[Ruby] tools for building a "smart" command-line language

Doug Beaver doug at beaver.net
Mon Aug 28 17:23:00 PDT 2006


On Mon, Aug 28, 2006 at 04:08:47PM -0700, Scott Laird wrote:
> On 8/28/06, Doug Beaver <doug at beaver.net> wrote:
> >
> > i'm not sure why you require the language to go back and forth between
> > the AST, are you looking to validate it?  or is there some magic i'm
> > missing?
> 
> Yeah.  You're missing the use case that I didn't mention.  I want  to
> be able to do the equivalent of this:
> 
> $ interface FastEthernet0/0
> interface$ ip 192.168.0.2
> interface$ end
> 
> That is, make small incremental changes via a commandline interface.
> That's kind of the point of the whole thing :-).  This little change
> needs to be persisted back to a static config file *and* it needs to
> trigger some action in the system.

irb does someting very similar:

irb(main):001:0> def foo
irb(main):002:1> puts "hi"
irb(main):003:1> end
=> nil
irb(main):004:0> foo()
hi
=> nil

note the 002:1, it knows it's inside a method definition.  you could
write something similar to irb for your interactive shell case.
persistence is easy to add in once you have your interactive piece
complete.

there has been work on pure ruby shells, so looking at that combined
with irb should get you where you want to go.  i'm thinking that all of
the machinery is there waiting for you, you just need to go glue it
together.  your use case seems pretty simple, so this should be doable
with existing tools...  the AST still seems like overengineering to
me...  YMMV.

doug

-- 
"Contrary to what most people say, the most dangerous animal in the
world is not the lion or the tiger or even the elephant.  It's a shark
riding on an elephant's back, just trampling and eating everything they
see." -- Jack Handey


More information about the Ruby mailing list