Autocompletion of commands & arguments

I want to build a Ruby app with the following broad properties

  • Has some graph of objects, with a root R
  • each object (including R) has some methods, m
  • each m on each object has some args A
  • each A has a set of valid candidates values, defined by method
    candidates_A_m
  • the objects have (string) names

I want to build a command-line interface which lets me:

  • start at the root R
  • invoke methods by typing in a prefix and using TAB
  • choose arg values by typing in object-name prefix and TAB
  • getting autocompletion or suggestion-list whenever possible
  • change my “working” location in the graph (like “cd”) & continue

I have not used Ruby in some time. Am looking for any suggestions on
useful classes / libraries / methods / apps I should consider to make
my life easier :slight_smile:

Thanks!

On Tue, Nov 15, 2011 at 5:17 AM, Sophie [email protected] wrote:

  • start at the root R
  • invoke methods by typing in a prefix and using TAB
  • choose arg values by typing in object-name prefix and TAB
  • getting autocompletion or suggestion-list whenever possible
  • change my “working” location in the graph (like “cd”) & continue

I have not used Ruby in some time. Am looking for any suggestions on useful
classes / libraries / methods / apps I should consider to make my life
easier :slight_smile:

I haven’t worked with it yet but I am almost 100% certain that you at
least want to take a look at “readline”.

$ ri19 Readline
$ gem19 list -b readline

Kind regards

robert

On Nov 15, 2011, at 5:17 AM, Sophie wrote:

  • start at the root R

Hi Sophie,

What would the relation between the objects be ? Named relations ?

You could use an OpenStruct or a hash to hold the related objects and
then iterate through that list as you press tab. The hash key would be
the object name string you indicated in your email.

Once on a object if you want to retrieve the public methods you can:
object.public_methods which returns you an array with the method symbols
so you can iterate through it.

Once on a method you can find out the arity of it with “method.arity”
and find out the name of the parameters and if it is requiered with
“method.parameters” and call it with “method.call”

e.g. From the pick axe:

def m(a, b=1, *c, &d)
end
method(:m).parameters # => [[:req, :a], [:opt, :b], [:rest, :c],
[:block, :d]]

I would not try to replicate that functionality as luckily Ruby provides
us with great reflection methods.
Regards,
V.

-----Messaggio originale-----
Da: Vicente B. Campos [mailto:[email protected]]
Inviato: marted 15 novembre 2011 11:34
A: ruby-talk ML
Oggetto: Re: Autocompletion of commands & arguments

On Nov 15, 2011, at 5:17 AM, Sophie wrote:

I want to build a Ruby app with the following broad properties

  • Has some graph of objects, with a root R
  • each object (including R) has some methods, m
  • each m on each object has some args A
  • each A has a set of valid candidates values, defined by method
    candidates_A_m
    I have not used Ruby in some time. Am looking for any suggestions on
    useful classes / libraries / methods / apps I should consider to make my
    life easier :slight_smile:

Thanks!

Hi Sophie,

What would the relation between the objects be ? Named relations ?

You could use an OpenStruct or a hash to hold the related objects and
then
iterate through that list as you press tab. The hash key would be the
object name string you indicated in your email.

Once on a object if you want to retrieve the public methods you can:
object.public_methods which returns you an array with the method symbols
so
you can iterate through it.

Once on a method you can find out the arity of it with “method.arity”
and
find out the name of the parameters and if it is requiered with
“method.parameters” and call it with “method.call”

e.g. From the pick axe:

def m(a, b=1, *c, &d)
end
method(:m).parameters # => [[:req, :a], [:opt, :b], [:rest, :c],
[:block,
:d]]

I would not try to replicate that functionality as luckily Ruby provides
us
with great reflection methods.
Regards,
V.


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
Conto Arancio al 4,20%. Zero spese e massima liberta’, aprilo in due
minuti!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid922&d)-12

-----Messaggio originale-----
Da: Sophie [mailto:[email protected]]
Inviato: marted 15 novembre 2011 05:18
A: ruby-talk ML
Oggetto: Autocompletion of commands & arguments

I want to build a Ruby app with the following broad properties

  • Has some graph of objects, with a root R
  • each object (including R) has some methods, m
  • each m on each object has some args A
  • each A has a set of valid candidates values, defined by method
    candidates_A_m
  • the objects have (string) names

I want to build a command-line interface which lets me:

  • start at the root R
  • invoke methods by typing in a prefix and using TAB
  • choose arg values by typing in object-name prefix and TAB
  • getting autocompletion or suggestion-list whenever possible
  • change my “working” location in the graph (like “cd”) & continue

I have not used Ruby in some time. Am looking for any suggestions on
useful
classes / libraries / methods / apps I should consider to make my life
easier :slight_smile:

Thanks!


Caselle da 1GB, trasmetti allegati fino a 3GB e in piu’ IMAP, POP3 e
SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f

Sponsor:
ING DIRECT Conto Arancio. 4,20% per 12 mesi, zero spese, aprilo in due
minuti!
Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid924&d)-12