Class: Hummer::Client::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/hummer/client/command.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Command



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/hummer/client/command.rb', line 8

def initialize(config = nil)
  @options = {
      :server => "http://0.0.0.0:3000"
  }
  if config
    config = File.expand_path(config)
    unless File.exist? config
      puts "Config file not found: #{config}"
      exit(1)
    end
    @options = YAML.load_file config if File.exist? config
  else
    config = File.expand_path("~/.hummer")
    @options = YAML.load_file config if File.exist? config
  end
  @options = Hash[@options.map{|a| [a.first.to_sym, a.last]}]

  parser = OptionParser.new do|opts|
    opts.banner = "Usage: hummer [options] [command]"
    opts.separator ""
    opts.separator "Specific commands: projects suites post"
    opts.separator ""
    opts.separator "Specific options:"
    opts.on('--help', 'Display help' ) do
      @options[:help] = true
    end
    opts.on('--user ID', 'User ID' ) do |id|
      @options[:user] = id
    end
    opts.on('--token ID', 'User token' ) do |id|
      @options[:token] = id
    end
    opts.on('--server URL', 'Server URL' ) do |url|
      @options[:server] = url
    end
    opts.on('--project ID', 'Project ID' ) do |id|
      @options[:project] = id
    end
    opts.on('--suite ID', 'Suite ID' ) do |id|
      @options[:suite] = id
    end
    opts.on('--json', 'Output in JSON format' ) do
      @options[:json] = true
    end
    opts.on('--file FILE', 'XML file with test results') do |file|
      @options[:file] = file
    end
  end
  begin
    parser.parse ARGV
    if @options[:help] or ARGV.empty?
      puts parser
      exit(0)
    end
  rescue => e
    puts e.message
  end
end

Instance Method Details

#runObject



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/hummer/client/command.rb', line 66

def run
  API.configure(@options)
  command = ARGV.first
  if "projects" == command
    @projects = API.get()
    if @projects.kind_of?(Hash) and @projects.has_key?("error")
      puts @projects["error"]
      exit(1)
    end
    if @options[:json]
      puts @projects.inspect
    else
      rows = []
      rows << ["ID","Name","Features","Owner"]
      rows << :separator
      @projects.each do |project|
        rows << [project["id"],project["name"],project["feature_list"].join(", "),project["owner_name"]]
      end
      table = Terminal::Table.new :rows => rows
      puts table
    end
  elsif "post" == command
    if @options[:project] and @options[:file]
      API.post(@options[:project], @options[:file], Readline.readline('Build: '), Readline.readline('Tags: '))
    else
      puts "Need project and file"
    end
  elsif "upload" == command
    if @options.has_key?(:project) and @options.has_key?(:file)
      @suite = API.post(@options[:project], @options[:file])
    else
      puts "Need project and file"
      exit(1)
    end

  elsif "suites" == command
    if @options.has_key?(:project)
      @suites = API.get(:project => @options[:project], :suite => nil)
      if @suites.kind_of?(Hash) and @suites.has_key?("error")
        puts @projects["error"]
        exit(1)
      end
      if @options[:json]
        puts @suites.inspect
      else
        rows = []
        rows << ["ID","Build","Tests","Errors","Failures","Skip","Passed","Features","Owner"]
        rows << :separator
        @suites.each do |suite|
          rows << [suite["id"],suite["build"],suite["total_tests"],suite["total_errors"],suite["total_failures"],suite["total_skip"],suite["total_passed"],suite["feature_list"].join(", "),suite["user_name"]]
        end
        table = Terminal::Table.new :rows => rows
        puts table
      end
    else
      puts "Need project"
      exit(1)
    end
  end
end