Class: Shuttle::CLI
- Inherits:
-
Object
- Object
- Shuttle::CLI
- Defined in:
- lib/shuttle/cli.rb
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #default_options ⇒ Object
- #find_config ⇒ Object
-
#initialize(path = nil) ⇒ CLI
constructor
A new instance of CLI.
- #parse_command ⇒ Object
- #parse_options ⇒ Object
- #run ⇒ Object
- #terminate(message, status = 1) ⇒ Object
- #try_config(path) ⇒ Object
Constructor Details
#initialize(path = nil) ⇒ CLI
Returns a new instance of CLI.
12 13 14 15 |
# File 'lib/shuttle/cli.rb', line 12 def initialize(path=nil) @path = File.(path || Dir.pwd) @options = end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
5 6 7 |
# File 'lib/shuttle/cli.rb', line 5 def command @command end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
5 6 7 |
# File 'lib/shuttle/cli.rb', line 5 def @options end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
6 7 8 |
# File 'lib/shuttle/cli.rb', line 6 def path @path end |
Class Method Details
Instance Method Details
#default_options ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/shuttle/cli.rb', line 44 def { :path => nil, :target => 'production', :log => false } end |
#find_config ⇒ Object
93 94 95 96 97 98 99 |
# 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 ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# 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 ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/shuttle/cli.rb', line 52 def 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.) end end |
#run ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/shuttle/cli.rb', line 17 def run parse_command if @command == 'generate' begin generator = Shuttle::Generator.new.run rescue Exception => err terminate(err.) end else find_config begin runner = Shuttle::Runner.new(@options) runner.execute(@command.dup) rescue Shuttle::ConfigError => err terminate(err.) end end end |
#terminate(message, status = 1) ⇒ Object
39 40 41 42 |
# File 'lib/shuttle/cli.rb', line 39 def terminate(, status=1) STDERR.puts() exit(status) end |
#try_config(path) ⇒ Object
101 102 103 104 105 106 107 108 |
# File 'lib/shuttle/cli.rb', line 101 def try_config(path) if File.exists?(path) @options[:path] = path true else false end end |