Module: RubyYacht::Runner

Defined in:
lib/ruby_yacht/runner.rb,
lib/ruby_yacht/runner/help.rb,
lib/ruby_yacht/runner/build.rb,
lib/ruby_yacht/runner/shell.rb,
lib/ruby_yacht/runner/runner.rb,
lib/ruby_yacht/runner/command.rb,
lib/ruby_yacht/runner/implode.rb,
lib/ruby_yacht/runner/checkout.rb,
lib/ruby_yacht/runner/services.rb,
lib/ruby_yacht/runner/build_images.rb,
lib/ruby_yacht/runner/update_hosts.rb,
lib/ruby_yacht/runner/run_containers.rb,
lib/ruby_yacht/runner/create_new_project.rb

Overview

This module groups together classes for running commands for managing the docker environment.

Defined Under Namespace

Classes: Build, BuildImages, Checkout, Command, CreateNewProject, Help, Implode, RunContainers, Services, Shell, UpdateHosts

Class Method Summary collapse

Class Method Details

.argumentsObject

This method gets the arguments for the current command.



29
30
31
# File 'lib/ruby_yacht/runner/runner.rb', line 29

def self.arguments
  ARGV
end

.clear_commandsObject

This method clears our list of commands that we can run.



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

def self.clear_commands
  @commands = []
end

.commandsObject

This method provides the commands that we can run.



3
4
5
# File 'lib/ruby_yacht/runner/runner.rb', line 3

def self.commands
  @commands ||= []
end

.load_default_commands(in_project = true) ⇒ Object

This method loads the default commands into our command list.

Parameters

  • in_project* Boolean Whether we are running a script in the context of a project, or in the top-level ruby_yacht command.


19
20
21
22
23
24
25
26
# File 'lib/ruby_yacht/runner/runner.rb', line 19

def self.load_default_commands(in_project=true)
  @commands ||= []
  if in_project
    @commands += [Help, Build, BuildImages, RunContainers, Services, Checkout, Shell, UpdateHosts, Implode]
  else
    @commands += [Help, CreateNewProject]
  end
end

.runObject

This method runs a command based on the command line arguments.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ruby_yacht/runner/runner.rb', line 34

def self.run
  load_default_commands if self.commands == []
  arg = arguments[0]

  if arg == '' || arg == nil
    puts "You must provide a command to run"
    puts "Run `#{$0} help` for more information"
    exit(1)
    return false
  end

  command = self.commands.find { |c| c.command == arg }
  if command
    command_arguments = arguments
    command_arguments.shift

    instance = command.new
    instance.option_parser.parse! command_arguments
    instance.parse_positional_arguments command_arguments
    
    success = instance.run
    unless success
      exit(1)
    return false
    end
  else
    puts "Command not recognized: #{arg}"
    puts "Run `#{$0} help` for more information"
    exit(1)
    return false
  end
  true
end