Class: Hummer::Client::Command
- Inherits:
-
Object
- Object
- Hummer::Client::Command
- Includes:
- Model
- Defined in:
- lib/hummer/client/command.rb
Instance Method Summary collapse
- #display(objects, titles) ⇒ Object
-
#initialize(config = nil) ⇒ Command
constructor
A new instance of Command.
- #run ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Command
Returns a new instance of Command.
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 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/hummer/client/command.rb', line 11 def initialize(config = nil) @options = { :server => "http://0.0.0.0:3000", :user => "00000000-0000-0000-0000-000000000000", :token => "" } if config config = File.(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.("~/.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. = "Usage: hummer [options] [command]" opts.separator "" opts.separator "Commands: projects suites features 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('--features NAMEs', 'Feature name, separeted by \',\'' ) do |features| @options[:features] = features end opts.on('--build name', 'Build for new post' ) do |build| @options[:build] = build 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 opts.on('--version', 'Display version') do @options[:version] = true end end begin parser.parse ARGV if @options[:version] puts "Version: #{Hummer::Client::VERSION}" exit(0) end if @options[:help] or ARGV.empty? puts parser exit(0) end rescue => e puts e. end end |
Instance Method Details
#display(objects, titles) ⇒ Object
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/hummer/client/command.rb', line 84 def display(objects, titles) objects = objects.kind_of?(Array) ? objects : objects.to_a rows = [] rows << titles.collect{|_,title| title } rows << :separator objects.each do |object| values = [] titles.collect{|key,_| key}.each do |attribute| value = object.send(attribute) if value.kind_of?(Array) values << value.join(", ") else values << value end end rows << values end puts Terminal::Table.new :rows => rows end |
#run ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/hummer/client/command.rb', line 103 def run Base.configure(@options) command = ARGV.first case command when "features" then display Feature.all, [[:id,"ID"],[:name, "Name"]] when "projects" then display Project.all, [[:id,"ID"],[:name,"Name"],[:feature_list,"Features"],[:owner_name,"Owner"]] when "suites" then if @options[:project] project = Project.find(@options[:project]) suites = project.suites else suites = Suite.all end display suites, [[:id,"ID"],[:build,"Build"],[:feature_list,"Features"],[:user_name,"User"],[:total_tests, "Tests"],[:total_errors, "Errors"],[:total_failures, "Failures"],[:total_skip,"Skip"],[:total_passed,"Passed"]] when "post" then project = @options[:project] unless project project = Readline.readline('Project> ') project = Project.find(project.strip) end build = @options[:build] unless build build = Readline.readline('Build> ') end features = @options[:features] unless features puts "Already exists features: #{Feature.all.collect{|f| f.name}.join(", ")}" puts "Default features: #{project.feature_list.join(", ")}" features = Readline.readline('Features> ') end file = @options[:file] unless file file = Readline.readline('File> ') end Suite.save(project.id, build, features, file) else puts "Unknown command: #{command}" exit(1) end end |