github_cli 0.5.9 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (127) hide show
  1. data/.travis.yml +1 -0
  2. data/CHANGELOG.md +12 -1
  3. data/Gemfile.lock +12 -10
  4. data/README.md +18 -0
  5. data/features/authorization.feature +53 -0
  6. data/features/blob.feature +1 -1
  7. data/features/download.feature +13 -11
  8. data/features/gist.feature +9 -1
  9. data/features/label.feature +11 -12
  10. data/features/member.feature +5 -4
  11. data/features/merging.feature +5 -4
  12. data/features/organization.feature +5 -4
  13. data/features/repository.feature +9 -1
  14. data/features/search.feature +5 -4
  15. data/github_cli.gemspec +1 -1
  16. data/lib/github_cli/api.rb +56 -49
  17. data/lib/github_cli/apis/assignee.rb +6 -6
  18. data/lib/github_cli/apis/authorization.rb +5 -5
  19. data/lib/github_cli/apis/blob.rb +6 -6
  20. data/lib/github_cli/apis/collaborator.rb +12 -12
  21. data/lib/github_cli/apis/commit.rb +6 -6
  22. data/lib/github_cli/apis/content.rb +9 -9
  23. data/lib/github_cli/apis/download.rb +15 -15
  24. data/lib/github_cli/apis/email.rb +9 -9
  25. data/lib/github_cli/apis/event.rb +24 -24
  26. data/lib/github_cli/apis/follower.rb +16 -15
  27. data/lib/github_cli/apis/fork.rb +6 -6
  28. data/lib/github_cli/apis/gist.rb +31 -30
  29. data/lib/github_cli/apis/hook.rb +6 -6
  30. data/lib/github_cli/apis/issue.rb +12 -12
  31. data/lib/github_cli/apis/key.rb +15 -15
  32. data/lib/github_cli/apis/label.rb +24 -26
  33. data/lib/github_cli/apis/member.rb +15 -27
  34. data/lib/github_cli/apis/merging.rb +3 -3
  35. data/lib/github_cli/apis/milestone.rb +15 -15
  36. data/lib/github_cli/apis/notification.rb +18 -18
  37. data/lib/github_cli/apis/organization.rb +9 -9
  38. data/lib/github_cli/apis/pull_request.rb +24 -24
  39. data/lib/github_cli/apis/reference.rb +15 -15
  40. data/lib/github_cli/apis/repository.rb +13 -12
  41. data/lib/github_cli/apis/search.rb +12 -12
  42. data/lib/github_cli/apis/starring.rb +15 -15
  43. data/lib/github_cli/apis/status.rb +6 -6
  44. data/lib/github_cli/apis/tag.rb +6 -6
  45. data/lib/github_cli/apis/team.rb +39 -39
  46. data/lib/github_cli/apis/tree.rb +6 -6
  47. data/lib/github_cli/apis/user.rb +9 -9
  48. data/lib/github_cli/apis/watching.rb +15 -15
  49. data/lib/github_cli/cli.rb +24 -16
  50. data/lib/github_cli/commands/assignees.rb +8 -2
  51. data/lib/github_cli/commands/authorizations.rb +10 -13
  52. data/lib/github_cli/commands/blobs.rb +9 -3
  53. data/lib/github_cli/commands/collaborators.rb +16 -4
  54. data/lib/github_cli/commands/commits.rb +11 -6
  55. data/lib/github_cli/commands/contents.rb +9 -6
  56. data/lib/github_cli/commands/downloads.rb +30 -6
  57. data/lib/github_cli/commands/emails.rb +12 -3
  58. data/lib/github_cli/commands/events.rb +30 -8
  59. data/lib/github_cli/commands/followers.rb +20 -5
  60. data/lib/github_cli/commands/forks.rb +6 -4
  61. data/lib/github_cli/commands/gists.rb +39 -12
  62. data/lib/github_cli/commands/hooks.rb +1 -1
  63. data/lib/github_cli/commands/issues.rb +15 -4
  64. data/lib/github_cli/commands/keys.rb +20 -5
  65. data/lib/github_cli/commands/labels.rb +53 -14
  66. data/lib/github_cli/commands/members.rb +28 -9
  67. data/lib/github_cli/commands/merging.rb +3 -2
  68. data/lib/github_cli/commands/milestones.rb +27 -15
  69. data/lib/github_cli/commands/notifications.rb +19 -11
  70. data/lib/github_cli/commands/organizations.rb +24 -5
  71. data/lib/github_cli/commands/pull_requests.rb +30 -8
  72. data/lib/github_cli/commands/references.rb +17 -5
  73. data/lib/github_cli/commands/repositories.rb +6 -4
  74. data/lib/github_cli/commands/search.rb +24 -6
  75. data/lib/github_cli/commands/starring.rb +19 -5
  76. data/lib/github_cli/commands/statuses.rb +7 -3
  77. data/lib/github_cli/commands/tags.rb +7 -3
  78. data/lib/github_cli/commands/teams.rb +52 -17
  79. data/lib/github_cli/commands/trees.rb +6 -2
  80. data/lib/github_cli/commands/users.rb +9 -3
  81. data/lib/github_cli/commands/watching.rb +19 -5
  82. data/lib/github_cli/vendor/thor/actions/directory.rb +2 -0
  83. data/lib/github_cli/vendor/thor/actions/empty_directory.rb +3 -19
  84. data/lib/github_cli/vendor/thor/actions/file_manipulation.rb +4 -1
  85. data/lib/github_cli/vendor/thor/actions.rb +1 -1
  86. data/lib/github_cli/vendor/thor/base.rb +20 -18
  87. data/lib/github_cli/vendor/thor/command.rb +1 -1
  88. data/lib/github_cli/vendor/thor/error.rb +0 -4
  89. data/lib/github_cli/vendor/thor/group.rb +4 -9
  90. data/lib/github_cli/vendor/thor/runner.rb +1 -1
  91. data/lib/github_cli/vendor/thor/shell/basic.rb +25 -7
  92. data/lib/github_cli/vendor/thor/version.rb +1 -1
  93. data/lib/github_cli/vendor/thor.rb +17 -2
  94. data/lib/github_cli/version.rb +1 -1
  95. data/spec/github_cli/api/configure_spec.rb +50 -0
  96. data/spec/github_cli/api/github_api_spec.rb +19 -0
  97. data/spec/github_cli/commands/assignees_spec.rb +1 -1
  98. data/spec/github_cli/commands/blobs_spec.rb +1 -1
  99. data/spec/github_cli/commands/collaborators_spec.rb +1 -1
  100. data/spec/github_cli/commands/commits_spec.rb +1 -1
  101. data/spec/github_cli/commands/contents_spec.rb +1 -1
  102. data/spec/github_cli/commands/downloads_spec.rb +35 -0
  103. data/spec/github_cli/commands/emails_spec.rb +1 -1
  104. data/spec/github_cli/commands/events_spec.rb +1 -1
  105. data/spec/github_cli/commands/followers_spec.rb +1 -1
  106. data/spec/github_cli/commands/forks_spec.rb +1 -1
  107. data/spec/github_cli/commands/gists_spec.rb +6 -1
  108. data/spec/github_cli/commands/issues_spec.rb +1 -1
  109. data/spec/github_cli/commands/keys_spec.rb +1 -1
  110. data/spec/github_cli/commands/labels_spec.rb +13 -3
  111. data/spec/github_cli/commands/members_spec.rb +46 -0
  112. data/spec/github_cli/commands/merging_spec.rb +1 -1
  113. data/spec/github_cli/commands/milestones_spec.rb +1 -1
  114. data/spec/github_cli/commands/notifications_spec.rb +1 -1
  115. data/spec/github_cli/commands/organizations_spec.rb +30 -0
  116. data/spec/github_cli/commands/pull_requests_spec.rb +1 -1
  117. data/spec/github_cli/commands/references_spec.rb +1 -1
  118. data/spec/github_cli/commands/repositories_spec.rb +5 -0
  119. data/spec/github_cli/commands/starring_spec.rb +1 -1
  120. data/spec/github_cli/commands/statuses_spec.rb +1 -1
  121. data/spec/github_cli/commands/tags_spec.rb +1 -1
  122. data/spec/github_cli/commands/teams_spec.rb +1 -1
  123. data/spec/github_cli/commands/trees_spec.rb +1 -1
  124. data/spec/github_cli/commands/users_spec.rb +1 -1
  125. data/spec/github_cli/commands/watching_spec.rb +1 -1
  126. metadata +27 -17
  127. data/spec/github_cli/api_spec.rb +0 -19
@@ -7,12 +7,18 @@ module GithubCLI
7
7
 
8
8
  desc 'list <org>', "List teams"
9
9
  def list(org)
10
- Team.all org, options[:params], options[:format]
10
+ global_options = options.dup
11
+ params = options[:params].dup
12
+ Util.hash_without!(global_options, params.keys + ['params'])
13
+ Team.all org, params, global_options
11
14
  end
12
15
 
13
16
  desc 'get <id>', "Get a team"
14
17
  def get(id)
15
- Team.get id, options[:params], options[:format]
18
+ global_options = options.dup
19
+ params = options[:params].dup
20
+ Util.hash_without!(global_options, params.keys + ['params'])
21
+ Team.get id, params, global_options
16
22
  end
17
23
 
18
24
  option :name, :type => :string, :required => true
@@ -32,12 +38,13 @@ module GithubCLI
32
38
  * admin - team members can pull, push and administor these repositories.\n
33
39
  DESC
34
40
  def create(org)
41
+ global_options = options.dup
35
42
  params = options[:params].dup
36
- params['name'] = options[:name]
43
+ params['name'] = options[:name]
37
44
  params['repo_names'] = options[:repo_names] if options[:repo_names]
38
45
  params['permission'] = options[:permission] if options[:permission]
39
-
40
- Team.create org, params, options[:format]
46
+ Util.hash_without!(global_options, params.keys + ['params'])
47
+ Team.create org, params, global_options
41
48
  end
42
49
 
43
50
  option :name, :type => :string, :required => true
@@ -55,11 +62,12 @@ module GithubCLI
55
62
  * admin - team members can pull, push and administor these repositories.\n
56
63
  DESC
57
64
  def edit(id)
65
+ global_options = options.dup
58
66
  params = options[:params].dup
59
- params['name'] = options[:name]
67
+ params['name'] = options[:name]
60
68
  params['permission'] = options[:permission] if options[:permission]
61
-
62
- Team.edit id, params, options[:format]
69
+ Util.hash_without!(global_options, params.keys + ['params'])
70
+ Team.edit id, params, global_options
63
71
  end
64
72
 
65
73
  desc 'delete <id>', 'Delete team <id>'
@@ -67,12 +75,18 @@ module GithubCLI
67
75
  In order to delete a team, the authenticated user must be an owner of the org that the team is associated with.
68
76
  DESC
69
77
  def delete(id)
70
- Team.delete id, options[:params], options[:format]
78
+ global_options = options.dup
79
+ params = options[:params].dup
80
+ Util.hash_without!(global_options, params.keys + ['params'])
81
+ Team.delete id, params, global_options
71
82
  end
72
83
 
73
84
  desc 'list_member <id>', "List team <id> members"
74
85
  def list_member(id)
75
- Team.all_member id, options[:params], options[:format]
86
+ global_options = options.dup
87
+ params = options[:params].dup
88
+ Util.hash_without!(global_options, params.keys + ['params'])
89
+ Team.all_member id, params, global_options
76
90
  end
77
91
 
78
92
  desc 'member <id> <user>', 'Check if <user> is a team member'
@@ -80,7 +94,10 @@ module GithubCLI
80
94
  In order to get if a user is a member of a team, the authenticated user must be a member of the team.
81
95
  DESC
82
96
  def member(id, user)
83
- Team.member id, user, options[:params], options[:format]
97
+ global_options = options.dup
98
+ params = options[:params].dup
99
+ Util.hash_without!(global_options, params.keys + ['params'])
100
+ Team.member id, user, params, global_options
84
101
  end
85
102
 
86
103
  desc 'add_member <id> <user>', 'Add team member'
@@ -88,7 +105,10 @@ module GithubCLI
88
105
  In order to add a user to a team, the authenticated user must have ‘admin’ permissions to the team or be an owner of the org that the team is associated with.
89
106
  DESC
90
107
  def add_member(id, user)
91
- Team.add_member id, user, options[:params], options[:format]
108
+ global_options = options.dup
109
+ params = options[:params].dup
110
+ Util.hash_without!(global_options, params.keys + ['params'])
111
+ Team.add_member id, user, params, global_options
92
112
  end
93
113
 
94
114
  desc 'remove_member <id> <user>', 'Remove team member'
@@ -99,17 +119,26 @@ module GithubCLI
99
119
  them from the team.
100
120
  DESC
101
121
  def remove_member(id, user)
102
- Team.remove_member id, user, options[:params], options[:format]
122
+ global_options = options.dup
123
+ params = options[:params].dup
124
+ Util.hash_without!(global_options, params.keys + ['params'])
125
+ Team.remove_member id, user, params, global_options
103
126
  end
104
127
 
105
128
  desc 'list_repo <id>', "List team <id> repositories"
106
129
  def list_repo(id)
107
- Team.all_repo id, options[:params], options[:format]
130
+ global_options = options.dup
131
+ params = options[:params].dup
132
+ Util.hash_without!(global_options, params.keys + ['params'])
133
+ Team.all_repo id, params, global_options
108
134
  end
109
135
 
110
136
  desc 'repo <id> <user> <repo>', 'Check if <repo> is managed by team <id>'
111
137
  def repo(id, user, repo)
112
- Team.repo id, user, repo, options[:params], options[:format]
138
+ global_options = options.dup
139
+ params = options[:params].dup
140
+ Util.hash_without!(global_options, params.keys + ['params'])
141
+ Team.repo id, user, repo, params, global_options
113
142
  end
114
143
 
115
144
  desc 'add_repo <id> <user> <repo>', 'Add team <repo>'
@@ -119,7 +148,10 @@ module GithubCLI
119
148
  by the organization, or a direct for of a repo owned by the organization.
120
149
  DESC
121
150
  def add_repo(id, user, repo)
122
- Team.add_repo id, user, repo, options[:params], options[:format]
151
+ global_options = options.dup
152
+ params = options[:params].dup
153
+ Util.hash_without!(global_options, params.keys + ['params'])
154
+ Team.add_repo id, user, repo, params, global_options
123
155
  end
124
156
 
125
157
  desc 'remove_repo <id> <user> <repo>', 'Remove team <repo>'
@@ -129,7 +161,10 @@ module GithubCLI
129
161
  delete the repo, it just removes it from the team.
130
162
  DESC
131
163
  def remove_repo(id, user, repo)
132
- Team.remove_repo id, user, repo, options[:params], options[:format]
164
+ global_options = options.dup
165
+ params = options[:params].dup
166
+ Util.hash_without!(global_options, params.keys + ['params'])
167
+ Team.remove_repo id, user, repo, params, global_options
133
168
  end
134
169
 
135
170
  end # Teams
@@ -9,9 +9,11 @@ module GithubCLI
9
9
  method_option :recursive, :type => :boolean, :aliases => ["-r"],
10
10
  :desc => 'get a tree recursively'
11
11
  def get(user, repo, sha)
12
+ global_options = options.dup
12
13
  params = options[:params].dup
13
14
  params['recursive'] = options[:recursive] if options[:recursive]
14
- Tree.get user, repo, sha, params, options[:format]
15
+ Util.hash_without!(global_options, params.keys + ['params'])
16
+ Tree.get user, repo, sha, params, global_options
15
17
  end
16
18
 
17
19
  desc 'create <user> <repo>', 'Create a new Tree'
@@ -36,10 +38,12 @@ module GithubCLI
36
38
  tree.content - String of content you want this file to have - GitHub will write this blob out and use the SHA for this entry. Use either this or tree.sha
37
39
  DESC
38
40
  def create(user, repo)
41
+ global_options = options.dup
39
42
  params = options[:params].dup
40
43
  params['base_tree'] = options[:base_tree] if options[:base_tree]
41
44
  params['tree'] = options[:tree] if options[:tree]
42
- Tree.create user, repo, params, options[:format]
45
+ Util.hash_without!(global_options, params.keys + ['params'])
46
+ Tree.create user, repo, params, global_options
43
47
  end
44
48
 
45
49
  end # Blobs
@@ -9,9 +9,11 @@ module GithubCLI
9
9
  option :since, :type => :string, :banner => "<user>",
10
10
  :desc => "The integer ID of the last User that you’ve seen."
11
11
  def list
12
+ global_options = options.dup
12
13
  params = options[:params].dup
13
14
  params['since'] = options[:since] if options[:since]
14
- User.all params, options[:format]
15
+ Util.hash_without!(global_options, params.keys + ['params'])
16
+ User.all params, global_options
15
17
  end
16
18
 
17
19
  desc 'get', 'Get the authenticated user'
@@ -19,9 +21,11 @@ module GithubCLI
19
21
  :desc => 'Get a single unauthenticated <user>',
20
22
  :banner => '<user>'
21
23
  def get
24
+ global_options = options.dup
22
25
  params = options[:params].dup
23
26
  params['user'] = options[:user] if options[:user]
24
- User.get params, options[:format]
27
+ Util.hash_without!(global_options, params.keys + ['params'])
28
+ User.get params, global_options
25
29
  end
26
30
 
27
31
  desc 'update', 'Update the authenticated user'
@@ -33,6 +37,7 @@ module GithubCLI
33
37
  option :hireable, :type => :string
34
38
  option :bio, :type => :string
35
39
  def update
40
+ global_options = options.dup
36
41
  params = options[:params].dup
37
42
  params['name'] = options[:name] if options[:name]
38
43
  params['email'] = options[:email] if options[:email]
@@ -41,7 +46,8 @@ module GithubCLI
41
46
  params['location'] = options[:location] if options[:location]
42
47
  params['hireable'] = options[:hireable] if options[:hireable]
43
48
  params['bio'] = options[:bio] if options[:bio]
44
- User.update params, options[:format]
49
+ Util.hash_without!(global_options, params.keys + ['params'])
50
+ User.update params, global_options
45
51
  end
46
52
 
47
53
  end # Users
@@ -7,33 +7,47 @@ module GithubCLI
7
7
 
8
8
  desc 'list <user> <repo>', 'Lists repo watchers'
9
9
  def list(user, repo)
10
- Watching.list user, repo, options[:params], options[:format]
10
+ global_options = options.dup
11
+ params = options[:params].dup
12
+ Util.hash_without!(global_options, params.keys + ['params'])
13
+ Watching.list user, repo, params, global_options
11
14
  end
12
15
 
13
16
  desc 'watched', 'Lists repos being watched by a user'
14
17
  method_option :user, :type => :string, :aliases => ["-u"],
15
18
  :desc => 'Watch repositories for <user>'
16
19
  def watched
20
+ global_options = options.dup
17
21
  params = options[:params].dup
18
22
  if options[:user]
19
23
  params['user'] = options[:user]
20
24
  end
21
- Watching.watched params, options[:format]
25
+ Util.hash_without!(global_options, params.keys + ['params'])
26
+ Watching.watched params, global_options
22
27
  end
23
28
 
24
29
  desc 'watching <user> <repo>', 'Check if you are watching a repository'
25
30
  def watching(user, repo)
26
- Watching.watching? user, repo, options[:params], options[:format]
31
+ global_options = options.dup
32
+ params = options[:params].dup
33
+ Util.hash_without!(global_options, params.keys + ['params'])
34
+ Watching.watching? user, repo, params, global_options
27
35
  end
28
36
 
29
37
  desc 'start <user> <repo>', 'Watch a repository'
30
38
  def start(user, repo)
31
- Watching.start user, repo, options[:params], options[:format]
39
+ global_options = options.dup
40
+ params = options[:params].dup
41
+ Util.hash_without!(global_options, params.keys + ['params'])
42
+ Watching.start user, repo, params, global_options
32
43
  end
33
44
 
34
45
  desc 'stop <user> <repo>', 'Stop watching a repository'
35
46
  def stop(user, repo)
36
- Watching.stop user, repo, options[:params], options[:format]
47
+ global_options = options.dup
48
+ params = options[:params].dup
49
+ Util.hash_without!(global_options, params.keys + ['params'])
50
+ Watching.stop user, repo, params, global_options
37
51
  end
38
52
 
39
53
  end # Watching
@@ -39,6 +39,7 @@ class Thor
39
39
  # config<Hash>:: give :verbose => false to not log the status.
40
40
  # If :recursive => false, does not look for paths recursively.
41
41
  # If :mode => :preserve, preserve the file mode from the source.
42
+ # If :exclude_pattern => /regexp/, prevents copying files that match that regexp.
42
43
  #
43
44
  # ==== Examples
44
45
  #
@@ -78,6 +79,7 @@ class Thor
78
79
 
79
80
  files(lookup).sort.each do |file_source|
80
81
  next if File.directory?(file_source)
82
+ next if config[:exclude_pattern] && file_source.match(config[:exclude_pattern])
81
83
  file_destination = File.join(given_destination, file_source.gsub(source, '.'))
82
84
  file_destination.gsub!('/./', '/')
83
85
 
@@ -97,28 +97,12 @@ class Thor
97
97
  #
98
98
  # user.rb
99
99
  #
100
- # The method referenced by %-string SHOULD be public. Otherwise you
101
- # get the exception with the corresponding error message.
100
+ # The method referenced can be either public or private.
102
101
  #
103
102
  def convert_encoded_instructions(filename)
104
103
  filename.gsub(/%(.*?)%/) do |initial_string|
105
- call_public_method($1.strip) or initial_string
106
- end
107
- end
108
-
109
- # Calls `base`'s public method `sym`.
110
- # Returns:: result of `base.sym` or `nil` if `sym` wasn't found in
111
- # `base`
112
- # Raises:: Thor::PrivateMethodEncodedError if `sym` references
113
- # a private method.
114
- def call_public_method(sym)
115
- if base.respond_to?(sym)
116
- base.send(sym)
117
- elsif base.respond_to?(sym, true)
118
- raise Thor::PrivateMethodEncodedError,
119
- "Method #{base.class}##{sym} should be public, not private"
120
- else
121
- nil
104
+ method = $1.strip
105
+ base.respond_to?(method, true) ? base.send(method) : initial_string
122
106
  end
123
107
  end
124
108
 
@@ -293,8 +293,11 @@ class Thor
293
293
  end
294
294
  alias :remove_dir :remove_file
295
295
 
296
+ attr_accessor :output_buffer
297
+ private :output_buffer, :output_buffer=
298
+
296
299
  private
297
- attr_accessor :output_buffer
300
+
298
301
  def concat(string)
299
302
  @output_buffer.concat(string)
300
303
  end
@@ -227,7 +227,7 @@ class Thor
227
227
  # ==== Parameters
228
228
  # command<String>:: the command to be executed.
229
229
  # config<Hash>:: give :verbose => false to not log the status, :capture => true to hide to output. Specify :with
230
- # to append an executable to command executation.
230
+ # to append an executable to command execution.
231
231
  #
232
232
  # ==== Example
233
233
  #
@@ -119,6 +119,18 @@ class Thor
119
119
  end
120
120
 
121
121
  module ClassMethods
122
+ def attr_reader(*) #:nodoc:
123
+ no_commands { super }
124
+ end
125
+
126
+ def attr_writer(*) #:nodoc:
127
+ no_commands { super }
128
+ end
129
+
130
+ def attr_accessor(*) #:nodoc:
131
+ no_commands { super }
132
+ end
133
+
122
134
  # If you want to raise an error for unknown options, call check_unknown_options!
123
135
  # This is disabled by default to allow dynamic invocations.
124
136
  def check_unknown_options!
@@ -406,11 +418,10 @@ class Thor
406
418
  # thor :my_command
407
419
  #
408
420
  def namespace(name=nil)
409
- @namespace = case name
410
- when nil
411
- @namespace || Thor::Util.namespace_from_thor_class(self)
412
- else
421
+ if name
413
422
  @namespace = name.to_s
423
+ else
424
+ @namespace ||= Thor::Util.namespace_from_thor_class(self)
414
425
  end
415
426
  end
416
427
 
@@ -462,17 +473,11 @@ class Thor
462
473
  end
463
474
  alias handle_no_task_error handle_no_command_error
464
475
 
465
- def handle_argument_error(command, error, arity=nil) #:nodoc:
466
- msg = "#{basename} #{command.name}"
467
- if arity && arity != 0
468
- required = arity < 0 ? (-1 - arity) : arity
469
- msg << " requires at least #{required} argument"
470
- msg << "s" if required > 1
471
- else
472
- msg = "call #{msg} as"
473
- end
474
-
475
- msg << ": #{self.banner(command).inspect}."
476
+ def handle_argument_error(command, error, args, arity) #:nodoc:
477
+ msg = "ERROR: #{basename} #{command.name} was called with "
478
+ msg << 'no arguments' if args.empty?
479
+ msg << 'arguments ' << args.inspect if !args.empty?
480
+ msg << "\nUsage: #{self.banner(command).inspect}."
476
481
  raise InvocationError, msg
477
482
  end
478
483
 
@@ -584,9 +589,6 @@ class Thor
584
589
  # Return if it's not a public instance method
585
590
  return unless public_method_defined?(meth.to_sym)
586
591
 
587
- # Return if attr_* added the method
588
- return if caller.first.to_s[/`attr_(reader|writer|accessor)'/]
589
-
590
592
  return if @no_commands || !create_command(meth)
591
593
 
592
594
  is_thor_reserved_word?(meth, :command)
@@ -32,7 +32,7 @@ class Thor
32
32
  end
33
33
  rescue ArgumentError => e
34
34
  handle_argument_error?(instance, e, caller) ?
35
- instance.class.handle_argument_error(self, e, arity) : (raise e)
35
+ instance.class.handle_argument_error(self, e, args, arity) : (raise e)
36
36
  rescue NoMethodError => e
37
37
  handle_no_method_error?(instance, e, caller) ?
38
38
  instance.class.handle_no_command_error(name) : (raise e)
@@ -25,8 +25,4 @@ class Thor
25
25
 
26
26
  class MalformattedArgumentError < InvocationError
27
27
  end
28
-
29
- # Raised when a user tries to call a private method encoded in templated filename.
30
- class PrivateMethodEncodedError < Error
31
- end
32
28
  end
@@ -205,15 +205,10 @@ class Thor::Group
205
205
  end
206
206
  alias printable_tasks printable_commands
207
207
 
208
- def handle_argument_error(command, error, arity=nil) #:nodoc:
209
- if arity > 0
210
- msg = "#{basename} #{command.name} takes #{arity} argument"
211
- msg << "s" if arity > 1
212
- msg << ", but it should not."
213
- else
214
- msg = "You should not pass arguments to #{basename} #{command.name}."
215
- end
216
-
208
+ def handle_argument_error(command, error, args, arity) #:nodoc:
209
+ msg = "#{basename} #{command.name} takes #{arity} argument"
210
+ msg << "s" if arity > 1
211
+ msg << ", but it should not."
217
212
  raise error, msg
218
213
  end
219
214
 
@@ -206,7 +206,7 @@ class Thor::Runner < Thor #:nodoc:
206
206
  # in the thor_root instead of loading them all.
207
207
  #
208
208
  # By default, it also traverses the current path until find Thor files, as
209
- # described in thorfiles. This look up can be skipped by suppliying
209
+ # described in thorfiles. This look up can be skipped by supplying
210
210
  # skip_lookup true.
211
211
  #
212
212
  def initialize_thorfiles(relevant_to=nil, skip_lookup=false)
@@ -47,8 +47,13 @@ class Thor
47
47
  #
48
48
  def ask(statement, *args)
49
49
  options = args.last.is_a?(Hash) ? args.pop : {}
50
+ color = args.first
50
51
 
51
- options[:limited_to] ? ask_filtered(statement, options[:limited_to], *args) : ask_simply(statement, *args)
52
+ if options[:limited_to]
53
+ ask_filtered(statement, color, options)
54
+ else
55
+ ask_simply(statement, color, options)
56
+ end
52
57
  end
53
58
 
54
59
  # Say (print) something to the user. If the sentence ends with a whitespace
@@ -372,17 +377,30 @@ HELP
372
377
  end
373
378
  end
374
379
 
375
- def ask_simply(statement, color=nil)
376
- say("#{statement} ", color)
377
- stdin.gets.tap{|text| text.strip! if text}
380
+ def ask_simply(statement, color, options)
381
+ default = options[:default]
382
+ message = [statement, ("(#{default})" if default), nil].uniq.join(" ")
383
+ say(message, color)
384
+ result = stdin.gets
385
+
386
+ return unless result
387
+
388
+ result.strip!
389
+
390
+ if default && result == ""
391
+ default
392
+ else
393
+ result
394
+ end
378
395
  end
379
396
 
380
- def ask_filtered(statement, answer_set, *args)
397
+ def ask_filtered(statement, color, options)
398
+ answer_set = options[:limited_to]
381
399
  correct_answer = nil
382
400
  until correct_answer
383
- answer = ask_simply("#{statement} #{answer_set.inspect}", *args)
401
+ answers = answer_set.join(", ")
402
+ answer = ask_simply("#{statement} [#{answers}]", color, options)
384
403
  correct_answer = answer_set.include?(answer) ? answer : nil
385
- answers = answer_set.map(&:inspect).join(", ")
386
404
  say("Your response must be one of: [#{answers}]. Please try again.") unless correct_answer
387
405
  end
388
406
  correct_answer
@@ -1,3 +1,3 @@
1
1
  class Thor
2
- VERSION = "0.17.0"
2
+ VERSION = "0.18.1"
3
3
  end
@@ -3,6 +3,16 @@ require 'thor/base'
3
3
 
4
4
  class Thor
5
5
  class << self
6
+ # Allows for custom "Command" package naming.
7
+ #
8
+ # === Parameters
9
+ # name<String>
10
+ # options<Hash>
11
+ #
12
+ def package_name(name, options={})
13
+ @package_name = name.nil? || name == '' ? nil : name
14
+ end
15
+
6
16
  # Sets the default command when thor is executed without an explicit command to be called.
7
17
  #
8
18
  # ==== Parameters
@@ -185,7 +195,12 @@ class Thor
185
195
  end
186
196
  list.sort!{ |a,b| a[0] <=> b[0] }
187
197
 
188
- shell.say "Commands:"
198
+ if @package_name
199
+ shell.say "#{@package_name} commands:"
200
+ else
201
+ shell.say "Commands:"
202
+ end
203
+
189
204
  shell.print_table(list, :indent => 2, :truncate => true)
190
205
  shell.say
191
206
  class_options_help(shell)
@@ -299,7 +314,7 @@ class Thor
299
314
  end
300
315
 
301
316
  def stop_on_unknown_option?(command) #:nodoc:
302
- !!@stop_on_unknown_option && @stop_on_unknown_option.include?(command.name.to_sym)
317
+ command && !@stop_on_unknown_option.nil? && @stop_on_unknown_option.include?(command.name.to_sym)
303
318
  end
304
319
 
305
320
  protected
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module GithubCLI
4
- VERSION = "0.5.9"
4
+ VERSION = "0.6.0"
5
5
  end
@@ -0,0 +1,50 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe GithubCLI::API, '#configure' do
6
+ let(:object) { described_class }
7
+
8
+ before {
9
+ GithubCLI.stub(:config).and_return(config)
10
+ }
11
+
12
+ subject { object.configure }
13
+
14
+ context 'with default' do
15
+ let(:config) { { } }
16
+
17
+ its(:adapter) { should eql(:net_http) }
18
+
19
+ its(:ssl) { should eql({}) }
20
+
21
+ its(:site) { should eql('https://github.com') }
22
+
23
+ its(:endpoint) { should eql('https://api.github.com') }
24
+
25
+ its(:oauth_token) { should be_nil }
26
+ end
27
+
28
+ context 'with config values' do
29
+ let(:config) {
30
+ {
31
+ 'core.ssl' => {"verify" => false},
32
+ 'core.adapter' => :patron,
33
+ 'core.site' => 'http://site.com',
34
+ 'core.endpoint' => 'http://api.com',
35
+ 'user.token' => 'abc1234'
36
+ }
37
+ }
38
+
39
+ its(:adapter) { should eql(:patron) }
40
+
41
+ its(:ssl) { should eql({"verify" => false})}
42
+
43
+ its(:site) { should eql('http://site.com')}
44
+
45
+ its(:endpoint) { should eql('http://api.com') }
46
+
47
+ its(:oauth_token) { should eql('abc1234') }
48
+ end
49
+
50
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe GithubCLI::API, '#gihtub_api' do
4
+ before {
5
+ described_class.send(:instance_variable_set, :@github_api, nil)
6
+ }
7
+
8
+ it 'sets up github api connection' do
9
+ github_instance = stub.as_null_object
10
+ Github.should_receive(:new).and_return github_instance
11
+ expect(described_class.github_api).to eql(github_instance)
12
+ end
13
+
14
+ it 'does not instantiate on subsequent calls' do
15
+ described_class.github_api
16
+ Github.should_receive(:new).exactly(0).times
17
+ described_class.github_api
18
+ end
19
+ end # GithubCLI::API
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GithubCLI::Commands::Assignees do
6
- let(:format) { 'table' }
6
+ let(:format) { {'format' => 'table'} }
7
7
  let(:user) { 'peter-murach' }
8
8
  let(:repo) { 'github_cli' }
9
9
  let(:api_class) { GithubCLI::Assignee }
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GithubCLI::Commands::Blobs do
6
- let(:format) { 'table' }
6
+ let(:format) { {'format' => 'table'} }
7
7
  let(:user) { 'peter-murach' }
8
8
  let(:repo) { 'github_cli' }
9
9
  let(:sha) { '3a0f86fb8db8eea7ccbb9a95f325ddbedfb25e15' }