Module: Boson::BinRunner::API

Included in:
Boson::BinRunner
Defined in:
lib/boson/bin_runner.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#commandObject

Returns the value of attribute command.



20
21
22
# File 'lib/boson/bin_runner.rb', line 20

def command
  @command
end

Instance Method Details

#command_name(cmd) ⇒ Object

Determine command name given full command name. Overridden by namespaces



64
65
66
# File 'lib/boson/bin_runner.rb', line 64

def command_name(cmd)
  cmd
end

#command_not_found?(cmd) ⇒ Boolean

Determines if a NoMethodError is a command not found error

Returns:

  • (Boolean)


69
70
71
# File 'lib/boson/bin_runner.rb', line 69

def command_not_found?(cmd)
  cmd[/\w+/]
end

#default_error_message(err) ⇒ Object

Constructs error message



74
75
76
# File 'lib/boson/bin_runner.rb', line 74

def default_error_message(err)
  "Error: #{err.message}"
end

#early_option?(args) ⇒ Boolean

Returns true if an option does something and exits early

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
43
44
# File 'lib/boson/bin_runner.rb', line 34

def early_option?(args)
  if @options[:version]
    puts("boson #{Boson::VERSION}")
    true
  elsif args.empty? || (@command.nil? && !@options[:execute])
    print_usage
    true
  else
    false
  end
end

#eval_execute_option(str) ⇒ Object

Evaluates :execute option.



29
30
31
# File 'lib/boson/bin_runner.rb', line 29

def eval_execute_option(str)
  Boson.main_object.instance_eval str
end

#execute_option_or_command(options, command, args) ⇒ Object

Executes functionality from either an option or a command



23
24
25
26
# File 'lib/boson/bin_runner.rb', line 23

def execute_option_or_command(options, command, args)
  options[:execute] ? eval_execute_option(options[:execute]) :
    execute_command(command, args)
end

#no_method_error_message(err) ⇒ Object

Handles no method errors



52
53
54
55
56
57
58
59
60
61
# File 'lib/boson/bin_runner.rb', line 52

def no_method_error_message(err)
  @command = @command.to_s
  if err.backtrace.grep(/`(invoke|full_invoke)'$/).empty? ||
    !err.message[/undefined method `(\w+\.)?#{command_name(@command)}'/]
      default_error_message($!)
  else
    command_not_found?(@command) ?
      "Error: Command '#{@command}' not found" : default_error_message(err)
  end
end

prints full usage



83
84
85
86
# File 'lib/boson/bin_runner.rb', line 83

def print_usage
  print_usage_header
  @option_parser.print_usage_table
end


78
79
80
# File 'lib/boson/bin_runner.rb', line 78

def print_usage_header
  puts "boson [GLOBAL OPTIONS] [COMMAND] [ARGS] [COMMAND OPTIONS]\n\n"
end

#verboseObject

Determines verbosity of this class



47
48
49
# File 'lib/boson/bin_runner.rb', line 47

def verbose
  false
end