class Shuttle::CLI
Attributes
command[R]
options[R]
path[R]
Public Class Methods
new(path=nil)
click to toggle source
# File lib/shuttle/cli.rb, line 12 def initialize(path=nil) @path = File.expand_path(path || Dir.pwd) @options = default_options end
run()
click to toggle source
# File lib/shuttle/cli.rb, line 8 def self.run Shuttle::CLI.new.run end
Public Instance Methods
default_options()
click to toggle source
# File lib/shuttle/cli.rb, line 44 def default_options { :path => nil, :target => 'production', :log => false } end
find_config()
click to toggle source
# File lib/shuttle/cli.rb, line 93 def find_config lookup_files.each { |path| break if try_config(path) } if @options[:path].nil? terminate("Please provide config with -f option.") end end
parse_command()
click to toggle source
# File lib/shuttle/cli.rb, line 79 def parse_command case ARGV.size when 0 terminate("Command required") when 1 @command = ARGV.shift when 2 @options[:target] = ARGV.shift @command = ARGV.shift else terminate("Maximum of 2 arguments allowed") end end
parse_options()
click to toggle source
# File lib/shuttle/cli.rb, line 52 def parse_options parser = OptionParser.new do |opts| opts.on('-v', '--version', 'Show version') do puts "Shuttle version #{Shuttle::VERSION}" exit 0 end opts.on('-e', '--environment NAME', 'Deployment target environment') do |v| @options[:target] = v end opts.on('-d', '--debug', 'Enable debugging') do @options[:log] = true end opts.on('-f', '--file PATH', 'Configuration file path') do |v| @options[:path] = v end end begin parser.parse! rescue OptionParser::ParseError => e terminate(e.message) end end
run()
click to toggle source
# File lib/shuttle/cli.rb, line 17 def run parse_options parse_command if @command == 'generate' begin generator = Shuttle::Generator.new.run rescue Exception => err terminate(err.message) end else find_config begin runner = Shuttle::Runner.new(@options) runner.execute(@command.dup) rescue Shuttle::ConfigError => err terminate(err.message) end end end
terminate(message, status=1)
click to toggle source
# File lib/shuttle/cli.rb, line 39 def terminate(message, status=1) STDERR.puts(message) exit(status) end
try_config(path)
click to toggle source
# File lib/shuttle/cli.rb, line 101 def try_config(path) if File.exists?(path) @options[:path] = path true else false end end
Private Instance Methods
lookup_files()
click to toggle source
# File lib/shuttle/cli.rb, line 112 def lookup_files [ options[:path], "#{@path}/shuttle.yml", "#{@path}/config/deploy.yml", "#{@path}/config/deploy/#{options[:target]}.yml", "#{ENV['HOME']}/.shuttle/#{File.basename(Dir.pwd)}.yml" ].compact end