github_cli 0.4.4 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (67) hide show
  1. data/.gitignore +1 -0
  2. data/.travis.yml +0 -2
  3. data/CHANGELOG.md +14 -0
  4. data/Gemfile.lock +9 -3
  5. data/README.md +68 -48
  6. data/Rakefile +47 -1
  7. data/bin/gcli +18 -0
  8. data/bin/ghc +1 -17
  9. data/features/blob.feature +6 -6
  10. data/features/collaborator.feature +10 -10
  11. data/features/commit.feature +6 -6
  12. data/features/completion.feature +3 -3
  13. data/features/config.feature +55 -0
  14. data/features/content.feature +9 -9
  15. data/features/download.feature +11 -11
  16. data/features/email.feature +8 -8
  17. data/features/errors.feature +11 -9
  18. data/features/event.feature +20 -20
  19. data/features/executable.feature +4 -4
  20. data/features/follower.feature +13 -13
  21. data/features/fork.feature +6 -6
  22. data/features/gist.feature +22 -22
  23. data/features/hook.feature +14 -14
  24. data/features/init.feature +48 -0
  25. data/features/issue.feature +12 -12
  26. data/features/key.feature +12 -12
  27. data/features/label.feature +23 -23
  28. data/features/member.feature +13 -13
  29. data/features/milestone.feature +12 -12
  30. data/features/organization.feature +9 -9
  31. data/features/pull_request.feature +18 -18
  32. data/features/reference.feature +13 -13
  33. data/features/repository.feature +20 -20
  34. data/features/search.feature +10 -10
  35. data/features/search_commands.feature +4 -4
  36. data/features/support/hooks.rb +3 -1
  37. data/features/tag.feature +6 -6
  38. data/features/team.feature +28 -28
  39. data/features/tree.feature +5 -5
  40. data/features/usage.feature +3 -3
  41. data/features/user.feature +7 -7
  42. data/features/watching.feature +13 -13
  43. data/fixtures/simple_config +9 -8
  44. data/github_cli.gemspec +2 -2
  45. data/lib/github_cli/api.rb +3 -3
  46. data/lib/github_cli/cli.rb +96 -17
  47. data/lib/github_cli/config.rb +30 -9
  48. data/lib/github_cli/editor.rb +11 -6
  49. data/lib/github_cli/man/gcli-config.1 +102 -0
  50. data/lib/github_cli/man/gcli-config.1.txt +96 -0
  51. data/lib/github_cli/man/gcli-repo.1 +16 -0
  52. data/lib/github_cli/man/gcli-repo.1.txt +15 -0
  53. data/lib/github_cli/man/gcli.1 +34 -0
  54. data/lib/github_cli/man/gcli.1.txt +33 -0
  55. data/lib/github_cli/manpage.rb +42 -0
  56. data/lib/github_cli/pager.rb +1 -1
  57. data/lib/github_cli/terminal.rb +8 -2
  58. data/lib/github_cli/thor_ext.rb +12 -1
  59. data/lib/github_cli/vendor.rb +10 -0
  60. data/lib/github_cli/version.rb +1 -1
  61. data/lib/github_cli.rb +7 -2
  62. data/man/gcli-config.1.ronn +82 -0
  63. data/man/gcli-repo.1.ronn +7 -0
  64. data/man/gcli.1.ronn +29 -0
  65. data/spec/github_cli/config_spec.rb +21 -7
  66. metadata +43 -22
  67. data/features/settings.feature +0 -35
@@ -1,20 +1,20 @@
1
- Feature: ghc search
1
+ Feature: gcli search
2
2
 
3
3
  Scenario: Available commands
4
4
 
5
- When I run `ghc search`
5
+ When I run `gcli search`
6
6
  Then the exit status should be 0
7
- And the output should contain "ghc search email"
8
- And the output should contain "ghc search issue"
9
- And the output should contain "ghc search repo"
10
- And the output should contain "ghc search user"
7
+ And the output should contain "gcli search email"
8
+ And the output should contain "gcli search issue"
9
+ And the output should contain "gcli search repo"
10
+ And the output should contain "gcli search user"
11
11
 
12
12
  Scenario: Search issues
13
13
  Given the GitHub API server:
14
14
  """
15
15
  get('/legacy/issues/search/wycats/thor/open/shell') { status 200 }
16
16
  """
17
- When I run `ghc search issue wycats thor shell --state=open`
17
+ When I run `gcli search issue wycats thor shell --state=open`
18
18
  Then the exit status should be 0
19
19
 
20
20
  Scenario: Search repositories
@@ -22,7 +22,7 @@ Feature: ghc search
22
22
  """
23
23
  get('/legacy/repos/search/shell') { status 200 }
24
24
  """
25
- When I run `ghc search repo shell`
25
+ When I run `gcli search repo shell`
26
26
  Then the exit status should be 0
27
27
 
28
28
  Scenario: Search users
@@ -30,7 +30,7 @@ Feature: ghc search
30
30
  """
31
31
  get('/legacy/user/search/wycats') { status 200 }
32
32
  """
33
- When I run `ghc search user wycats`
33
+ When I run `gcli search user wycats`
34
34
  Then the exit status should be 0
35
35
 
36
36
  Scenario: Search email
@@ -38,5 +38,5 @@ Feature: ghc search
38
38
  """
39
39
  get('/legacy/user/search/wycats') { status 200 }
40
40
  """
41
- When I run `ghc search user wycats`
41
+ When I run `gcli search user wycats`
42
42
  Then the exit status should be 0
@@ -6,7 +6,7 @@ Feature: Github API Commands Search
6
6
  I have ability to list commands by search criteria
7
7
 
8
8
  Scenario: Listing
9
- When I run `ghc list`
9
+ When I run `gcli list`
10
10
  Then the exit status should be 0
11
11
  And the output should contain:
12
12
  """
@@ -16,7 +16,7 @@ Feature: Github API Commands Search
16
16
  """
17
17
 
18
18
  Scenario Outline: Pattern Matching
19
- When I run `ghc list <pattern>`
19
+ When I run `gcli list <pattern>`
20
20
  Then the output should contain "repo"
21
21
  And the output should not contain "issue"
22
22
 
@@ -26,8 +26,8 @@ Feature: Github API Commands Search
26
26
  | repo |
27
27
 
28
28
  Scenario: No Match
29
- When I run `ghc list bla`
29
+ When I run `gcli list bla`
30
30
  Then the output should contain:
31
31
  """
32
- ghc: 'bla' is not a ghc command. See 'ghc --help'.
32
+ gcli: 'bla' is not a gcli command. See 'gcli --help'.
33
33
  """
@@ -1,7 +1,9 @@
1
1
  require 'fileutils'
2
2
 
3
3
  Before do
4
- @aruba_timeout_seconds = 10
4
+ @aruba_timeout_seconds = 5
5
+ @aruba_io_wait_seconds = 0.2
6
+
5
7
  @real_home = ENV['HOME']
6
8
  fake_home = File.join('/tmp', 'fakehome')
7
9
  FileUtils.rm_rf fake_home if File.exists? fake_home
data/features/tag.feature CHANGED
@@ -1,18 +1,18 @@
1
- Feature: ghc tag
1
+ Feature: gcli tag
2
2
 
3
3
  Scenario: Available commands
4
4
 
5
- When I run `ghc tag`
5
+ When I run `gcli tag`
6
6
  Then the exit status should be 0
7
- And the output should contain "ghc tag create"
8
- And the output should contain "ghc tag get"
7
+ And the output should contain "gcli tag create"
8
+ And the output should contain "gcli tag get"
9
9
 
10
10
  Scenario: Get tag
11
11
  Given the GitHub API server:
12
12
  """
13
13
  get('/repos/wycats/thor/git/tags/827efc6d5') { status 200 }
14
14
  """
15
- When I run `ghc tag get wycats thor 827efc6d5`
15
+ When I run `gcli tag get wycats thor 827efc6d5`
16
16
  Then the exit status should be 0
17
17
 
18
18
  Scenario: Create tag
@@ -20,5 +20,5 @@ Feature: ghc tag
20
20
  """
21
21
  post('/repos/wycats/thor/git/tags') { status 200 }
22
22
  """
23
- When I run `ghc tag create wycats thor`
23
+ When I run `gcli tag create wycats thor`
24
24
  Then the exit status should be 0
@@ -1,28 +1,28 @@
1
- Feature: ghc team
1
+ Feature: gcli team
2
2
 
3
3
  Scenario: Available commands
4
- When I run `ghc team`
4
+ When I run `gcli team`
5
5
  Then the exit status should be 0
6
- And the output should contain "ghc team add_member"
7
- And the output should contain "ghc team add_repo"
8
- And the output should contain "ghc team create"
9
- And the output should contain "ghc team delete"
10
- And the output should contain "ghc team edit"
11
- And the output should contain "ghc team get"
12
- And the output should contain "ghc team list"
13
- And the output should contain "ghc team list_member"
14
- And the output should contain "ghc team list_repo"
15
- And the output should contain "ghc team member"
16
- And the output should contain "ghc team remove_member"
17
- And the output should contain "ghc team remove_repo"
18
- And the output should contain "ghc team repo"
6
+ And the output should contain "gcli team add_member"
7
+ And the output should contain "gcli team add_repo"
8
+ And the output should contain "gcli team create"
9
+ And the output should contain "gcli team delete"
10
+ And the output should contain "gcli team edit"
11
+ And the output should contain "gcli team get"
12
+ And the output should contain "gcli team list"
13
+ And the output should contain "gcli team list_member"
14
+ And the output should contain "gcli team list_repo"
15
+ And the output should contain "gcli team member"
16
+ And the output should contain "gcli team remove_member"
17
+ And the output should contain "gcli team remove_repo"
18
+ And the output should contain "gcli team repo"
19
19
 
20
20
  Scenario: List all teams
21
21
  Given the GitHub API server:
22
22
  """
23
23
  get('/orgs/rails/teams') { status 200 }
24
24
  """
25
- When I run `ghc team ls rails`
25
+ When I run `gcli team ls rails`
26
26
  Then the exit status should be 0
27
27
 
28
28
  Scenario: Get team
@@ -30,7 +30,7 @@ Feature: ghc team
30
30
  """
31
31
  get('/teams/rails') { status 200 }
32
32
  """
33
- When I run `ghc team get rails`
33
+ When I run `gcli team get rails`
34
34
  Then the exit status should be 0
35
35
 
36
36
  Scenario: Create team
@@ -38,7 +38,7 @@ Feature: ghc team
38
38
  """
39
39
  post('/orgs/rails/teams') { status 200 }
40
40
  """
41
- When I run `ghc team create rails --params=name:'new team'`
41
+ When I run `gcli team create rails --params=name:'new team'`
42
42
  Then the exit status should be 0
43
43
 
44
44
  Scenario: Edit team
@@ -46,7 +46,7 @@ Feature: ghc team
46
46
  """
47
47
  patch('/teams/rails') { status 200 }
48
48
  """
49
- When I run `ghc team edit rails --params=name:'new team'`
49
+ When I run `gcli team edit rails --params=name:'new team'`
50
50
  Then the exit status should be 0
51
51
 
52
52
  Scenario: Delete team
@@ -54,7 +54,7 @@ Feature: ghc team
54
54
  """
55
55
  delete('/teams/rails') { status 200 }
56
56
  """
57
- When I run `ghc team del rails`
57
+ When I run `gcli team del rails`
58
58
  Then the exit status should be 0
59
59
 
60
60
  Scenario: List team members
@@ -62,7 +62,7 @@ Feature: ghc team
62
62
  """
63
63
  get('/teams/rails/members') { status 200 }
64
64
  """
65
- When I run `ghc team list_members rails`
65
+ When I run `gcli team list_members rails`
66
66
  Then the exit status should be 0
67
67
 
68
68
  Scenario: Check is user is a team member
@@ -70,7 +70,7 @@ Feature: ghc team
70
70
  """
71
71
  get('/teams/rails/members/wycats') { status 200 }
72
72
  """
73
- When I run `ghc team member rails wycats`
73
+ When I run `gcli team member rails wycats`
74
74
  Then the exit status should be 0
75
75
 
76
76
  Scenario: Add a team member
@@ -78,7 +78,7 @@ Feature: ghc team
78
78
  """
79
79
  put('/teams/rails/members/wycats') { status 200 }
80
80
  """
81
- When I run `ghc team add_member rails wycats`
81
+ When I run `gcli team add_member rails wycats`
82
82
  Then the exit status should be 0
83
83
 
84
84
  Scenario: Remove a team member
@@ -86,7 +86,7 @@ Feature: ghc team
86
86
  """
87
87
  delete('/teams/rails/members/wycats') { status 200 }
88
88
  """
89
- When I run `ghc team remove_member rails wycats`
89
+ When I run `gcli team remove_member rails wycats`
90
90
  Then the exit status should be 0
91
91
 
92
92
  Scenario: List team repositories
@@ -94,7 +94,7 @@ Feature: ghc team
94
94
  """
95
95
  get('/teams/rails/repos') { status 200 }
96
96
  """
97
- When I run `ghc team list_repo rails`
97
+ When I run `gcli team list_repo rails`
98
98
  Then the exit status should be 0
99
99
 
100
100
  Scenario: Check if repository belongs to a team
@@ -102,7 +102,7 @@ Feature: ghc team
102
102
  """
103
103
  get('/teams/rails/repos/wycats/thor') { status 200 }
104
104
  """
105
- When I run `ghc team repo rails wycats thor`
105
+ When I run `gcli team repo rails wycats thor`
106
106
  Then the exit status should be 0
107
107
 
108
108
  Scenario: Add a team repository
@@ -110,7 +110,7 @@ Feature: ghc team
110
110
  """
111
111
  put('/teams/rails/repos/wycats/thor') { status 200 }
112
112
  """
113
- When I run `ghc team add_repo rails wycats thor`
113
+ When I run `gcli team add_repo rails wycats thor`
114
114
  Then the exit status should be 0
115
115
 
116
116
  Scenario: Remove a team repository
@@ -118,6 +118,6 @@ Feature: ghc team
118
118
  """
119
119
  delete('/teams/rails/repos/wycats/thor') { status 200 }
120
120
  """
121
- When I run `ghc team remove_repo rails wycats thor`
121
+ When I run `gcli team remove_repo rails wycats thor`
122
122
  Then the exit status should be 0
123
123
 
@@ -1,16 +1,16 @@
1
- Feature: ghc tree
1
+ Feature: gcli tree
2
2
 
3
3
  Scenario: Available commands
4
4
 
5
- When I run `ghc tree`
5
+ When I run `gcli tree`
6
6
  Then the exit status should be 0
7
- And the output should contain "ghc tree create"
8
- And the output should contain "ghc tree get"
7
+ And the output should contain "gcli tree create"
8
+ And the output should contain "gcli tree get"
9
9
 
10
10
  Scenario: Get tree
11
11
  Given the GitHub API server:
12
12
  """
13
13
  get('/repos/wycats/thor/git/trees/827efc6d5') { status 200 }
14
14
  """
15
- When I run `ghc tree get wycats thor 827efc6d5`
15
+ When I run `gcli tree get wycats thor 827efc6d5`
16
16
  Then the exit status should be 0
@@ -2,9 +2,9 @@ Feature: Command Usage
2
2
 
3
3
  Scenario: Getting Usage for Commands
4
4
 
5
- When I run `ghc`
5
+ When I run `gcli`
6
6
  Then the exit status should be 0
7
- And the output should contain "Usage: ghc"
7
+ And the output should contain "Usage: gcli"
8
8
  And the output should contain "[--config]"
9
9
  And the output should contain "[--no-color]"
10
10
  And the output should contain "[--no-pager]"
@@ -13,6 +13,6 @@ Feature: Command Usage
13
13
 
14
14
  Scenario: Specific usage for command
15
15
 
16
- When I run `ghc repo`
16
+ When I run `gcli repo`
17
17
  Then the exit status should be 0
18
18
  And the output should contain "repo <subcommand>"
@@ -1,18 +1,18 @@
1
- Feature: ghc user
1
+ Feature: gcli user
2
2
 
3
3
  Scenario: Available commands
4
4
 
5
- When I run `ghc user`
5
+ When I run `gcli user`
6
6
  Then the exit status should be 0
7
- And the output should contain "ghc user get"
8
- And the output should contain "ghc user update"
7
+ And the output should contain "gcli user get"
8
+ And the output should contain "gcli user update"
9
9
 
10
10
  Scenario: Get user
11
11
  Given the GitHub API server:
12
12
  """
13
13
  get('/users/wycats') { status 200 }
14
14
  """
15
- When I run `ghc user get -u wycats`
15
+ When I run `gcli user get -u wycats`
16
16
  Then the exit status should be 0
17
17
 
18
18
  Scenario: Get the authenticated user
@@ -20,7 +20,7 @@ Feature: ghc user
20
20
  """
21
21
  get('/user') { status 200 }
22
22
  """
23
- When I run `ghc user get`
23
+ When I run `gcli user get`
24
24
  Then the exit status should be 0
25
25
 
26
26
  Scenario: Update the authenticated user
@@ -28,5 +28,5 @@ Feature: ghc user
28
28
  """
29
29
  patch('/user') { status 200 }
30
30
  """
31
- When I run `ghc user update --params=name:peter-murach`
31
+ When I run `gcli user update --params=name:peter-murach`
32
32
  Then the exit status should be 0
@@ -1,21 +1,21 @@
1
- Feature: ghc watching
1
+ Feature: gcli watching
2
2
 
3
3
  Scenario: Available commands
4
4
 
5
- When I run `ghc watch`
5
+ When I run `gcli watch`
6
6
  Then the exit status should be 0
7
- And the output should contain "ghc watch start"
8
- And the output should contain "ghc watch stop"
9
- And the output should contain "ghc watch watched"
10
- And the output should contain "ghc watch watchers"
11
- And the output should contain "ghc watch watching"
7
+ And the output should contain "gcli watch start"
8
+ And the output should contain "gcli watch stop"
9
+ And the output should contain "gcli watch watched"
10
+ And the output should contain "gcli watch watchers"
11
+ And the output should contain "gcli watch watching"
12
12
 
13
13
  Scenario: Watchers
14
14
  Given the GitHub API server:
15
15
  """
16
16
  get('/repos/wycats/thor/watchers') { status 200 }
17
17
  """
18
- When I run `ghc watch watchers wycats thor`
18
+ When I run `gcli watch watchers wycats thor`
19
19
  Then the exit status should be 0
20
20
 
21
21
  Scenario: Start watching
@@ -23,7 +23,7 @@ Feature: ghc watching
23
23
  """
24
24
  put('/user/watched/wycats/thor') { status 200 }
25
25
  """
26
- When I run `ghc watch start wycats thor`
26
+ When I run `gcli watch start wycats thor`
27
27
  Then the exit status should be 0
28
28
 
29
29
  Scenario: Stop watching
@@ -31,7 +31,7 @@ Feature: ghc watching
31
31
  """
32
32
  delete('/user/watched/wycats/thor') { status 200 }
33
33
  """
34
- When I run `ghc watch stop wycats thor`
34
+ When I run `gcli watch stop wycats thor`
35
35
  Then the exit status should be 0
36
36
 
37
37
  Scenario: Watching
@@ -39,7 +39,7 @@ Feature: ghc watching
39
39
  """
40
40
  get('/user/watched/wycats/thor') { status 200 }
41
41
  """
42
- When I run `ghc watch watching wycats thor`
42
+ When I run `gcli watch watching wycats thor`
43
43
  Then the exit status should be 0
44
44
 
45
45
  Scenario: Watched by a user
@@ -47,7 +47,7 @@ Feature: ghc watching
47
47
  """
48
48
  get('/users/wycats/watched') { status 200 }
49
49
  """
50
- When I run `ghc watch watched -u wycats`
50
+ When I run `gcli watch watched -u wycats`
51
51
  Then the exit status should be 0
52
52
 
53
53
  Scenario: Watched by the authenticated user
@@ -55,6 +55,6 @@ Feature: ghc watching
55
55
  """
56
56
  get('/user/watched') { status 200 }
57
57
  """
58
- When I run `ghc watch watched`
58
+ When I run `gcli watch watched`
59
59
  Then the exit status should be 0
60
60
 
@@ -1,9 +1,10 @@
1
1
  ---
2
- oauth_token: ad7f9asdf97as98df7as9fd7
3
- basic_auth: 'login:password'
4
- host:
5
- user:
6
- repo:
7
- commands:
8
- issue-list: { inputs: 'ticket' }
9
- issue-get: {}
2
+ auth.token: ad7f9asdf97as98df7as9fd7
3
+ auth.basic: 'login:password'
4
+ core.host:
5
+ core.user:
6
+ core.repo:
7
+ commands.issue.list:
8
+ title: 'ticket'
9
+ commands.issue.get:
10
+ title: 'ticket'
data/github_cli.gemspec CHANGED
@@ -9,17 +9,17 @@ Gem::Specification.new do |gem|
9
9
  gem.homepage = "http://github.com/peter-murach/github_cli"
10
10
 
11
11
  gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
- gem.files = `git ls-files`.split("\n")
12
+ gem.files = `git ls-files`.split("\n") + Dir.glob("lib/github_cli/man/**/*")
13
13
  gem.test_files = `git ls-files -- {spec,features}/*`.split("\n")
14
14
  gem.name = "github_cli"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = GithubCLI::VERSION
17
17
 
18
18
  gem.add_dependency 'github_api', '~> 0.6'
19
- gem.add_dependency 'thor'
20
19
 
21
20
  gem.add_development_dependency 'rspec'
22
21
  gem.add_development_dependency 'aruba'
23
22
  gem.add_development_dependency 'rake'
24
23
  gem.add_development_dependency 'communist'
24
+ gem.add_development_dependency 'ronn'
25
25
  end
@@ -20,9 +20,9 @@ module GithubCLI
20
20
 
21
21
  def configure_api
22
22
  @@api = Github.new
23
- @@api.oauth_token = GithubCLI.config['oauth_token']
24
- @@api.basic_auth = GithubCLI.config['basic_auth']
25
- puts "#{ENV['TEST_HOST']}"
23
+ @@api.oauth_token = GithubCLI.config['auth.token']
24
+ @@api.basic_auth = GithubCLI.config['auth.basic']
25
+ @@api.endpoint = GithubCLI.config['core.endpoint'] || @@api.endpoint
26
26
  if ENV['TEST_HOST']
27
27
  @@api.endpoint = 'http://' + ENV['TEST_HOST']
28
28
  end
@@ -18,56 +18,135 @@ module GithubCLI
18
18
  'reference' => 'ref',
19
19
  'is' => :issue,
20
20
  '--version' => 'version',
21
+ '-V' => 'version',
21
22
  'ls' => 'list'
22
23
  }
23
24
 
24
25
  map ALIASES
25
26
 
26
27
  class_option :config, :type => :string,
27
- :desc => "Configuration file.", :banner => "Config file name",
28
+ :desc => "Configuration file.", :banner => "<filename>",
28
29
  :default => ".githubrc"
29
- class_option :oauth, :type => :string, :aliases => '-a',
30
+ class_option :token, :type => :string,
30
31
  :desc => 'Authentication token.',
31
- :banner => 'Set authentication token'
32
+ :banner => '<oauth token>'
32
33
  class_option "no-color", :type => :boolean,
33
34
  :desc => "Disable colorization in output."
34
35
  class_option "no-pager", :type => :boolean,
35
36
  :desc => "Disable pagination of the output."
36
37
  class_option :pager, :type => :string, :aliases => '-p',
37
- :desc => "Command to be used for paging. Command can have options after it i.e. 'less -r'. Defaults to common pagers i.e. less if detected.",
38
- :banner => "less, more etc..."
38
+ :desc => "Command to be used for paging.",
39
+ :banner => "less|more|..."
39
40
  class_option :verbose, :type => :boolean,
40
41
  :desc => "Enable verbose output mode."
41
- class_option :version, :type => :boolean,
42
+ class_option :version, :type => :boolean, :aliases => ['-V'],
42
43
  :desc => "Show program version"
43
44
 
44
- desc 'init', 'Generates a configuration file in your home directory'
45
+ no_tasks do
46
+ def defaults
47
+ {
48
+ 'auth.token' => nil,
49
+ 'auth.basic' => nil,
50
+ 'auth.login' => nil,
51
+ 'auth.password' => nil,
52
+ 'core.endpoint' => nil,
53
+ 'core.editor' => 'vi',
54
+ 'core.pager' => 'less',
55
+ 'core.no-pager' => false,
56
+ 'core.no-color' => false,
57
+ 'core.format' => 'csv',
58
+ 'core.auto' => false,
59
+ 'core.aliases' => {}
60
+ }
61
+ end
62
+ end
63
+
64
+ desc 'init [<filename>]', 'Generates a configuration file in your home directory'
45
65
  long_desc <<-DESC
46
66
  Initializes a configuration file where you can set default options for
47
- interacting with GitHub API. Both global and per-command options can be
48
- specified. These defaults override the bult-in defaults and allow you to
49
- omit commonly used command line options.
67
+ interacting with GitHub API.\n
68
+
69
+ Both global and per-command options can be specified. These defaults
70
+ override the bult-in defaults and allow you to save typing commonly used
71
+ command line options.
50
72
  DESC
51
73
  method_option :force, :type => :boolean, :default => false, :aliases => "-f",
52
74
  :banner => "Overwrite configuration file. "
75
+ method_option :global, :type => :boolean, :default => false,
76
+ :desc => 'Create global config file'
77
+ method_option :local, :type => :boolean, :default => false,
78
+ :desc => 'Create local config file'
53
79
  def init(filename=nil)
54
- if filename.nil? || filename =~ /^\//
55
- @config_filename = options[:config]
56
- else
57
- @config_filename = filename
80
+ config_filename = (filename.nil? || filename =~ /^\//)? options[:config] : filename
81
+
82
+ if !options[:global] and !options[:local]
83
+ GithubCLI.ui.error 'Invalid scope given. Please use --local or --global.'
84
+ exit 1
58
85
  end
59
86
 
60
- # config = Config.new(@config_filename)
87
+ GithubCLI.config.location = options[:local] ? 'local' : 'global'
88
+
61
89
  if File.exists?(GithubCLI.config.path) && !options[:force]
62
90
  GithubCLI.ui.error "Not overwritting existing config file #{GithubCLI.config.path}, use --force to override."
63
91
  exit 1
64
92
  end
65
93
 
66
94
  oauth_token = ask "Please specify your GitHub Authentication Token (register on github.com to get it):"
67
- GithubCLI.config.save({'oauth_token' => oauth_token, 'basic_auth' => nil })
95
+ GithubCLI.config.save(defaults.merge({'auth.token' => oauth_token}))
68
96
  GithubCLI.ui.confirm "Writing new configuration file to #{GithubCLI.config.path}"
69
97
  end
70
98
 
99
+ desc 'config <name> [<value>]', 'Get and set GitHub configuration options'
100
+ long_desc <<-DESC
101
+ You can query/set options with this command. The name is actually a hash key
102
+ string that is a composite one, nested with dots. If only name is provided, a
103
+ value will be retrieved. If two parameters are given then value will be set
104
+ or updated depending whether it already exists or not.\n
105
+
106
+ There two types of config files, global and project specific. When modifying
107
+ options ensure that you modifying the correct config.
108
+ DESC
109
+ method_option :global, :type => :boolean, :default => false,
110
+ :desc => 'use global config file'
111
+ method_option :local, :type => :boolean, :default => false,
112
+ :desc => 'use local config file'
113
+ method_option :list, :type => :boolean, :default => false, :aliases => '-l',
114
+ :desc => 'list all'
115
+ method_option :edit, :type => :boolean, :default => false, :aliases => '-e',
116
+ :desc => 'opens an editor'
117
+ def config(*args)
118
+ name, value = args.shift, args.shift
119
+
120
+ GithubCLI.config.location = options[:local] ? 'local' : 'global'
121
+
122
+ if !options[:global] and !options[:local]
123
+ GithubCLI.ui.error 'Invalid scope given. Please use --local or --global.'
124
+ exit 1
125
+ elsif !File.exists?(GithubCLI.config.path)
126
+ GithubCLI.ui.error "#{GithubCLI.config.location} configuration file does not exist. Please use `#{GithubCLI.executable_name} init --#{GithubCLI.config.location}`"
127
+ exit 1
128
+ end
129
+
130
+ if options[:list]
131
+ Terminal.print_config(name) && return
132
+ elsif options[:edit]
133
+ editor = Editor.new GithubCLI.config.path
134
+ editor.open && return
135
+ end
136
+
137
+ if !name
138
+ Terminal.print_config && return
139
+ end
140
+
141
+ if !value
142
+ Terminal.line GithubCLI.config[name]
143
+ else
144
+ Terminal.line GithubCLI.config[name] = value
145
+ end
146
+
147
+ return
148
+ end
149
+
71
150
  desc 'list <pattern>', 'List all available commands limited by pattern'
72
151
  def list(pattern="")
73
152
  pattern = /^#{pattern}.*$/i
@@ -76,7 +155,7 @@ module GithubCLI
76
155
 
77
156
  desc 'version', 'Display Github CLI version.'
78
157
  def version
79
- say "Github CLI #{GithubCLI::VERSION}"
158
+ GithubCLI.ui.info "#{GithubCLI.program_name} v#{GithubCLI::VERSION}"
80
159
  end
81
160
 
82
161
  end # CLI