Module: Rbdock::Command::Options
- Defined in:
- lib/rbdock/command/options.rb
Class Method Summary collapse
- .check_version_avaiable(argv) ⇒ Object
- .create_command_parser(options) ⇒ Object
- .list_ruby_versions ⇒ Object
- .parse!(argv) ⇒ Object
- .ruby_version_perser(options, argv) ⇒ Object
- .set_default_value(options) ⇒ Object
- .show_help(opt) ⇒ Object
- .show_version(opt) ⇒ Object
Class Method Details
.check_version_avaiable(argv) ⇒ Object
73 74 75 76 77 78 79 |
# File 'lib/rbdock/command/options.rb', line 73 def self.check_version_avaiable argv argv.each do |v| if not Rbdock::Generate.ruby_versions.include? v raise ArgumentError, "Definition not found: #{v} \n\nYou can list all available ruby versions with `rbdock --list'." end end end |
.create_command_parser(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rbdock/command/options.rb', line 27 def self.create_command_parser OptionParser.new do |opt| show_version opt show_help opt opt.on('-i name','--image=name', 'Set image name(ubuntu|centos)') { |v| [:image] = v } opt.on('--rbenv', desc='Use rbenv') { [:use_rbenv] = true } opt.on('--rvm', desc='Use rvm') { [:use_rvm] = true } opt.on('-a path','--app=path', 'Add Rails/Sinatra app') { |path| [:app] = path } opt.on('-l','--list', 'List all available ruby versions') { list_ruby_versions } end end |
.list_ruby_versions ⇒ Object
81 82 83 84 85 86 |
# File 'lib/rbdock/command/options.rb', line 81 def self.list_ruby_versions STDERR.print "Available versions:\n " STDERR.print Rbdock::Generate.ruby_versions.join("\n ") STDERR.puts exit end |
.parse!(argv) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rbdock/command/options.rb', line 7 def self.parse!(argv) = {} set_default_value command_parser = create_command_parser begin command_parser.parse!(argv) ruby_version_perser , argv rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e abort e. end end |
.ruby_version_perser(options, argv) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/rbdock/command/options.rb', line 66 def self.ruby_version_perser , argv raise ArgumentError, "#{[:command]} ruby versions not found." if argv.empty? check_version_avaiable argv [:ruby_versions] = argv end |
.set_default_value(options) ⇒ Object
23 24 25 |
# File 'lib/rbdock/command/options.rb', line 23 def self.set_default_value [:image] = "ubuntu" end |
.show_help(opt) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/rbdock/command/options.rb', line 58 def self.show_help opt opt. = "Usage: #{opt.program_name} <ruby-versions> [<args>]" opt.on_tail('-h','--help','Show this message') { STDERR.puts opt.help exit } end |