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
94 95 96 97 98 99 100 |
# File 'lib/rbdock/command/options.rb', line 94 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
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/rbdock/command/options.rb', line 33 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)') { |i| [:image] = i } opt.on('-a path','--app=path', 'Add Rails/Sinatra app') { |path| [:app] = path } opt.on('-o filename', '--ouput=filename', 'Set output Dockerfile name') { |f| [:output_filename] = f } opt.on('-f','--force', 'Attempt to overwrite Dockerfile without prompting for confirmation') {|b| [:force_write_mode] = b } opt.on('--rbenv', desc='Use rbenv for ruby version manager') { [:use_rbenv] = true } opt.on('--rvm', desc='Use rvm for ruby version manager') { [:use_rvm] = true } opt.on('-l','--list', 'List all available ruby versions') { list_ruby_versions } opt.on('--debug', desc='Run as debug mode') end end |
.list_ruby_versions ⇒ Object
102 103 104 105 106 107 |
# File 'lib/rbdock/command/options.rb', line 102 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 22 23 24 25 26 |
# File 'lib/rbdock/command/options.rb', line 7 def self.parse!(argv) # Setup logger @logger = Log4r::Logger.new("rbdock::command::options") # Restore option and its value = {} 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
87 88 89 90 91 92 |
# File 'lib/rbdock/command/options.rb', line 87 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
28 29 30 31 |
# File 'lib/rbdock/command/options.rb', line 28 def self.set_default_value [:image] = "ubuntu" [:output_filename] = "Dockerfile" end |
.show_help(opt) ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/rbdock/command/options.rb', line 79 def self.show_help opt opt. = "Usage: #{opt.program_name} <ruby-versions> [options]" opt.on_tail('-h','--help','Show this message') { STDERR.puts opt.help exit } end |