我有使用highline的gem / cli,我想知道你是否可以设置自己的命令,因此它始终可用(类似于'help')。
require 'rubygems'
require 'highline/import'
say("\nThis is the new mode (default)...")
choose do |menu|
menu.prompt = "Please choose your favorite programming language? "
menu.choice :ruby do say("Good choice!") end
menu.choices(:python, :perl) do say("Not from around here, are you?") end
end
say("\nThis is letter indexing...")
choose do |menu|
menu.index = :letter
menu.index_suffix = ") "
menu.prompt = "Please choose your favorite programming language? "
menu.choice :ruby do say("Good choice!") end
menu.choices(:python, :perl) do say("Not from around here, are you?") end
end
say("\nThis is with a different layout...")
choose do |menu|
menu.layout = :one_line
menu.header = "Languages"
menu.prompt = "Favorite? "
menu.choice :ruby do say("Good choice!") end
menu.choices(:python, :perl) do say("Not from around here, are you?") end
end
谢谢!
答案 0 :(得分:2)
我认为这只能通过相当怪异的猴子修补高线宝石来实现,除非您想要将命令添加到每个选项中(您最喜欢的编程语言是什么?1。ruby 2. perl 3. help 4. menu 5.退出...),您可以通过以下方法提取:
def add_custom_choices(menu)
menu.choice(:quit) do
say "Ok, see you."
exit 0
end
menu.choice(:dostuff) do call_do_stuff_method end
end
# and later ...
choose do |menu|
# ...
menu.choice :ruby do say("Good choice!") end
add_custom_choices menu
# ....
end