Howto tab completion

Hello,

I use [1] to process a string from cmdline-user-input to call methods
form a module namespace. It works for
now, but there are later a lot of commands to input so i want
tab-completion because iam lazy :slight_smile:

module CmdsBase
聽聽CmdsBase.cmd_foo
聽聽聽聽DoSomething.new
聽聽end

聽聽...
end

All methods with /^cmd_(\w*)$/ should be completeable from
commandline.

Any ideas to solve this clean?

[1]
聽聽# snip:
聽聽def self.cmd
聽聽聽聽begin

聽聽聽聽聽聽line = gets
聽聽聽聽聽聽args, i =[], -1
聽聽聽聽聽聽line.scan(/\w*\s/) do |a|
聽聽聽聽聽聽聽聽a.strip!
聽聽聽聽聽聽聽聽meth = nil
聽聽聽聽聽聽聽聽unless (i+=1).zero? and

聽聽聽聽聽聽聽聽MyBiadjCmdlineCaller.methods.include?(a)
聽聽聽聽聽聽聽聽聽聽break if i.zero?
聽聽聽聽聽聽聽聽聽聽args.push(a)
聽聽聽聽聽聽聽聽else
聽聽聽聽聽聽聽聽聽聽meth = a
聽聽聽聽聽聽聽聽end

聽聽聽聽聽聽聽聽unless args.size.zero? # ignoring input with arguments yet
聽聽聽聽聽聽聽聽聽聽MyBiadjCMDLine.ok?(MyBiadjCmdlineCaller.method(meth).call)
聽聽聽聽聽聽聽聽end

聽聽聽聽聽聽end
聽聽聽聽end while true
聽聽end

So long

路路路

--
Michael 'entropie' Trommer; http://ackro.org

ruby -e "0.upto((a='njduspAhnbjm/dpn').size-1){|x| a[x]-=1}; p 'mailto:'+a"

Have you tried using the Readline module?

require "readline"
$completions = ["cmd_1","cmd_42","cmd_one"]
Readline::completion_proc = Proc.new{ |prefix| $completions if prefix
=~ /cmd_/ }
0.upto(4) { line = Readline::readline( "Cmd? ", true ) }

You get the idea...

Daniel.

thanks a lot, thats what i need!

So long

路路路

* Daniel Calvelo (dca.gis@gmail.com) wrote:

Have you tried using the Readline module?

require "readline"
$completions = ["cmd_1","cmd_42","cmd_one"]
Readline::completion_proc = Proc.new{ |prefix| $completions if prefix
=~ /cmd_/ }
0.upto(4) { line = Readline::readline( "Cmd? ", true ) }

--
Michael 'entropie' Trommer; http://ackro.org

ruby -e "0.upto((a='njduspAhnbjm/dpn').size-1){|x| a-=1}; p 'mailto:'+a"