class Cirun::CLI
Public Class Methods
new()
click to toggle source
# File lib/cirun/cli.rb, line 9 def initialize @options = OpenStruct.new @options.database = '' @options.redmine = '' @options.ruby = '' @options.plugin = '' @options.dependent = '' @options.print = false end
Public Instance Methods
parse()
click to toggle source
# File lib/cirun/cli.rb, line 19 def parse OptionParser.new do |opts| opts.banner = 'Usage: cirun [options]' opts.on('-d', '--database DATABASE', "Specify database #{database_list}") do |db| @options.database = db end opts.on('-m', '--redmine REDMINE', "Specify redmine #{redmine_list}") do |redmine| @options.redmine = redmine end opts.on('-r', '--ruby RUBY', "Specify ruby #{ruby_list}") do |ruby| @options.ruby = ruby end opts.on('-p', '--plugin PLUGIN', "Specify plugin (will try to guess from pwd)") do |plugin| @options.plugin = plugin end opts.on('-e', '--dependent DEPENDENT', "Specify plugin dependency") do |dependent| @options.dependent = dependent end opts.on( '-i', '--interactive', 'Instead of executing docker for you this will just print', ' required command string to the standard output.', ' This is useful when you want to run interactive', ' debug session. Docker CLI is very hard to trick', ' so with this option you can just backtick output', ' like: `cirun -d mysql -m 2.3 -r 1.9.3-p551 -i`' ) do @options.print = true end end.parse! validate_options || abort_due_to_lack_of_options enhance_options @options end
Private Instance Methods
abort_due_to_lack_of_options()
click to toggle source
# File lib/cirun/cli.rb, line 77 def abort_due_to_lack_of_options puts "Database should be given and be one of #{database_list}" unless validate_database puts "Ruby should be given and be one of #{ruby_list}" unless validate_ruby puts "Redmine should be given and be one of #{redmine_list}" unless validate_redmine exit -1 end
database_list()
click to toggle source
# File lib/cirun/cli.rb, line 89 def database_list Cirun::Variants::DATABASES.join('|') end
enhance_options()
click to toggle source
# File lib/cirun/cli.rb, line 84 def enhance_options return if @options.plugin.size > 0 @options.plugin = Dir.pwd.split('/').last end
redmine_list()
click to toggle source
# File lib/cirun/cli.rb, line 93 def redmine_list Cirun::Variants::REDMINES.join('|') end
ruby_list()
click to toggle source
# File lib/cirun/cli.rb, line 97 def ruby_list Cirun::Variants::RUBIES.join('|') end
validate_database()
click to toggle source
# File lib/cirun/cli.rb, line 65 def validate_database @options.database.size > 0 && Cirun::Variants::DATABASES.include?(@options.database) end
validate_options()
click to toggle source
# File lib/cirun/cli.rb, line 59 def validate_options validate_database && validate_ruby && validate_redmine end
validate_redmine()
click to toggle source
# File lib/cirun/cli.rb, line 73 def validate_redmine @options.redmine.size > 0 && Cirun::Variants::REDMINES.include?(@options.redmine) end
validate_ruby()
click to toggle source
# File lib/cirun/cli.rb, line 69 def validate_ruby @options.ruby.size > 0 && Cirun::Variants::RUBIES.include?(@options.ruby) end