Class: CLI
- Inherits:
-
Thor
- Object
- Thor
- CLI
- Defined in:
- lib/mothra/cli.rb
Instance Method Summary collapse
- #attach(bug_id, file_path) ⇒ Object
- #browse(bug_id) ⇒ Object
- #create(summary) ⇒ Object
- #get(bug_id) ⇒ Object
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
- #search(keyword, days_ago = 180) ⇒ Object
- #submit(summary, file_path) ⇒ Object
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
47 48 49 50 51 52 |
# File 'lib/mothra/cli.rb', line 47 def initialize(*args) super @config = YAML.load_file "#{Dir.home}/.mothra.yml" @config['BZ_URL'] = clean_bz_url(@config['BZ_URL']) @bz = Rodzilla::Resource::Bug.new(@config['BZ_URL'], @config['BZ_USER'], @config['BZ_PASSWD'], :json) end |
Instance Method Details
#attach(bug_id, file_path) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/mothra/cli.rb', line 135 def attach(bug_id, file_path) attach_id = _attach(bug_id, file_path) if not attach_id puts 'Fail to add attachments, please try again!'.yellow else print 'PR' print " [#{bug_id}] ".cyan print 'had add an attachment, ' puts " [#{attach_id}] ".yellow puts "#{@config['BZ_URL']}/show_bug.cgi?id=#{bug_id}".cyan end end |
#browse(bug_id) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/mothra/cli.rb', line 98 def browse(bug_id) if not is_numeric?bug_id puts 'No such bug id' exit end url = "#{@config['BZ_URL']}/show_bug.cgi?id=#{bug_id}" if RbConfig::CONFIG['host_os'] =~ /darwin/ system "open #{url}" elsif RbConfig::CONFIG['host_os'] =~ /linux|bsd/ if find_executable 'xdg-open' system "xdg-open #{url}" else puts 'You have no xdg-open command, please browse it manually!' puts url.cyan end else puts 'Could not open url at your platform, sorry.' end end |
#create(summary) ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/mothra/cli.rb', line 121 def create(summary) bug_id = _create(summary) if not bug_id puts 'Send-pr fail, please try again!'.yellow else print 'PR' print " [#{bug_id}] ".yellow puts "created!" puts "#{@config['BZ_URL']}/show_bug.cgi?id=#{bug_id}".cyan end end |
#get(bug_id) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/mothra/cli.rb', line 77 def get(bug_id) if not is_numeric?bug_id puts 'No such bug id' exit end ret = @bz.get(ids: bug_id) begin r = ret['bugs'][0] print "[#{r['id']}] ".yellow print "[#{r['status']}] ".cyan print "#{r['summary']} ".white puts "[#{r['last_change_time']}] ".light_black puts "#{@config['BZ_URL']}/show_bug.cgi?id=#{bug_id}".cyan rescue puts 'No such bug_id' end end |
#search(keyword, days_ago = 180) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mothra/cli.rb', line 55 def search(keyword, days_ago=180) search_days = DateTime.now - days_ago.to_i results = @bz.search(product: @config['PRODUCT'], component: @config['COMPONENT'], creation_time: search_days, status: @config['STATUS'], summary: keyword ) if not results['bugs'].empty? results['bugs'].each_with_index do |r, i| print "[#{r['id']}] ".yellow print "[#{r['status']}] ".cyan print "#{r['summary']} ".white puts "[#{r['last_change_time']}] ".light_black end else puts 'Not found.' end end |
#submit(summary, file_path) ⇒ Object
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
# File 'lib/mothra/cli.rb', line 150 def submit(summary, file_path) bug_id = _create(summary) if not bug_id puts 'Send-pr fail, please try again!'.yellow exit end attach_id = _attach(bug_id, file_path) if not attach_id puts 'Fail to add attachments, please upload attachment manually!'.yellow else print 'PR' print " [#{bug_id}] ".cyan print 'had add an attachment, ' puts " [#{attach_id}] ".yellow end puts "#{@config['BZ_URL']}/show_bug.cgi?id=#{bug_id}".cyan end |