[英]Command Line Radio Buttons/Options in Ruby
我會想象代碼看起來像這樣
options = Hash.new()
options['Monolithic'] = 'Monolithic application'
options['Microservice'] = 'Microservice application'
options['Gateway'] = 'Microservice gateway'
puts 'Which *type* of application would you like to create?'
options.each do |key, option|
puts option
end
# interface here
我編寫了tty-prompt gem 來幫助構建交互式菜單。 該示例的實現如下所示:
require "tty-prompt"
prompt = TTY::Prompt.new
type = prompt.decorate("*type*", :yellow)
prompt.select("Which #{type} of application would you like to create?") do |menu|
menu.choice "Monolithic application", "Monolithic"
menu.choice "Microservice application", "Microservice"
menu.choice "Microservice gateway", "Gateway"
end
以上將在控制台中呈現以下選擇菜單:
這個 gem 經過測試可以在各種操作系統上工作,並且有多種類型的提示可用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.