Method: Conify::Command#run

Defined in:
lib/conify/command.rb

#run(klass, method) ⇒ Object

Call a method on a klass with certain arguments. Will validate arguments first before calling method.



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/conify/command.rb', line 73

def run(klass, method)
  # Get the command info for this method on this klass
  command_info_module = klass::CommandInfo.const_get(camelize(method))

  # If seeking help for this command with --help or -h
  if seeking_command_help?(@current_args)
    puts "\nPurpose: #{command_description(command_info_module)}\n"

    # respond with command-specific help
    respond_with_command_help(command_info_module)
    return
  end

  # get the valid arguments defined for this comand
  valid_args = command_valid_args(command_info_module)

  if !valid_args?(valid_args)
    handle_invalid_args(command_info_module)
    return
  end

  klass.new(@current_args.dup).send(method)
end