tc-client 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/bin/tc-client CHANGED
@@ -2,16 +2,41 @@
2
2
 
3
3
  $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
4
4
  require 'tc-client'
5
+ require 'optparse'
5
6
 
6
- client = TCClient.new(false)
7
+ options = {}
8
+ OptionParser.new do |opts|
9
+ opts.banner = "Usage: tc-client <project name> <build name> [options]"
10
+
11
+ opts.on("-v", "--[no-]verbose", "Run verbosely") do |v|
12
+ options[:verbose] = v
13
+ end
14
+
15
+ opts.separator ""
16
+ opts.separator "Common tasks"
17
+ opts.on_tail("-h", "--help", "Show this message") do
18
+ puts opts
19
+ exit
20
+ end
21
+
22
+ opts.on_tail("--version", "Show version") do
23
+ require 'version'
24
+ puts "TCClient v#{TCClient::Version}"
25
+ exit
26
+ end
27
+ end.parse!
28
+
29
+ client = TCClient.new(options[:verbose])
7
30
 
8
31
  case ARGV.length
9
32
  when 1 then
10
- puts "Available builds on #{ARGV[0]}: "
11
- puts client.builds(ARGV[0]).map { |x| x[:name] }
33
+ builds = client.builds(ARGV[0])
34
+ puts "Available builds on #{builds[:project_name]}: "
35
+ puts builds[:builds].map { |x| x[:name] }
12
36
  when 2
13
- puts "Last 10 builds on #{ARGV[0]} [#{ARGV[1]}]: "
14
- client.statuses(ARGV[0], ARGV[1]).each do |x|
37
+ statuses = client.statuses(ARGV[0], ARGV[1])
38
+ puts "Last 10 builds on #{statuses[:project_name]} '#{statuses[:build_name]}': "
39
+ statuses[:statuses].each do |x|
15
40
  puts "#{x[:build]} (#{x[:status]})"
16
41
  end
17
42
  else
data/lib/tc-client.rb CHANGED
@@ -23,17 +23,20 @@ class TCClient
23
23
  end
24
24
 
25
25
  def builds(project)
26
- p = projects.select{|x| x[:name] == project}.first[:href]
27
- xml = get(p)
26
+ p = projects.select{|x| x[:name].match /#{project}/i }
27
+ return [{:name => "Can't find a project matching '#{project}'"}] if p.empty?
28
+ xml = get(p.first[:href])
28
29
  doc = REXML::Document.new xml
29
- doc.elements.collect("project/buildTypes/buildType") { |b| { :name => b.attributes["name"], :href => b.attributes["href"] } }
30
+ { :project_name => p.first[:name], :builds => doc.elements.collect("project/buildTypes/buildType") { |b| { :name => b.attributes["name"], :href => b.attributes["href"] } } }
30
31
  end
31
32
 
32
33
  def statuses(project, build)
33
- b = builds(project).select{|x| x[:name] == build}.first[:href]
34
- xml = get("#{b}/builds?count=10")
34
+ all = builds(project)
35
+ b = all[:builds].select{|x| x[:name].match /#{build}/i}
36
+ return [{:build => "Can't find a build matching: '#{build}'", :status => "FATAL"}] if b.empty?
37
+ xml = get("#{b.first[:href]}/builds?count=10")
35
38
  doc = REXML::Document.new xml
36
- doc.elements.collect("builds/build") {|x| { :build => x.attributes["number"], :status => x.attributes["status"] } }
39
+ { :project_name => all[:project_name], :build_name => b.first[:name], :statuses => doc.elements.collect("builds/build") {|x| { :build => x.attributes["number"], :status => x.attributes["status"] } } }
37
40
  end
38
41
 
39
42
  def get(what)
data/lib/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  class TCClient
2
- VERSION = "0.0.2"
2
+ Version = "0.0.3"
3
3
  end
data/tc-client.gemspec CHANGED
@@ -5,7 +5,7 @@ require "version"
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "tc-client"
8
- s.version = TCClient::VERSION
8
+ s.version = TCClient::Version
9
9
  s.platform = Gem::Platform::RUBY
10
10
  s.authors = ["Kristoffer Roupe"]
11
11
  s.email = ["kitofr@gmail.com"]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tc-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 27
4
+ hash: 25
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 2
10
- version: 0.0.2
9
+ - 3
10
+ version: 0.0.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Kristoffer Roupe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-03-21 00:00:00 +01:00
18
+ date: 2012-04-04 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency