How do we make a command line options like this:
I would image the code would look like this
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
A menu in a console windows can be done with several gems, the best known are curses , tty-prompt and derivates and Highlight
If you want a simple graphical menu see my answer here .
See here for an example of what curses can do. Here are more examples.
Result will depend on OS and console being used.
I wrote tty-prompt gem to help build interactive menus. Implementation of the example would look like:
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
The above will render the following select menu in the console:
This gem is tested to work on a variety of operating systems and there are many types of prompts available.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.