Class: Boson::Runner

Inherits:
BareRunner show all
Defined in:
lib/boson/runner.rb

Overview

Defines a RunnerLibrary for use by executables as a simple way to map methods to subcommands

Constant Summary

Constants inherited from BareRunner

BareRunner::DEFAULT_LIBRARIES, BareRunner::GLOBAL_OPTIONS

Class Method Summary collapse

Methods inherited from BareRunner

allowed_argument_error?, no_command_error

Methods included from BareRunner::API

#abort_with, #all_libraries, #default_libraries, #init, #start

Class Method Details

.app_nameObject



54
55
56
# File 'lib/boson/runner.rb', line 54

def self.app_name
  File.basename($0).split(' ').first
end

.default_librariesObject



12
13
14
# File 'lib/boson/runner.rb', line 12

def self.default_libraries
  [self]
end

.display_default_usageObject



47
48
49
50
51
52
# File 'lib/boson/runner.rb', line 47

def self.display_default_usage
  commands = Boson.commands.sort_by(&:name).map {|c| [c.name, c.desc.to_s] }
  puts "Usage: #{app_name} COMMAND [ARGS]", "", "Available commands:",
    Util.format_table(commands), "",
    "For help on a command: #{app_name} COMMAND -h"
end

.display_help(cmd) ⇒ Object



37
38
39
40
41
42
43
44
45
# File 'lib/boson/runner.rb', line 37

def self.display_help(cmd)
  puts "Usage: #{app_name} #{cmd.name} #{cmd.basic_usage}".rstrip, ""
  if cmd.options
    puts "Options:"
    cmd.option_parser.print_usage_table(no_headers: true)
    puts ""
  end
  puts "Description:\n  #{cmd.desc || 'TODO'}"
end

.execute(command, args, options) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/boson/runner.rb', line 25

def self.execute(command, args, options)
  if options[:help] || command.nil?
    display_default_usage
  else
    execute_command(command, args, options)
  end
end

.execute_command(cmd, args, options) ⇒ Object



33
34
35
# File 'lib/boson/runner.rb', line 33

def self.execute_command(cmd, args, options)
  Command.find(cmd) ? super(cmd, args) : no_command_error(cmd)
end

.inherited(mod) ⇒ Object



7
8
9
10
# File 'lib/boson/runner.rb', line 7

def self.inherited(mod)
  @help_added ||= add_command_help
  Inspector.enable all_classes: true, module: mod.singleton_class
end

.start(args = ARGV) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/boson/runner.rb', line 16

def self.start(args=ARGV)
  Boson.in_shell = true
  ENV['BOSONRC'] ||= ''
  super
  init
  command, options, args = parse_args(args)
  execute command, args, options
end