Class: DPL::CLI
- Inherits:
-
Object
- Object
- DPL::CLI
- Defined in:
- lib/dpl/cli.rb
Constant Summary collapse
- OPTION_PATTERN =
/\A--([a-z][a-z_\-]*)(?:=(.+))?\z/
Instance Attribute Summary collapse
-
#fold_count ⇒ Object
Returns the value of attribute fold_count.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #default_options ⇒ Object
- #die(message) ⇒ Object
- #env ⇒ Object
- #fold(message) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
- #shell(command) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/dpl/cli.rb', line 13 def initialize(*args) = {} args.flatten.each do |arg| next .update(arg) if arg.is_a? Hash die("invalid option %p" % arg) unless match = OPTION_PATTERN.match(arg) key = match[1].tr('-', '_').to_sym if .include? key [key] = Array([key]) << match[2] else [key] = match[2] || true end end self.fold_count = 0 self. = .merge() end |
Instance Attribute Details
#fold_count ⇒ Object
Returns the value of attribute fold_count.
11 12 13 |
# File 'lib/dpl/cli.rb', line 11 def fold_count @fold_count end |
#options ⇒ Object
Returns the value of attribute options.
11 12 13 |
# File 'lib/dpl/cli.rb', line 11 def @options end |
Class Method Details
.run(*args) ⇒ Object
6 7 8 |
# File 'lib/dpl/cli.rb', line 6 def self.run(*args) new(args).run end |
Instance Method Details
#default_options ⇒ Object
46 47 48 49 50 51 |
# File 'lib/dpl/cli.rb', line 46 def { :app => File.basename(Dir.pwd), :key_name => %x[hostname].strip } end |
#die(message) ⇒ Object
57 58 59 60 |
# File 'lib/dpl/cli.rb', line 57 def die() $stderr.puts() exit 1 end |
#env ⇒ Object
62 63 64 |
# File 'lib/dpl/cli.rb', line 62 def env ENV end |
#fold(message) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'lib/dpl/cli.rb', line 37 def fold() self.fold_count += 1 print "travis_fold:start:dpl.#{fold_count}\r" if [:fold] puts "\e[33m#{}\e[0m" yield ensure print "\ntravis_fold:end:dpl.#{fold_count}\r" if [:fold] end |
#run ⇒ Object
30 31 32 33 34 35 |
# File 'lib/dpl/cli.rb', line 30 def run provider = Provider.new(self, ) provider.deploy rescue Error => error [:debug] ? raise(error) : die(error.) end |
#shell(command) ⇒ Object
53 54 55 |
# File 'lib/dpl/cli.rb', line 53 def shell(command) system(command) end |