github_cli 0.2.1 → 0.3.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 (55) hide show
  1. data/CHANGELOG.md +9 -0
  2. data/Gemfile.lock +3 -3
  3. data/README.md +30 -0
  4. data/bin/ghc +13 -1
  5. data/features/repositories.feature +9 -0
  6. data/github_cli.gemspec +1 -1
  7. data/lib/github_cli.rb +2 -0
  8. data/lib/github_cli/api.rb +7 -2
  9. data/lib/github_cli/apis.rb +4 -0
  10. data/lib/github_cli/apis/authorization.rb +20 -10
  11. data/lib/github_cli/apis/blob.rb +8 -4
  12. data/lib/github_cli/apis/collaborator.rb +34 -0
  13. data/lib/github_cli/apis/commit.rb +8 -4
  14. data/lib/github_cli/apis/download.rb +20 -10
  15. data/lib/github_cli/apis/fork.rb +8 -4
  16. data/lib/github_cli/apis/gist.rb +70 -0
  17. data/lib/github_cli/apis/hook.rb +24 -12
  18. data/lib/github_cli/apis/issue.rb +40 -0
  19. data/lib/github_cli/apis/key.rb +20 -10
  20. data/lib/github_cli/apis/label.rb +40 -18
  21. data/lib/github_cli/apis/pull_request.rb +32 -16
  22. data/lib/github_cli/apis/reference.rb +20 -10
  23. data/lib/github_cli/apis/repository.rb +36 -19
  24. data/lib/github_cli/apis/tag.rb +8 -4
  25. data/lib/github_cli/apis/tree.rb +8 -4
  26. data/lib/github_cli/apis/watching.rb +20 -10
  27. data/lib/github_cli/command.rb +19 -0
  28. data/lib/github_cli/commands.rb +2 -0
  29. data/lib/github_cli/commands/authorizations.rb +5 -5
  30. data/lib/github_cli/commands/blobs.rb +2 -2
  31. data/lib/github_cli/commands/collaborators.rb +37 -0
  32. data/lib/github_cli/commands/commits.rb +2 -2
  33. data/lib/github_cli/commands/downloads.rb +5 -5
  34. data/lib/github_cli/commands/forks.rb +2 -2
  35. data/lib/github_cli/commands/gists.rb +103 -0
  36. data/lib/github_cli/commands/hooks.rb +6 -6
  37. data/lib/github_cli/commands/issues.rb +67 -18
  38. data/lib/github_cli/commands/keys.rb +5 -5
  39. data/lib/github_cli/commands/labels.rb +8 -8
  40. data/lib/github_cli/commands/pull_requests.rb +8 -8
  41. data/lib/github_cli/commands/references.rb +5 -5
  42. data/lib/github_cli/commands/repositories.rb +20 -20
  43. data/lib/github_cli/commands/tags.rb +2 -2
  44. data/lib/github_cli/commands/trees.rb +2 -2
  45. data/lib/github_cli/commands/watching.rb +5 -5
  46. data/lib/github_cli/errors.rb +33 -2
  47. data/lib/github_cli/formatters.rb +8 -0
  48. data/lib/github_cli/formatters/csv.rb +39 -0
  49. data/lib/github_cli/formatters/table.rb +36 -0
  50. data/lib/github_cli/subcommands.rb +6 -0
  51. data/lib/github_cli/terminal.rb +25 -0
  52. data/lib/github_cli/util.rb +35 -0
  53. data/lib/github_cli/version.rb +1 -1
  54. data/spec/github_cli/util_spec.rb +37 -0
  55. metadata +26 -13
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ module Formatters
5
+ class CSV
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def format
12
+ case @response
13
+ when Array
14
+ render_headers @response.first
15
+ @response.each_with_index do |item, indx|
16
+ render_line indx, item
17
+ $stdout.puts
18
+ end
19
+ else
20
+ render_headers @response
21
+ render_line 1, @response
22
+ end
23
+ end
24
+
25
+ def render_headers(response)
26
+ output = {}
27
+ GithubCLI::Util.flatten_hash(response.to_hash, output)
28
+ puts "Index," + output.keys.join(',')
29
+ end
30
+
31
+ def render_line(index, item)
32
+ output = {}
33
+ GithubCLI::Util.flatten_hash(item.to_hash, output)
34
+ printf "%d,%s", index, output.values.join(',')
35
+ end
36
+
37
+ end # CSV
38
+ end # Formatters
39
+ end # GithubCLI
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ module GithubCLI
4
+ module Formatters
5
+ class Table
6
+
7
+ def initialize(response)
8
+ @response = response
9
+ end
10
+
11
+ def format
12
+ case @response
13
+ when Array
14
+ @response.each do |item|
15
+ render_vertical item
16
+ $stdout.puts
17
+ end
18
+ else
19
+ render_vertical @response
20
+ end
21
+ end
22
+
23
+ def render_vertical(item)
24
+ output = {}
25
+ GithubCLI::Util.flatten_hash(item.to_hash, output)
26
+ GithubCLI.ui.print_table(
27
+ output.keys.zip(GithubCLI::Util.convert_values(output.values))
28
+ )
29
+ end
30
+
31
+ def render_horizontal
32
+ end
33
+
34
+ end # Table
35
+ end # Formatters
36
+ end # GithubCLI
@@ -9,6 +9,9 @@ module GithubCLI
9
9
  desc "blob <command>", "Leverage Blobs API"
10
10
  subcommand "blob", GithubCLI::Commands::Blobs
11
11
 
12
+ desc "collab <command>", "Leverage Collaborators API"
13
+ subcommand "collab", GithubCLI::Commands::Collaborators
14
+
12
15
  desc "commit <command>", "Leverage Commits API"
13
16
  subcommand "commit", GithubCLI::Commands::Commits
14
17
 
@@ -18,6 +21,9 @@ module GithubCLI
18
21
  desc "fork <command>", "Leverage Forks API"
19
22
  subcommand "fork", GithubCLI::Commands::Forks
20
23
 
24
+ desc "gist <command>", "Leverage Gists API"
25
+ subcommand "gist", GithubCLI::Commands::Gists
26
+
21
27
  desc "hook <command>", "Leverage Hooks API"
22
28
  subcommand "hook", GithubCLI::Commands::Hooks
23
29
 
@@ -9,6 +9,31 @@ module GithubCLI
9
9
  class << self
10
10
  attr_accessor :size
11
11
 
12
+ def render_output(response, options={})
13
+ render_status response
14
+ case options[:format].to_s
15
+ when 'table'
16
+ formatter = Formatters::Table.new(response)
17
+ formatter.format
18
+ when 'csv'
19
+ formatter = Formatters::CSV.new(response)
20
+ formatter.format
21
+ when 'json'
22
+ 'json output'
23
+ else
24
+ raise UnknownFormatError, options[:format]
25
+ end
26
+ end
27
+
28
+ # Render status code
29
+ def render_status(response)
30
+ puts "Response Status: #{response.status}"
31
+ puts
32
+ end
33
+
34
+ def render_header
35
+ end
36
+
12
37
  def print_commands(pattern=nil)
13
38
  GithubCLI.ui.info "Commands:"
14
39
 
@@ -0,0 +1,35 @@
1
+ module GithubCLI
2
+ module Util
3
+ extend self
4
+
5
+ def flatten_hash(prefix=nil, hash, new_hash)
6
+ hash.each do |key, val|
7
+ key = prefix ? :"#{prefix}_#{key}" : key
8
+ case val
9
+ when Hash
10
+ flatten_hash(key, val, new_hash)
11
+ else
12
+ new_hash[key] = val
13
+ end
14
+ end
15
+ return new_hash
16
+ end
17
+
18
+ def convert_values(values)
19
+ values_copy = values.dup
20
+ collected = []
21
+ 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
32
+ end
33
+ end
34
+ end
35
+ end # GithubCLI
@@ -1,3 +1,3 @@
1
1
  module GithubCLI
2
- VERSION = "0.2.1"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,37 @@
1
+ require 'spec_helper'
2
+
3
+ describe GithubCLI::Util do
4
+ describe '#flatten_has' do
5
+ let(:hash) { { :a => { :b => { :c => 1 }}} }
6
+
7
+ it 'preserves original hash' do
8
+ hash = { :a => 1, :b => 2 }
9
+ output = {}
10
+ subject.flatten_hash hash, output
11
+ output.should == hash
12
+ end
13
+
14
+ it "reduces multidimensional keys to one dimension" do
15
+ output = {}
16
+ subject.flatten_hash hash, output
17
+ output.should == { :a_b_c => 1 }
18
+ end
19
+ end
20
+
21
+ describe '#convert_values' do
22
+ let(:values) { [true, {:a => false }, 'string']}
23
+
24
+ it "converts ruby boolean to string" do
25
+ subject.convert_values(values).should include "true"
26
+ subject.convert_values(values).should_not include true
27
+ end
28
+
29
+ it "converts recursively" do
30
+ subject.convert_values(values).should include ['false']
31
+ end
32
+
33
+ it 'preserves strings' do
34
+ subject.convert_values(values).should include 'string'
35
+ end
36
+ end
37
+ 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.2.1
4
+ version: 0.3.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-04-30 00:00:00.000000000Z
12
+ date: 2012-05-13 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_api
16
- requirement: &2153209580 !ruby/object:Gem::Requirement
16
+ requirement: &2153151980 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
20
20
  - !ruby/object:Gem::Version
21
- version: 0.5.0
21
+ version: '0.5'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153209580
24
+ version_requirements: *2153151980
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: thor
27
- requirement: &2153208980 !ruby/object:Gem::Requirement
27
+ requirement: &2153151560 !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: *2153208980
35
+ version_requirements: *2153151560
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &2153208340 !ruby/object:Gem::Requirement
38
+ requirement: &2153151100 !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: *2153208340
46
+ version_requirements: *2153151100
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: aruba
49
- requirement: &2153207420 !ruby/object:Gem::Requirement
49
+ requirement: &2153150680 !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: *2153207420
57
+ version_requirements: *2153150680
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rake
60
- requirement: &2153207000 !ruby/object:Gem::Requirement
60
+ requirement: &2153150260 !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: *2153207000
68
+ version_requirements: *2153150260
69
69
  description: CLI-based access to GitHub API v3
70
70
  email:
71
71
  - pmurach@gmail.com
@@ -86,6 +86,7 @@ files:
86
86
  - Rakefile
87
87
  - bin/ghc
88
88
  - features/executable.feature
89
+ - features/repositories.feature
89
90
  - features/search.feature
90
91
  - features/settings.feature
91
92
  - features/support/env.rb
@@ -98,10 +99,13 @@ files:
98
99
  - lib/github_cli/apis.rb
99
100
  - lib/github_cli/apis/authorization.rb
100
101
  - lib/github_cli/apis/blob.rb
102
+ - lib/github_cli/apis/collaborator.rb
101
103
  - lib/github_cli/apis/commit.rb
102
104
  - lib/github_cli/apis/download.rb
103
105
  - lib/github_cli/apis/fork.rb
106
+ - lib/github_cli/apis/gist.rb
104
107
  - lib/github_cli/apis/hook.rb
108
+ - lib/github_cli/apis/issue.rb
105
109
  - lib/github_cli/apis/key.rb
106
110
  - lib/github_cli/apis/label.rb
107
111
  - lib/github_cli/apis/pull_request.rb
@@ -115,9 +119,11 @@ files:
115
119
  - lib/github_cli/commands.rb
116
120
  - lib/github_cli/commands/authorizations.rb
117
121
  - lib/github_cli/commands/blobs.rb
122
+ - lib/github_cli/commands/collaborators.rb
118
123
  - lib/github_cli/commands/commits.rb
119
124
  - lib/github_cli/commands/downloads.rb
120
125
  - lib/github_cli/commands/forks.rb
126
+ - lib/github_cli/commands/gists.rb
121
127
  - lib/github_cli/commands/hooks.rb
122
128
  - lib/github_cli/commands/issues.rb
123
129
  - lib/github_cli/commands/keys.rb
@@ -131,16 +137,21 @@ files:
131
137
  - lib/github_cli/config.rb
132
138
  - lib/github_cli/dsl.rb
133
139
  - lib/github_cli/errors.rb
140
+ - lib/github_cli/formatters.rb
141
+ - lib/github_cli/formatters/csv.rb
142
+ - lib/github_cli/formatters/table.rb
134
143
  - lib/github_cli/helpers.rb
135
144
  - lib/github_cli/subcommands.rb
136
145
  - lib/github_cli/terminal.rb
137
146
  - lib/github_cli/ui.rb
147
+ - lib/github_cli/util.rb
138
148
  - lib/github_cli/version.rb
139
149
  - spec/github_cli/api_spec.rb
140
150
  - spec/github_cli/cli_spec.rb
141
151
  - spec/github_cli/command_spec.rb
142
152
  - spec/github_cli/config_spec.rb
143
153
  - spec/github_cli/helpers_spec.rb
154
+ - spec/github_cli/util_spec.rb
144
155
  - spec/spec_helper.rb
145
156
  homepage: http://github.com/peter-murach/github_cli
146
157
  licenses: []
@@ -168,6 +179,7 @@ specification_version: 3
168
179
  summary: CLI-based access to GitHub API v3
169
180
  test_files:
170
181
  - features/executable.feature
182
+ - features/repositories.feature
171
183
  - features/search.feature
172
184
  - features/settings.feature
173
185
  - features/support/env.rb
@@ -177,4 +189,5 @@ test_files:
177
189
  - spec/github_cli/command_spec.rb
178
190
  - spec/github_cli/config_spec.rb
179
191
  - spec/github_cli/helpers_spec.rb
192
+ - spec/github_cli/util_spec.rb
180
193
  - spec/spec_helper.rb