module CIHelper::CLI

Attributes

args[RW]
command_class[RW]
options[RW]

Public Instance Methods

run!(args) click to toggle source
# File lib/ci_helper/cli.rb, line 9
def run!(args)
  self.args = args.dup
  prepare!
  perform_command!
end

Private Instance Methods

parse_options_from(args) click to toggle source
# File lib/ci_helper/cli.rb, line 28
def parse_options_from(args)
  args
    .slice_when { |_el_before, el_after| el_after.start_with?("--") }
    .each_with_object({}) do |commands, options|
      key = Tools::Inflector.instance.underscore(commands.shift.split("--").last)
      raise "Invalid options" if key.empty?
      value = commands.size <= 1 ? commands.first : commands
      options[key.to_sym] = value || ""
    end
end
perform_command!() click to toggle source
# File lib/ci_helper/cli.rb, line 39
def perform_command!
  command_class.call!(**options).to_i
rescue CIHelper::Commands::Error => error
  raise Error, error.message
end
prepare!() click to toggle source
# File lib/ci_helper/cli.rb, line 19
def prepare!
  class_name = args.shift
  self.options = parse_options_from(args)
  require(Tools::Inflector.instance.underscore("ci_helper/commands/#{class_name}"))
  self.command_class = Commands.const_get(class_name)
rescue LoadError => error
  raise Error, "Can't find command with path: #{error.path}"
end