Class: CruiseStatus::Command
- Inherits:
-
Object
- Object
- CruiseStatus::Command
- Defined in:
- lib/cruisestatus/command.rb
Constant Summary collapse
- USAGE =
<<-EOS Usage: #{File.basename($0)} [options] BUILD_URL Reads the feed at BUILD_URL and reports if the build[s] passed. Examples: # CruiseControl.rb: #{File.basename($0)} http://my.cruiseserver.com #{File.basename($0)} http://my.cruiseserver.com/projects.rss #{File.basename($0)} http://my.cruiseserver.com/projects/myproject.rss # RunCodeRun.com: #{File.basename($0)} http://runcoderun.com/api/v1/json/myusername Options: EOS
- DEFAULT_PROMPT =
"Are you <%= color 'sure', :underline %> you want to check in? (y/n): "
Instance Attribute Summary collapse
Class Method Summary collapse
Instance Method Summary collapse
- #are_you_sure?(status) ⇒ Boolean
-
#initialize ⇒ Command
constructor
A new instance of Command.
- #parse_options(argv) ⇒ Object
- #run(argv) ⇒ Object
Constructor Details
#initialize ⇒ Command
Returns a new instance of Command.
37 38 39 |
# File 'lib/cruisestatus/command.rb', line 37 def initialize() @prompt = false end |
Instance Attribute Details
#prompt ⇒ Object
84 85 86 |
# File 'lib/cruisestatus/command.rb', line 84 def prompt @prompt || DEFAULT_PROMPT end |
Class Method Details
.run!(argv) ⇒ Object
29 30 31 |
# File 'lib/cruisestatus/command.rb', line 29 def self.run!( argv ) self.new.run( argv ) end |
Instance Method Details
#are_you_sure?(status) ⇒ Boolean
33 34 35 |
# File 'lib/cruisestatus/command.rb', line 33 def are_you_sure?( status ) agree( prompt ) ? 0 : 1 end |
#parse_options(argv) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/cruisestatus/command.rb', line 61 def ( argv ) @options = OptionParser.new do |option| option.version = CruiseStatus::Version::STRING option.release = CruiseStatus::Version::RELEASE option. = CruiseStatus::Command::USAGE option.on( "-p", "--prompt", "=[PROMPT]", "Prompt the user if the build has failed.", "#{File.basename($0)} will exit with a non-zero status if the user " \ "does not respond 'y' to the prompt." ) do |val| if val == true self.prompt = DEFAULT_PROMPT else self.prompt = val end end end @options.parse! argv end |
#run(argv) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/cruisestatus/command.rb', line 41 def run( argv ) argv = ( argv ) return Kernel.abort( @options.to_s ) if argv.empty? status = CruiseStatus.new argv.last if status.pass? say "Build <%= color 'PASSED', :green, :bold %>" 0 else say "Build <%= color 'FAILURES', :red, :bold %>:" status.failures.each do |failure| say " * " + $terminal.color( failure, :red ) end return are_you_sure?( status ) if @prompt 1 end end |