class RubyYacht::Runner::Checkout
This class provides a command for checking out a new branch for an app.
Attributes
app_name[RW]
The name of the app.
branch[RW]
The branch that we are checking out.
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/checkout.rb, line 5 def self.command; 'checkout'; end
description()
click to toggle source
The short description for the command.
# File lib/ruby_yacht/runner/checkout.rb, line 8 def self.description "Check out a new branch for an app" end
Public Instance Methods
option_parser()
click to toggle source
This OptionParser for parsing command-line flags.
This command accepts the project name as an optional flag.
# File lib/ruby_yacht/runner/checkout.rb, line 24 def option_parser OptionParser.new do |options| options.banner = "Usage: #{Command.short_script_name} checkout [options] [APP] [BRANCH]" options.separator "Options:" options.on('-p', '--project PROJECT', "The project with the app we are checking out the branch 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 positional arguments from the command line.
This will take the app name and branch from the command line.
# File lib/ruby_yacht/runner/checkout.rb, line 38 def parse_positional_arguments(arguments) self.app_name = arguments.shift self.branch = arguments.shift end
run()
click to toggle source
This method runs the logic for the command.
# File lib/ruby_yacht/runner/checkout.rb, line 44 def run if app_name.nil? log "You must provide an app name" log "Run #{Command.short_script_name} help checkout for more information" return false end if branch.nil? log "You must provide a branch" log "Run #{Command.short_script_name} help checkout for more information" return false end project = self.project_named(self.project_name) return false unless project app = project.apps.find { |a| a.name == app_name.to_sym } container_name = app.container_name docker "exec #{container_name} bash -c 'cd /var/code; git fetch; git checkout .; git checkout #{branch}; git pull'" docker "exec #{container_name} /var/docker/before_startup.bash" docker "restart #{container_name}" true end