bl 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: aeee077cf059738c1ec061b1edfafd1334d2b45b
4
- data.tar.gz: c9ddb7d6fea0d12a3921a9086b4c0f49ba866b6e
3
+ metadata.gz: fc4154b13eadcea9ee471f9bd72e578d4050cbf5
4
+ data.tar.gz: ca2a158bd9ed0c124e580a7ae91d477c72216e0c
5
5
  SHA512:
6
- metadata.gz: d8bdc72960808ec076c6e98690cf49ebd77b7d11fd020e30b976bff4419a3052245d68d1f59c77b6c49bf005c7f7f059525c31fe5faf606aaee2f90fe310de31
7
- data.tar.gz: 4742a7482eea14dde49be3226febd11336db4feb9b58523cd418319ec251c3334913199b49c6629014cc072807d803e0d534369daa9a803c5f03dc15347a9069
6
+ metadata.gz: 36f3757ac201bb78263826ec67f00511e7c63762d64b193f5e8c5487f3c24470d22963778f7fa0e35bac526bd8c4878e737820b413bed73537a9b88d1ab04f01
7
+ data.tar.gz: 597304f8282502130a6a3dc6daedf8c9eb7d9387063cf5f260f5ac4221a5acd88691f46daf6de3bc199da6cd214ad5889e9e958bf3ddcd17ad0e0316005ccb06
data/bl.gemspec CHANGED
@@ -24,6 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_dependency 'thor', '~> 0.19.4'
25
25
  spec.add_dependency 'backlog_kit', '~> 0.15.0'
26
26
  spec.add_dependency 'paint', '~> 2.0'
27
+ spec.add_dependency 'hirb', '~> 0.7.3'
28
+ spec.add_dependency 'hirb-unicode', '~> 0.0.5'
29
+
27
30
  spec.add_development_dependency 'bundler', '~> 1.14.6'
28
31
  spec.add_development_dependency 'rake', '~> 12.0'
29
32
  spec.add_development_dependency 'minitest', '~> 5.10'
data/lib/bl.rb CHANGED
@@ -7,6 +7,7 @@ require 'bl/version'
7
7
  require 'bl/config'
8
8
  require 'bl/requestable'
9
9
  require 'bl/formatting'
10
+ require 'bl/command'
10
11
  require 'bl/space'
11
12
  require 'bl/type'
12
13
  require 'bl/category'
@@ -21,6 +22,7 @@ require 'bl/groups'
21
22
  require 'bl/webhooks'
22
23
  require 'bl/notifications'
23
24
  require 'bl/watchings'
25
+ require 'bl/formatter'
24
26
  require 'bl/cli'
25
27
 
26
28
  Bl::CLI.start(ARGV)
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class Category < Thor
3
- include Bl::Requestable
2
+ class Category < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -10,9 +9,8 @@ module Bl
10
9
 
11
10
  desc 'list', 'list categories'
12
11
  def list
13
- client.get(@url).body.each do |c|
14
- puts [c.id, c.name].join("\t")
15
- end
12
+ res = client.get(@url)
13
+ puts formatter.render(res.body, fields: %i(id name))
16
14
  end
17
15
 
18
16
  desc 'add [NAME...]', 'add categories'
@@ -1,8 +1,6 @@
1
1
  module Bl
2
2
 
3
- class CLI < Thor
4
- include Bl::Requestable
5
- include Bl::Formatting
3
+ class CLI < Command
6
4
 
7
5
  ISSUES_PARAMS = {
8
6
  projectId: :array,
@@ -111,7 +109,7 @@ module Bl
111
109
  desc 'search', 'search issues'
112
110
  options ISSUES_PARAMS
113
111
  def search
114
- client.get('issues', options.to_h).body.map {|i| print_issue(i)}
112
+ client.get('issues', delete_format(options.to_h)).body.map {|i| print_issue(i)}
115
113
  end
116
114
 
117
115
  desc 'show KEY', "show an issue's details"
@@ -159,7 +157,7 @@ module Bl
159
157
  issue_default_options = @config[:issue][:default]
160
158
  res = client.post(
161
159
  'issues',
162
- issue_default_options.merge({summary: s}).merge(options)
160
+ issue_default_options.merge({summary: s}).merge(delete_format(options.to_h))
163
161
  )
164
162
  puts "issue added: #{res.body.issueKey}\t#{res.body.summary}"
165
163
  end
@@ -170,7 +168,7 @@ module Bl
170
168
  option :comment, type: :string
171
169
  def update(*keys)
172
170
  keys.each do |k|
173
- res = client.patch("issues/#{k}", options.to_h)
171
+ res = client.patch("issues/#{k}", delete_format(options.to_h))
174
172
  puts "issue updated: #{res.body.issueKey}\t#{res.body.summary}"
175
173
  end
176
174
  end
@@ -203,23 +201,20 @@ module Bl
203
201
 
204
202
  desc 'statuses', 'list statuses'
205
203
  def statuses
206
- client.get('statuses').body.each do |s|
207
- puts [s.id, colorize_status(s.id, s.name)].join("\t")
208
- end
204
+ res = client.get('statuses')
205
+ puts formatter.render(res.body, fields: %i(id name))
209
206
  end
210
207
 
211
208
  desc 'priorities', 'list priorities'
212
209
  def priorities
213
- client.get('priorities').body.each do |p|
214
- puts [p.id, colorize_priority(p.id, p.name)].join("\t")
215
- end
210
+ res = client.get('priorities')
211
+ puts formatter.render(res.body, fields: %i(id name))
216
212
  end
217
213
 
218
214
  desc 'resolutions', 'list resolutions'
219
215
  def resolutions
220
- client.get('resolutions').body.each do |r|
221
- puts [r.id, r.name].join("\t")
222
- end
216
+ res = client.get('resolutions')
217
+ puts formatter.render(res.body, fields: %i(id name))
223
218
  end
224
219
 
225
220
  desc 'doctor', 'check issues'
@@ -283,5 +278,12 @@ module Bl
283
278
 
284
279
  desc 'watchings SUBCOMMAND ...ARGS', ''
285
280
  subcommand 'watchings', Watchings
281
+
282
+ private
283
+
284
+ def delete_format(h)
285
+ h.delete('format')
286
+ h
287
+ end
286
288
  end
287
289
  end
@@ -0,0 +1,7 @@
1
+ module Bl
2
+ class Command < Thor
3
+ include Bl::Requestable
4
+ include Bl::Formatting
5
+ class_option :format, type: :string, default: 'table', desc: 'set output format'
6
+ end
7
+ end
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class File < Thor
3
- include Bl::Requestable
2
+ class File < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -9,9 +8,8 @@ module Bl
9
8
 
10
9
  desc 'list PATH', 'list files on PATH'
11
10
  def list(path='')
12
- client.get("projects/#{@config[:project_key]}/files/metadata/#{path}").body.each do |f|
13
- puts [f.id, f.type, f.dir, f.name, f.size, f.created, f.updated].join("\t")
14
- end
11
+ res = client.get("projects/#{@config[:project_key]}/files/metadata/#{path}")
12
+ puts formatter.render(res.body, fields: %i(id type dir name size created updated))
15
13
  end
16
14
 
17
15
  desc 'get [ID...]', 'get files'
@@ -0,0 +1,39 @@
1
+ require 'hirb'
2
+ require 'hirb-unicode'
3
+ require 'json'
4
+
5
+ module Bl
6
+ class Formatter
7
+ def initialize(format: 'table')
8
+ @format = case format
9
+ when 'table'
10
+ Format::Hirb
11
+ when 'json'
12
+ Format::Json
13
+ else
14
+ abort 'format must be set to \'table\' or \'json\''
15
+ end
16
+ end
17
+
18
+ def render(*args)
19
+ @format.render(*args)
20
+ end
21
+
22
+ module Format
23
+ class Hirb < Hirb::Helpers::AutoTable
24
+ end
25
+
26
+ class Json
27
+ def self.render(objects, fields: [])
28
+ result = []
29
+ objects.each do |obj|
30
+ h = {}
31
+ fields.map { |f| h.store(f, obj.send(f)) }
32
+ result << h
33
+ end
34
+ result.to_json
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class GitRepo < Thor
3
- include Bl::Requestable
2
+ class GitRepo < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -10,15 +9,8 @@ module Bl
10
9
 
11
10
  desc 'list', 'list git repositories'
12
11
  def list
13
- client.get(@url).body.each do |repo|
14
- puts [
15
- repo.id,
16
- repo.projectId,
17
- repo.name,
18
- repo.description,
19
- repo.sshUrl
20
- ].join("\t")
21
- end
12
+ res = client.get(@url)
13
+ puts formatter.render(res.body, fields: %i(id projectId name description sshUrl))
22
14
  end
23
15
 
24
16
  desc 'show ID', 'show a git repository'
@@ -1,7 +1,5 @@
1
1
  module Bl
2
- class Groups < Thor
3
- include Bl::Requestable
4
- include Bl::Formatting
2
+ class Groups < Command
5
3
 
6
4
  def initialize(*)
7
5
  @config = Bl::Config.instance
@@ -13,13 +11,13 @@ module Bl
13
11
  options order: :string, offset: :numeric, count: :numeric
14
12
  def list
15
13
  res = client.get(@url, options.to_h)
16
- res.body.map { |g| print_group(g) }
14
+ puts formatter.render(res.body, fields: %i(id name))
17
15
  end
18
16
 
19
17
  desc 'show GROUP_ID', ''
20
18
  def show(id)
21
19
  res = client.get("#{@url}/#{id}")
22
- print_group_and_members(res.body)
20
+ puts formatter.render(res.body.members, fields: %i(id userId name roleType lang mailAddress))
23
21
  end
24
22
 
25
23
  desc 'add GROUP_NAME', ''
@@ -1,6 +1,11 @@
1
1
  module Bl
2
- class Milestone < Thor
3
- include Bl::Requestable
2
+ class Milestone < Command
3
+
4
+ MILESTONE_PARAMS = {
5
+ description: :string,
6
+ startDate: :string,
7
+ releaseDueDate: :string
8
+ }
4
9
 
5
10
  def initialize(*)
6
11
  @config = Bl::Config.instance
@@ -10,23 +15,12 @@ module Bl
10
15
 
11
16
  desc 'list', 'list milestones'
12
17
  def list
13
- client.get(@url).body.each do |v|
14
- puts [
15
- v.id,
16
- v.projectId,
17
- v.name,
18
- v.description,
19
- v.startDate,
20
- v.releaseDueDate,
21
- v.archived
22
- ].join("\t")
23
- end
18
+ res = client.get(@url)
19
+ puts formatter.render(res.body, fields: %i(id projectId name description startDate releaseDueDate archived))
24
20
  end
25
21
 
26
22
  desc 'add [NAME...]', 'add milestones'
27
- option :description, type: :string
28
- option :startDate, type: :string
29
- option :releaseDate, type: :string
23
+ options MILESTONE_PARAMS
30
24
  def add(*names)
31
25
  names.each do |name|
32
26
  res = client.post(
@@ -34,7 +28,7 @@ module Bl
34
28
  name: name,
35
29
  description: options[:description],
36
30
  startDate: options[:startDate],
37
- releaseDate: options[:releaseDate]
31
+ releaseDueDate: options[:releaseDueDate]
38
32
  )
39
33
  puts "milestone added: #{res.body.id}\t#{res.body.name}"
40
34
  end
@@ -42,9 +36,7 @@ module Bl
42
36
 
43
37
  desc 'update [ID...]', 'update milestones'
44
38
  option :name, type: :string
45
- option :description, type: :string
46
- option :startDate, type: :string
47
- option :releaseDate, type: :string
39
+ options MILESTONE_PARAMS
48
40
  def update(*ids)
49
41
  ids.each do |id|
50
42
  res = client.patch("#{@url}/#{id}", options)
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class Notifications < Thor
3
- include Bl::Requestable
2
+ class Notifications < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class Project < Thor
3
- include Bl::Requestable
2
+ class Project < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -10,9 +9,8 @@ module Bl
10
9
 
11
10
  desc 'list', 'list projects'
12
11
  def list
13
- client.get(@url).body.each do |p|
14
- puts [p.id, p.projectKey, p.name].join("\t")
15
- end
12
+ res = client.get(@url)
13
+ puts formatter.render(res.body, fields: %i(id projectKey name))
16
14
  end
17
15
 
18
16
  desc 'status ID', 'show project status'
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class Recent < Thor
3
- include Bl::Requestable
2
+ class Recent < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -8,5 +8,9 @@ module Bl
8
8
  api_key: @config[:api_key]
9
9
  )
10
10
  end
11
+
12
+ def formatter
13
+ @formatter ||= Formatter.new(format: options[:format])
14
+ end
11
15
  end
12
16
  end
@@ -1,7 +1,5 @@
1
1
  module Bl
2
- class Space < Thor
3
- include Bl::Requestable
4
- include Bl::Formatting
2
+ class Space < Command
5
3
 
6
4
  def initialize(*)
7
5
  @config = Bl::Config.instance
@@ -1,7 +1,5 @@
1
1
  module Bl
2
- class Type < Thor
3
- include Bl::Requestable
4
- include Bl::Formatting
2
+ class Type < Command
5
3
 
6
4
  def initialize(*)
7
5
  @config = Bl::Config.instance
@@ -11,9 +9,8 @@ module Bl
11
9
 
12
10
  desc 'list', 'list issue types'
13
11
  def list
14
- client.get(@url).body.each do |t|
15
- puts [t.id, colorize_type(t.name, t.color), t.color].join("\t")
16
- end
12
+ res = client.get(@url)
13
+ puts formatter.render(res.body, fields: %i(id name color))
17
14
  end
18
15
 
19
16
  desc 'add [NAME...]', 'add types'
@@ -1,7 +1,5 @@
1
1
  module Bl
2
- class Users < Thor
3
- include Bl::Requestable
4
- include Bl::Formatting
2
+ class Users < Command
5
3
 
6
4
  def initialize(*)
7
5
  @config = Bl::Config.instance
@@ -11,7 +9,8 @@ module Bl
11
9
 
12
10
  desc 'list', 'list users'
13
11
  def list
14
- client.get('users').body.map { |u| print_user(u) }
12
+ res = client.get('users')
13
+ puts formatter.render(res.body, fields: %i(id userId name roleType lang mailAddress))
15
14
  end
16
15
 
17
16
  desc 'show USER_ID', ''
@@ -1,3 +1,3 @@
1
1
  module Bl
2
- VERSION = '0.4.2'.freeze
2
+ VERSION = '0.5.0'.freeze
3
3
  end
@@ -1,7 +1,5 @@
1
1
  module Bl
2
- class Watchings < Thor
3
- include Bl::Requestable
4
- include Bl::Formatting
2
+ class Watchings < Command
5
3
 
6
4
  WATCHINGS_PARAMS = {
7
5
  order: :string,
@@ -21,7 +19,7 @@ module Bl
21
19
  desc 'list USER_ID', ''
22
20
  options WATCHINGS_PARAMS
23
21
  def list(id)
24
- res = client.get("/users/#{id}/#{@url}", options.to_h)
22
+ res = client.get("/users/#{id}/#{@url}", delete_format(options.to_h))
25
23
  res.body.map { |t| print_watch_target(t) }
26
24
  end
27
25
 
@@ -73,5 +71,12 @@ module Bl
73
71
  res = client.post("/users/#{id}/watchings/markAsChecked")
74
72
  puts 'watch mark as checked'
75
73
  end
74
+
75
+ private
76
+
77
+ def delete_format(h)
78
+ h.delete('format')
79
+ h
80
+ end
76
81
  end
77
82
  end
@@ -1,7 +1,5 @@
1
1
  module Bl
2
- class Webhooks < Thor
3
- include Bl::Requestable
4
- include Bl::Formatting
2
+ class Webhooks < Command
5
3
 
6
4
  WEBHOOK_PARAMS = {
7
5
  name: :string,
@@ -20,7 +18,7 @@ module Bl
20
18
  desc 'list', ''
21
19
  def list
22
20
  res = client.get(@url)
23
- res.body.map { |w| print_webhook(w) }
21
+ puts formatter.render(res.body, fields: %i(id name description hookUrl))
24
22
  end
25
23
 
26
24
  desc 'show WEBHOOK_ID', ''
@@ -1,6 +1,5 @@
1
1
  module Bl
2
- class Wiki < Thor
3
- include Bl::Requestable
2
+ class Wiki < Command
4
3
 
5
4
  def initialize(*)
6
5
  @config = Bl::Config.instance
@@ -10,9 +9,8 @@ module Bl
10
9
 
11
10
  desc 'list', 'list wikis'
12
11
  def list
13
- client.get(@url, projectIdOrKey: @config[:project_key]).body.each do |w|
14
- puts [w.id, w.projectId, w.name, w.updated].join("\t")
15
- end
12
+ res = client.get(@url, projectIdOrKey: @config[:project_key])
13
+ puts formatter.render(res.body, fields: %i(id projectId name updated))
16
14
  end
17
15
 
18
16
  desc 'show ID', "show a wiki's content"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - saki
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-04-08 00:00:00.000000000 Z
11
+ date: 2017-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -52,6 +52,34 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: hirb
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.7.3
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.7.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: hirb-unicode
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.5
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.5
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: bundler
57
85
  requirement: !ruby/object:Gem::Requirement
@@ -143,8 +171,10 @@ files:
143
171
  - lib/bl.rb
144
172
  - lib/bl/category.rb
145
173
  - lib/bl/cli.rb
174
+ - lib/bl/command.rb
146
175
  - lib/bl/config.rb
147
176
  - lib/bl/file.rb
177
+ - lib/bl/formatter.rb
148
178
  - lib/bl/formatting.rb
149
179
  - lib/bl/gitrepo.rb
150
180
  - lib/bl/groups.rb