Class: RubyYacht::Runner::Shell
- Defined in:
- lib/ruby_yacht/runner/shell.rb
Overview
This class provides a command for opening a shell in an app container.
Instance Attribute Summary collapse
-
#app_name ⇒ Object
The name of the app that we are opening a shell in.
-
#command ⇒ Object
The name of the command that we are invoking in the shell.
-
#project_name ⇒ Object
The name of the project that the app is in.
Class Method Summary collapse
-
.command ⇒ Object
The name of the command.
-
.description ⇒ Object
The description of the command.
Instance Method Summary collapse
-
#option_parser ⇒ Object
This method gets the command-line options for the command.
-
#parse_positional_arguments(arguments) ⇒ Object
This method extracts the arguments from the command line.
-
#run ⇒ Object
This method runs the logic for the command.
Methods inherited from Command
#backtick, #default_project, #docker, #docker_machine, #get_machine_info, #log, #project_named, #projects, short_script_name, #system
Instance Attribute Details
#app_name ⇒ Object
The name of the app that we are opening a shell in.
16 17 18 |
# File 'lib/ruby_yacht/runner/shell.rb', line 16 def app_name @app_name end |
#command ⇒ Object
The name of the command that we are invoking in the shell.
19 20 21 |
# File 'lib/ruby_yacht/runner/shell.rb', line 19 def command @command end |
#project_name ⇒ Object
The name of the project that the app is in.
13 14 15 |
# File 'lib/ruby_yacht/runner/shell.rb', line 13 def project_name @project_name end |
Class Method Details
.command ⇒ Object
The name of the command.
5 |
# File 'lib/ruby_yacht/runner/shell.rb', line 5 def self.command; 'shell'; end |
.description ⇒ Object
The description of the command.
8 9 10 |
# File 'lib/ruby_yacht/runner/shell.rb', line 8 def self.description "Open a shell in a container" end |
Instance Method Details
#option_parser ⇒ Object
This method gets the command-line options for the command.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ruby_yacht/runner/shell.rb', line 22 def option_parser OptionParser.new do || . = "Usage: #{Command.short_script_name} shell [options] [APP] [command]" .separator "" .separator "The command is optional. If you omit it, this will open a bash shell" .separator "" .separator "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) ⇒ Object
This method extracts the arguments from the command line.
Parameters
- arguments: Array The command-line arguments.
41 42 43 44 45 46 47 |
# 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 ⇒ Object
This method runs the logic for the command.
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# 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 |