class RubyYacht::Runner::Shell

This class provides a command for opening a shell in an app container.

Attributes

app_name[RW]

The name of the app that we are opening a shell in.

command[RW]

The name of the command that we are invoking in the shell.

project_name[RW]

The name of the project that the app is in.

Public Class Methods

command() click to toggle source

The name of the command.

# File lib/ruby_yacht/runner/shell.rb, line 5
def self.command; 'shell'; end
description() click to toggle source

The description of the command.

# File lib/ruby_yacht/runner/shell.rb, line 8
def self.description
  "Open a shell in a container"
end

Public Instance Methods

option_parser() click to toggle source

This method gets the command-line options for the command.

# File lib/ruby_yacht/runner/shell.rb, line 22
def option_parser
  OptionParser.new do |options|
    options.banner = "Usage: #{Command.short_script_name} shell [options] [APP] [command]"
    options.separator ""
    options.separator "The command is optional. If you omit it, this will open a bash shell"
    options.separator ""
    options.separator "Options:"

    options.on('-p', '--project PROJECT', "The project with the app we are opening the sell in. Default: #{default_project.name}") do |name|
      self.project_name = name.to_sym
    end
  end
end
parse_positional_arguments(arguments) click to toggle source

This method extracts the arguments from the command line.

### Parameters

  • **arguments: Array** The command-line arguments.

# File lib/ruby_yacht/runner/shell.rb, line 41
def parse_positional_arguments(arguments)
  self.app_name = arguments.shift
  self.command = arguments.join(' ')
  if self.command == ''
    self.command = 'bash'
  end
end
run() click to toggle source

This method runs the logic for the command.

# File lib/ruby_yacht/runner/shell.rb, line 50
def run
  if app_name.nil?
    log "You must provide an app name"
    log "Run #{Command.short_script_name} help shell for more information"
    return false
  end

  project = self.project_named(project_name)
  return false unless project

  app = project.apps.find { |a| a.name == app_name.to_sym }
  container = app.container_name
  exec("docker exec -it #{container} bash -c 'cd /var/code; TERM=xterm #{command}'")
  true
end