github_cli 0.3.1 → 0.4.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.
Files changed (56) hide show
  1. data/CHANGELOG.md +21 -0
  2. data/Gemfile.lock +20 -22
  3. data/README.md +29 -4
  4. data/bin/ghc +1 -1
  5. data/features/download.feature +11 -0
  6. data/features/email.feature +9 -0
  7. data/features/errors.feature +10 -0
  8. data/features/event.feature +14 -0
  9. data/features/executable.feature +44 -17
  10. data/features/follower.feature +11 -0
  11. data/features/fork.feature +13 -0
  12. data/features/hook.feature +12 -0
  13. data/features/label.feature +16 -0
  14. data/features/member.feature +18 -0
  15. data/features/milestone.feature +11 -0
  16. data/features/organization.feature +9 -0
  17. data/features/reference.feature +11 -0
  18. data/features/repositories.feature +16 -7
  19. data/features/tag.feature +8 -0
  20. data/features/team.feature +18 -0
  21. data/features/tree.feature +8 -0
  22. data/features/user.feature +8 -0
  23. data/ghc_logo.png +0 -0
  24. data/github_cli.gemspec +2 -2
  25. data/lib/github_cli/api.rb +14 -11
  26. data/lib/github_cli/apis/follower.rb +40 -0
  27. data/lib/github_cli/apis/member.rb +52 -0
  28. data/lib/github_cli/apis/organization.rb +28 -0
  29. data/lib/github_cli/apis/team.rb +89 -0
  30. data/lib/github_cli/apis/user.rb +22 -0
  31. data/lib/github_cli/apis.rb +5 -0
  32. data/lib/github_cli/cli.rb +11 -4
  33. data/lib/github_cli/command.rb +40 -28
  34. data/lib/github_cli/commands/followers.rb +50 -0
  35. data/lib/github_cli/commands/members.rb +70 -0
  36. data/lib/github_cli/commands/organizations.rb +42 -0
  37. data/lib/github_cli/commands/teams.rb +148 -0
  38. data/lib/github_cli/commands/users.rb +26 -0
  39. data/lib/github_cli/commands.rb +5 -0
  40. data/lib/github_cli/editor.rb +27 -0
  41. data/lib/github_cli/errors.rb +6 -1
  42. data/lib/github_cli/formatter.rb +47 -0
  43. data/lib/github_cli/formatters/csv.rb +8 -8
  44. data/lib/github_cli/formatters/table.rb +237 -11
  45. data/lib/github_cli/pager.rb +66 -0
  46. data/lib/github_cli/subcommands.rb +15 -0
  47. data/lib/github_cli/system.rb +33 -0
  48. data/lib/github_cli/terminal.rb +60 -30
  49. data/lib/github_cli/thor_ext.rb +15 -0
  50. data/lib/github_cli/ui.rb +8 -0
  51. data/lib/github_cli/util.rb +55 -12
  52. data/lib/github_cli/version.rb +1 -1
  53. data/lib/github_cli.rb +3 -0
  54. data/spec/github_cli/pager_spec.rb +69 -0
  55. data/spec/github_cli/util_spec.rb +14 -4
  56. metadata +64 -14
data/lib/github_cli/ui.rb CHANGED
@@ -35,5 +35,13 @@ module GithubCLI
35
35
  def print_table(table, options={})
36
36
  @shell.print_table table, options
37
37
  end
38
+
39
+ def print_wrapped(message, options={})
40
+ @shell.print_wrapped message, options
41
+ end
42
+
43
+ def terminal_width
44
+ @shell.terminal_width
45
+ end
38
46
  end # UI
39
47
  end # GithubCLI
@@ -1,13 +1,16 @@
1
+ # encoding: utf-8
2
+
1
3
  module GithubCLI
2
4
  module Util
3
5
  extend self
4
6
 
5
- def flatten_hash(prefix=nil, hash, new_hash)
7
+ def flatten_hash(prefix=nil, hash)
8
+ new_hash ||= {}
6
9
  hash.each do |key, val|
7
10
  key = prefix ? :"#{prefix}_#{key}" : key
8
11
  case val
9
12
  when Hash
10
- flatten_hash(key, val, new_hash)
13
+ new_hash.update flatten_hash(key, val)
11
14
  else
12
15
  new_hash[key] = val
13
16
  end
@@ -19,17 +22,57 @@ module GithubCLI
19
22
  values_copy = values.dup
20
23
  collected = []
21
24
  values_copy.inject([]) do |collected, val|
22
- collected << case val
23
- when true
24
- "true"
25
- when false
26
- "false"
27
- when Hash
28
- self.convert_values(val.values)
29
- else
30
- val.to_s
31
- end
25
+ collected << convert_value(val)
26
+ end
27
+ end
28
+
29
+ def convert_value(value)
30
+ case value
31
+ when true then "true"
32
+ when false then "false"
33
+ when Hash then convert_value(value.values)
34
+ when Array then value.map(&:to_s)
35
+ else value.to_s
36
+ end
37
+ end
38
+
39
+ # Shortens string
40
+ # :trailing - trailing character in place of cutout string
41
+ def truncate(string, width, options={})
42
+ trailing = options[:trailing] || '…'
43
+
44
+ chars = string.to_s.chars.to_a
45
+ if chars.length < width && chars.length > 3
46
+ chars.join
47
+ elsif chars.length > 3
48
+ (chars[0, width - trailing.length].join) + trailing
49
+ end
50
+ end
51
+
52
+ # Pads a string
53
+ # padder - padding character
54
+ # align - align :left, :right, :center
55
+ def pad(string, width, options={})
56
+ supported = [:left, :right, :center]
57
+ padder = options[:padder] || ' '
58
+ align = options[:align] || :left
59
+
60
+ chars = string.to_s.chars.to_a
61
+ if chars.length < width
62
+ string = case :"#{align}"
63
+ when :left
64
+ string + (padder * (width - chars.length))
65
+ when :right
66
+ (padder * (width - chars.length)) + string
67
+ when :center
68
+ right = ((pad_length = width - chars.length).to_f / 2).ceil
69
+ left = pad_length - right
70
+ (padder * left) + string + (padder * right)
71
+ else
72
+ raise ArgumentError, "Alignment must be one of: #{supported.join(' ')}"
73
+ end
32
74
  end
75
+ string
33
76
  end
34
77
  end
35
78
  end # GithubCLI
@@ -1,3 +1,3 @@
1
1
  module GithubCLI
2
- VERSION = "0.3.1"
2
+ VERSION = "0.4.0"
3
3
  end
data/lib/github_cli.rb CHANGED
@@ -16,8 +16,11 @@ module GithubCLI
16
16
  autoload :Command, 'github_cli/command'
17
17
  autoload :API, 'github_cli/api'
18
18
  autoload :Terminal, 'github_cli/terminal'
19
+ autoload :System, 'github_cli/system'
20
+ autoload :Pager, 'github_cli/pager'
19
21
  autoload :Commands, 'github_cli/commands'
20
22
  autoload :Helpers, 'github_cli/helpers'
23
+ autoload :Formatter, 'github_cli/formatter'
21
24
  autoload :Formatters,'github_cli/formatters'
22
25
  autoload :UI, 'github_cli/ui'
23
26
  autoload :Util, 'github_cli/util'
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ describe GithubCLI::Pager do
4
+
5
+ context '#pager_command' do
6
+ it 'chooses default pagers if none present' do
7
+ GithubCLI::System.stub(:command?) { true }
8
+ described_class.pager_command.to_s.should =~ /less/
9
+ end
10
+
11
+ it 'permits custom commands' do
12
+ cmd = 'mine'
13
+ GithubCLI::System.stub(:command?) { true }
14
+ described_class.pager_command(cmd).should == cmd
15
+ end
16
+ end
17
+
18
+ context '#page' do
19
+ let(:read_io) { stub(:read_io).as_null_object }
20
+ let(:write_io) { stub(:write_io).as_null_object }
21
+ let(:pager) { described_class.new }
22
+
23
+ before do
24
+ $stdout.stub(:tty?).and_return true
25
+ IO.stub(:pipe).and_return [read_io, write_io]
26
+ end
27
+
28
+ context 'child process' do
29
+ before { Kernel.stub(:fork) { false } }
30
+
31
+ it 'pipes to standard output' do
32
+ Kernel.stub(:fork) { false}
33
+ $stdout.should_receive(:reopen).with(write_io)
34
+ $stderr.should_receive(:reopen).with(write_io)
35
+ pager.page
36
+ end
37
+
38
+ it 'closes pipe' do
39
+ $stdout.stub(:reopen)
40
+ $stderr.stub(:reopen)
41
+ write_io.should_receive(:close)
42
+ read_io.should_receive(:close)
43
+ pager.page
44
+ end
45
+ end
46
+
47
+ context 'parent process' do
48
+ before do
49
+ Kernel.stub(:fork) { true }
50
+ Kernel.stub(:select)
51
+ described_class.stub(:pager_command) { 'less' }
52
+ Kernel.stub(:exec)
53
+ end
54
+
55
+ it 'reads from standard output' do
56
+ $stdin.should_receive(:reopen).with(read_io)
57
+ pager.page
58
+ end
59
+
60
+ it 'closes pipe' do
61
+ $stdin.stub(:reopen)
62
+ write_io.should_receive(:close)
63
+ read_io.should_receive(:close)
64
+ pager.page
65
+ end
66
+ end
67
+ end
68
+
69
+ end # GithubCLI::Pager
@@ -6,14 +6,12 @@ describe GithubCLI::Util do
6
6
 
7
7
  it 'preserves original hash' do
8
8
  hash = { :a => 1, :b => 2 }
9
- output = {}
10
- subject.flatten_hash hash, output
9
+ output = subject.flatten_hash hash
11
10
  output.should == hash
12
11
  end
13
12
 
14
13
  it "reduces multidimensional keys to one dimension" do
15
- output = {}
16
- subject.flatten_hash hash, output
14
+ output = subject.flatten_hash hash
17
15
  output.should == { :a_b_c => 1 }
18
16
  end
19
17
  end
@@ -34,4 +32,16 @@ describe GithubCLI::Util do
34
32
  subject.convert_values(values).should include 'string'
35
33
  end
36
34
  end
35
+
36
+ describe "#convert_value" do
37
+ it 'converts arrays to arrays of strings' do
38
+ values = [:bar, 123, 3.14]
39
+ subject.convert_value(values).should eq(["bar", "123", "3.14"])
40
+ end
41
+
42
+ it 'converts hash values to strings' do
43
+ values = {:foo => 123, :bar => :baz, :buz => 2.3}
44
+ subject.convert_value(values).should eq(["123", "baz", "2.3"])
45
+ end
46
+ end
37
47
  end # GithubCLI::Util
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,22 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-30 00:00:00.000000000Z
12
+ date: 2012-06-15 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_api
16
- requirement: &2160356360 !ruby/object:Gem::Requirement
16
+ requirement: &2160543980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: '0.5'
21
+ version: '0.6'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2160356360
24
+ version_requirements: *2160543980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &2160355220 !ruby/object:Gem::Requirement
27
+ requirement: &2160543340 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *2160355220
35
+ version_requirements: *2160543340
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2160354060 !ruby/object:Gem::Requirement
38
+ requirement: &2160542820 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160354060
46
+ version_requirements: *2160542820
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: aruba
49
- requirement: &2160353500 !ruby/object:Gem::Requirement
49
+ requirement: &2160542400 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160353500
57
+ version_requirements: *2160542400
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &2160352620 !ruby/object:Gem::Requirement
60
+ requirement: &2160541940 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2160352620
68
+ version_requirements: *2160541940
69
69
  description: CLI-based access to GitHub API v3
70
70
  email:
71
71
  - pmurach@gmail.com
@@ -85,14 +85,31 @@ files:
85
85
  - README.md
86
86
  - Rakefile
87
87
  - bin/ghc
88
+ - features/download.feature
89
+ - features/email.feature
90
+ - features/errors.feature
91
+ - features/event.feature
88
92
  - features/executable.feature
93
+ - features/follower.feature
94
+ - features/fork.feature
95
+ - features/hook.feature
96
+ - features/label.feature
97
+ - features/member.feature
98
+ - features/milestone.feature
99
+ - features/organization.feature
100
+ - features/reference.feature
89
101
  - features/repositories.feature
90
102
  - features/search.feature
91
103
  - features/settings.feature
92
104
  - features/support/env.rb
93
105
  - features/support/hooks.rb
106
+ - features/tag.feature
107
+ - features/team.feature
108
+ - features/tree.feature
109
+ - features/user.feature
94
110
  - fixtures/.githubrc
95
111
  - fixtures/simple_config
112
+ - ghc_logo.png
96
113
  - github_cli.gemspec
97
114
  - lib/github_cli.rb
98
115
  - lib/github_cli/api.rb
@@ -104,18 +121,23 @@ files:
104
121
  - lib/github_cli/apis/download.rb
105
122
  - lib/github_cli/apis/email.rb
106
123
  - lib/github_cli/apis/event.rb
124
+ - lib/github_cli/apis/follower.rb
107
125
  - lib/github_cli/apis/fork.rb
108
126
  - lib/github_cli/apis/gist.rb
109
127
  - lib/github_cli/apis/hook.rb
110
128
  - lib/github_cli/apis/issue.rb
111
129
  - lib/github_cli/apis/key.rb
112
130
  - lib/github_cli/apis/label.rb
131
+ - lib/github_cli/apis/member.rb
113
132
  - lib/github_cli/apis/milestone.rb
133
+ - lib/github_cli/apis/organization.rb
114
134
  - lib/github_cli/apis/pull_request.rb
115
135
  - lib/github_cli/apis/reference.rb
116
136
  - lib/github_cli/apis/repository.rb
117
137
  - lib/github_cli/apis/tag.rb
138
+ - lib/github_cli/apis/team.rb
118
139
  - lib/github_cli/apis/tree.rb
140
+ - lib/github_cli/apis/user.rb
119
141
  - lib/github_cli/apis/watching.rb
120
142
  - lib/github_cli/cli.rb
121
143
  - lib/github_cli/command.rb
@@ -127,27 +149,36 @@ files:
127
149
  - lib/github_cli/commands/downloads.rb
128
150
  - lib/github_cli/commands/emails.rb
129
151
  - lib/github_cli/commands/events.rb
152
+ - lib/github_cli/commands/followers.rb
130
153
  - lib/github_cli/commands/forks.rb
131
154
  - lib/github_cli/commands/gists.rb
132
155
  - lib/github_cli/commands/hooks.rb
133
156
  - lib/github_cli/commands/issues.rb
134
157
  - lib/github_cli/commands/keys.rb
135
158
  - lib/github_cli/commands/labels.rb
159
+ - lib/github_cli/commands/members.rb
136
160
  - lib/github_cli/commands/milestones.rb
161
+ - lib/github_cli/commands/organizations.rb
137
162
  - lib/github_cli/commands/pull_requests.rb
138
163
  - lib/github_cli/commands/references.rb
139
164
  - lib/github_cli/commands/repositories.rb
140
165
  - lib/github_cli/commands/tags.rb
166
+ - lib/github_cli/commands/teams.rb
141
167
  - lib/github_cli/commands/trees.rb
168
+ - lib/github_cli/commands/users.rb
142
169
  - lib/github_cli/commands/watching.rb
143
170
  - lib/github_cli/config.rb
144
171
  - lib/github_cli/dsl.rb
172
+ - lib/github_cli/editor.rb
145
173
  - lib/github_cli/errors.rb
174
+ - lib/github_cli/formatter.rb
146
175
  - lib/github_cli/formatters.rb
147
176
  - lib/github_cli/formatters/csv.rb
148
177
  - lib/github_cli/formatters/table.rb
149
178
  - lib/github_cli/helpers.rb
179
+ - lib/github_cli/pager.rb
150
180
  - lib/github_cli/subcommands.rb
181
+ - lib/github_cli/system.rb
151
182
  - lib/github_cli/terminal.rb
152
183
  - lib/github_cli/thor_ext.rb
153
184
  - lib/github_cli/ui.rb
@@ -158,6 +189,7 @@ files:
158
189
  - spec/github_cli/command_spec.rb
159
190
  - spec/github_cli/config_spec.rb
160
191
  - spec/github_cli/helpers_spec.rb
192
+ - spec/github_cli/pager_spec.rb
161
193
  - spec/github_cli/util_spec.rb
162
194
  - spec/spec_helper.rb
163
195
  homepage: http://github.com/peter-murach/github_cli
@@ -183,18 +215,36 @@ rubyforge_project:
183
215
  rubygems_version: 1.8.10
184
216
  signing_key:
185
217
  specification_version: 3
186
- summary: CLI-based access to GitHub API v3
218
+ summary: github_cli is a set of tools that provide full command line access to GitHub
219
+ API v3
187
220
  test_files:
221
+ - features/download.feature
222
+ - features/email.feature
223
+ - features/errors.feature
224
+ - features/event.feature
188
225
  - features/executable.feature
226
+ - features/follower.feature
227
+ - features/fork.feature
228
+ - features/hook.feature
229
+ - features/label.feature
230
+ - features/member.feature
231
+ - features/milestone.feature
232
+ - features/organization.feature
233
+ - features/reference.feature
189
234
  - features/repositories.feature
190
235
  - features/search.feature
191
236
  - features/settings.feature
192
237
  - features/support/env.rb
193
238
  - features/support/hooks.rb
239
+ - features/tag.feature
240
+ - features/team.feature
241
+ - features/tree.feature
242
+ - features/user.feature
194
243
  - spec/github_cli/api_spec.rb
195
244
  - spec/github_cli/cli_spec.rb
196
245
  - spec/github_cli/command_spec.rb
197
246
  - spec/github_cli/config_spec.rb
198
247
  - spec/github_cli/helpers_spec.rb
248
+ - spec/github_cli/pager_spec.rb
199
249
  - spec/github_cli/util_spec.rb
200
250
  - spec/spec_helper.rb