github_cli 0.5.8 → 0.5.9

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.
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.9 (April , 2013)
2
+
3
+ * Change API class configure to take options and allow for basic auth,
4
+ stop using class api variable
5
+ * Change API commands to take and pass options for global configuration
6
+
1
7
  0.5.8 (April 14, 2013)
2
8
 
3
9
  * Change forks commands to take specific options and add tests
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- github_cli (0.5.8)
4
+ github_cli (0.5.9)
5
5
  github_api (~> 0.9)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -93,7 +93,9 @@ $ gcli help config
93
93
 
94
94
  ### Authorization
95
95
 
96
- To create oauth tokens you need to setup your basic authentication like so
96
+ To create oauth tokens you need to setup your basic authentication.
97
+
98
+ You can either set it up manually like so
97
99
 
98
100
  ```shell
99
101
  $ gcli init
@@ -107,12 +109,24 @@ Then to create your token do
107
109
  $ gcli auth create --scopes=repo --note=gihtub_cli --note-url=http://github.com/peter-murach/github_cli
108
110
  ```
109
111
 
112
+ Alternatively `authorize` command has been provided that will guide you through authentication process by asking questions and then save the crednetials to `.githubrc` file. Example
113
+
114
+ ```shell
115
+ $ gcli authorize
116
+ ```
117
+
110
118
  To see your current tokens do
111
119
 
112
120
  ```shell
113
121
  $ gcli auth ls
114
122
  ```
115
123
 
124
+ To see current tokens without configuration file pass `--login` and `--password` flags like so
125
+
126
+ ```shell
127
+ $ gcli auth ls --login=... --password=...
128
+ ```
129
+
116
130
  Finally to add the token to your config do
117
131
 
118
132
  ```shell
@@ -5,58 +5,65 @@ module GithubCLI
5
5
  # The API class is the main entry point for creating GithubCLI APIs.
6
6
  class API
7
7
 
8
- @@api = nil
9
-
10
8
  class << self
11
9
 
12
- attr_reader :config
13
-
14
- def github_api
15
- @@api ||= begin
16
- @@api = configure_api
10
+ # Access or initialize Github API client
11
+ #
12
+ # @api public
13
+ def github_api(options={})
14
+ @github_api ||= begin
15
+ @github_api = configure(options)
17
16
  end
18
17
  end
19
18
 
20
- # see http://stackoverflow.com/questions/5729071/how-to-compose-thor-tasks-in-separate-classes-modules-files
21
-
22
19
  # this could become a command such as configure that gets class options
23
-
24
- def configure_api
25
- @@api = Github.new
20
+ #
21
+ # @api public
22
+ def configure(options={})
23
+ api = Github.new
26
24
  config = GithubCLI.config.data
27
25
 
28
- if config['user.token']
29
- @@api.oauth_token = config['user.token']
30
- end
31
- if config['user.login'] && config['user.password']
32
- @@api.basic_auth = "#{config['user.login']}:#{config['user.password']}"
33
- end
34
- @@api.endpoint = GithubCLI.config['core.endpoint'] || @@api.endpoint
26
+ api.oauth_token = config['user.token'] if config['user.token']
27
+
28
+ api.basic_auth = set_basic_auth(config, options)
29
+
30
+ api.endpoint = config['core.endpoint'] if config['core.endpoint']
31
+
35
32
  if ENV['TEST_HOST']
36
- @@api.endpoint = 'http://' + ENV['TEST_HOST']
33
+ api.endpoint = 'http://' + ENV['TEST_HOST']
34
+ end
35
+ api
36
+ end
37
+
38
+ # Set user basic authentication
39
+ #
40
+ # @api public
41
+ def set_basic_auth(config, options)
42
+ if options['login'] && options['password']
43
+ "#{options['login']}:#{options['password']}"
44
+ elsif config['user.login'] && config['user.password']
45
+ "#{config['user.login']}:#{config['user.password']}"
46
+ else
47
+ nil
37
48
  end
38
- @@api
39
49
  end
40
50
 
41
- def output(format=:table, &block)
42
- # GithubCLI.on_error do
51
+ # Procoess response and output to shell
52
+ # TODO: change to take options
53
+ # @api public
54
+ def output(format=:table, quiet=false, &block)
55
+ GithubCLI.on_error do
43
56
  response = block.call
44
57
  if response.respond_to?(:body)
45
- formatter = Formatter.new response, :format => format
58
+ formatter = Formatter.new response, :format => format, :quiet => quiet
46
59
  formatter.render_output
47
60
  else
48
61
  response
49
62
  end
50
- # end
63
+ end
51
64
  end
52
65
 
53
66
  end
54
67
 
55
- class All
56
- def initialize(params)
57
- puts Github::Repos.new.all params
58
- end
59
- end
60
-
61
68
  end # API
62
69
  end # GithubCLI
@@ -5,33 +5,33 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(params, format)
9
- output format do
10
- github_api.oauth.list params
8
+ def all(params, options)
9
+ output options[:format], options[:quiet] do
10
+ github_api(options).oauth.list params
11
11
  end
12
12
  end
13
13
 
14
- def get(id, params, format)
15
- output format do
16
- github_api.oauth.get id, params
14
+ def get(id, params, options)
15
+ output options[:format], options[:quiet] do
16
+ github_api(options).oauth.get id, params
17
17
  end
18
18
  end
19
19
 
20
- def create(params, format)
21
- output format do
22
- github_api.oauth.create params
20
+ def create(params, options)
21
+ output options[:format], options[:quiet] do
22
+ github_api(options).oauth.create params
23
23
  end
24
24
  end
25
25
 
26
- def update(id, params, format)
27
- output format do
28
- github_api.oauth.update id, params
26
+ def update(id, params, options)
27
+ output options[:format], options[:quiet] do
28
+ github_api(options).oauth.update id, params
29
29
  end
30
30
  end
31
31
 
32
- def delete(id, params, format)
33
- output format do
34
- github_api.oauth.delete id, params
32
+ def delete(id, params, options)
33
+ output options[:format], options[:quiet] do
34
+ github_api(options).oauth.delete id, params
35
35
  end
36
36
  end
37
37
  end
@@ -5,39 +5,39 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(user, repo, params, format)
9
- output format do
10
- github_api.repos.hooks.list user, repo, params
8
+ def all(user, repo, params, options)
9
+ output options[:format], options[:quiet] do
10
+ github_api(options).repos.hooks.list user, repo, params
11
11
  end
12
12
  end
13
13
 
14
- def get(user, repo, id, params, format)
15
- output format do
16
- github_api.repos.hooks.get user, repo, id, params
14
+ def get(user, repo, id, params, options)
15
+ output options[:format], options[:quiet] do
16
+ github_api(options).repos.hooks.get user, repo, id, params
17
17
  end
18
18
  end
19
19
 
20
- def create(user, repo, params, format)
21
- output format do
22
- github_api.repos.hooks.create user, repo, params
20
+ def create(user, repo, params, options)
21
+ output options[:format], options[:quiet] do
22
+ github_api(options).repos.hooks.create user, repo, params
23
23
  end
24
24
  end
25
25
 
26
- def edit(user, repo, id, params, format)
27
- output format do
28
- github_api.repos.hooks.edit user, repo, id, params
26
+ def edit(user, repo, id, params, options)
27
+ output options[:format], options[:quiet] do
28
+ github_api(options).repos.hooks.edit user, repo, id, params
29
29
  end
30
30
  end
31
31
 
32
- def test(user, repo, id, params, format)
33
- output format do
34
- github_api.repos.hooks.test user, repo, id, params
32
+ def test(user, repo, id, params, options)
33
+ output options[:format], options[:quiet] do
34
+ github_api(options).repos.hooks.test user, repo, id, params
35
35
  end
36
36
  end
37
37
 
38
- def delete(user, repo, id, params, format)
39
- output format do
40
- github_api.repos.hooks.delete user, repo, id, params
38
+ def delete(user, repo, id, params, options)
39
+ output options[:format], options[:quiet] do
40
+ github_api(options).repos.hooks.delete user, repo, id, params
41
41
  end
42
42
  end
43
43
  end
@@ -5,69 +5,69 @@ module GithubCLI
5
5
 
6
6
  class << self
7
7
 
8
- def all(params, format)
9
- output format do
10
- github_api.repos.list params
8
+ def all(params, options)
9
+ output options[:format], options[:quiet] do
10
+ github_api(options).repos.list params
11
11
  end
12
12
  end
13
13
 
14
- def get(user, repo, params, format)
15
- output format do
16
- github_api.repos.get user, repo, params
14
+ def get(user, repo, params, options)
15
+ output options[:format], options[:quiet] do
16
+ github_api(options).repos.get user, repo, params
17
17
  end
18
18
  end
19
19
 
20
- def create(params, format)
21
- output format do
22
- github_api.repos.create params
20
+ def create(params, options)
21
+ output options[:format], options[:quiet] do
22
+ github_api(options).repos.create params
23
23
  end
24
24
  end
25
25
 
26
- def edit(user, repo, params, format)
27
- output format do
28
- github_api.repos.edit user, repo, params
26
+ def edit(user, repo, params, options)
27
+ output options[:format], options[:quiet] do
28
+ github_api(options).repos.edit user, repo, params
29
29
  end
30
30
  end
31
31
 
32
- def delete(user, repo, params, format)
33
- output format do
34
- github_api.repos.delete user, repo, params
32
+ def delete(user, repo, params, options)
33
+ output options[:format], options[:quiet] do
34
+ github_api(options).repos.delete user, repo, params
35
35
  end
36
36
  end
37
37
 
38
- def branches(user, repo, params, format)
39
- output format do
40
- github_api.repos.branches user, repo, params
38
+ def branches(user, repo, params, options)
39
+ output options[:format], options[:quiet] do
40
+ github_api(options).repos.branches user, repo, params
41
41
  end
42
42
  end
43
43
 
44
- def branch(user, repo, name, params, format)
45
- output format do
46
- github_api.repos.branch user, repo, name, params
44
+ def branch(user, repo, name, params, options)
45
+ output options[:format], options[:quiet] do
46
+ github_api(options).repos.branch user, repo, name, params
47
47
  end
48
48
  end
49
49
 
50
- def contributors(user, repo, params, format)
51
- output format do
52
- github_api.repos.contributors user, repo, params
50
+ def contributors(user, repo, params, options)
51
+ output options[:format], options[:quiet] do
52
+ github_api(options).repos.contributors user, repo, params
53
53
  end
54
54
  end
55
55
 
56
- def languages(user, repo, params, format)
57
- output format do
58
- github_api.repos.languages user, repo, params
56
+ def languages(user, repo, params, options)
57
+ output options[:format], options[:quiet] do
58
+ github_api(options).repos.languages user, repo, params
59
59
  end
60
60
  end
61
61
 
62
- def tags(user, repo, params, format)
63
- output format do
62
+ def tags(user, repo, params, options)
63
+ output options[:format], options[:quiet] do
64
64
  github_api.repos.tags user, repo, params
65
65
  end
66
66
  end
67
67
 
68
- def teams(user, repo, params, format)
69
- output format do
70
- github_api.repos.teams user, repo, params
68
+ def teams(user, repo, params, options)
69
+ output options[:format], options[:quiet] do
70
+ github_api(options).repos.teams user, repo, params
71
71
  end
72
72
  end
73
73
  end
@@ -24,6 +24,8 @@ module GithubCLI
24
24
 
25
25
  map ALIASES
26
26
 
27
+ # can extract class options into global options module
28
+
27
29
  class_option :filename, :type => :string,
28
30
  :desc => "Configuration file name.", :banner => "<filename>",
29
31
  :default => ".githubrc"
@@ -39,6 +41,8 @@ module GithubCLI
39
41
  class_option :pager, :type => :string, :aliases => '-p',
40
42
  :desc => "Command to be used for paging.",
41
43
  :banner => "less|more|..."
44
+ class_option :quiet, :type => :boolean, :aliases => "-q",
45
+ :desc => "Suppress response output"
42
46
  class_option :verbose, :type => :boolean,
43
47
  :desc => "Enable verbose output mode."
44
48
  class_option :version, :type => :boolean, :aliases => ['-V'],
@@ -79,12 +83,23 @@ module GithubCLI
79
83
  You may use this command to change your details.
80
84
  DESC
81
85
  def authorize
86
+ global_options = options.dup
82
87
  params = {}
83
- params['scopes'] = options[:scopes] || %w(public_repo repo)
84
- params['note'] = options[:note] || 'github_cli'
88
+ params['scopes'] = options[:scopes] || %w(public_repo repo)
89
+ params['note'] = options[:note] || 'github_cli'
85
90
  params['note_url'] = options[:note_url] || 'https://github.com/peter-murach/github_cli'
91
+ global_options[:params] = params
86
92
  # Need to configure client with login and password
87
- res = self.invoke("auth:create", [], params)
93
+ print 'OPTIONS '
94
+ p options
95
+ login = ask("login: ")
96
+ password = ask("password: ")
97
+
98
+ global_options['login'] = login
99
+ global_options['password'] = password
100
+ global_options['quiet'] = true
101
+
102
+ res = self.invoke("auth:create", [], global_options)
88
103
  token = res.body['token']
89
104
 
90
105
  config = GithubCLI.config
@@ -39,24 +39,17 @@ module GithubCLI
39
39
  }
40
40
  map ALIASES
41
41
 
42
- class_option :params, :type => :hash, :default => {}, :aliases => '-p',
43
- :desc => 'Request parameters e.i per_page:100'
44
-
45
42
  class_option :format, :type => :string, :aliases => '-f',
46
43
  :default => 'table',
47
44
  :banner => output_formats.keys.join('|'),
48
45
  :desc => "Format of the output. Type table:h to display table horizontally."
46
+ class_option :quiet, :type => :boolean, :aliases => "-q",
47
+ :desc => "Suppress response output"
49
48
 
50
- class << self
49
+ class_option :params, :type => :hash, :default => {}, :aliases => '-p',
50
+ :desc => 'Request parameters e.i per_page:100'
51
51
 
52
- def api(name=nil)
53
- @api = case name
54
- when nil
55
- @api || GithubCLI.const_get(name.to_s.capitalize)
56
- else
57
- @pi
58
- end
59
- end
52
+ class << self
60
53
 
61
54
  def banner(task, namespace=true, subcommand=true)
62
55
  "#{basename} #{task.formatted_usage(self, true, subcommand)}"
@@ -10,7 +10,10 @@ module GithubCLI
10
10
  You can only list your own tokens, and only through Basic Authentication.
11
11
  DESC
12
12
  def list
13
- Authorization.all options[:params], options[:format]
13
+ global_options = options.dup
14
+ params = global_options[:params].dup
15
+ Util.hash_without!(global_options, %w[ params ])
16
+ Authorization.all params, global_options
14
17
  end
15
18
 
16
19
  desc 'get <id>', 'Get a single authorization'
@@ -18,7 +21,10 @@ module GithubCLI
18
21
  You can only access your own token, and only through Basic Authentication.
19
22
  DESC
20
23
  def get(id)
21
- Authorization.get id, options[:params], options[:format]
24
+ global_options = options.dup
25
+ params = global_options[:params].dup
26
+ Util.hash_without!(global_options, %w[ params ])
27
+ Authorization.get id, params, global_options
22
28
  end
23
29
 
24
30
  desc 'create', 'Create a new authorization'
@@ -38,11 +44,15 @@ module GithubCLI
38
44
  note_url - Optional string - A URL to remind you what the OAuth token is for.
39
45
  DESC
40
46
  def create
41
- params = options[:params].dup
47
+ global_options = options.dup
48
+ params = global_options[:params].dup
42
49
  params['scopes'] = options[:scopes] if options[:scopes]
43
50
  params['note'] = options[:note] if options[:note]
44
51
  params['note_url'] = options[:note_url] if options[:note_url]
45
- Authorization.create params, options[:format]
52
+
53
+ Util.hash_without!(global_options, %w[ params scopes note note_url])
54
+
55
+ Authorization.create params, global_options
46
56
  end
47
57
 
48
58
  desc 'update <id>', 'Update an existing authorization'
@@ -66,18 +76,26 @@ module GithubCLI
66
76
  note_url - Optional string - A URL to remind you what the OAuth token is for.
67
77
  DESC
68
78
  def update(id)
69
- params = options[:params].dup
79
+ global_options = options.dup
80
+ params = global_options[:params].dup
70
81
  params['scopes'] = options[:scopes] if options[:scopes]
71
82
  params['add_scopes'] = options[:add_scopes] if options[:add_scopes]
72
83
  params['remove_scopes'] = options[:remove_scopes] if options[:remove_scopes]
73
84
  params['note'] = options[:note] if options[:note]
74
85
  params['note_url'] = options[:note_url] if options[:note_url]
75
- Authorization.update id, params, options[:format]
86
+
87
+ Util.hash_without!(global_options,
88
+ %w[ params scopes add_scopes remove_scopes note note_url])
89
+
90
+ Authorization.update id, params, global_options
76
91
  end
77
92
 
78
93
  desc 'delete <id>', 'Delete an authorization'
79
94
  def delete(id)
80
- Authorization.delete id, options[:params], options[:format]
95
+ global_options = options.dup
96
+ params = global_options[:params].dup
97
+ Util.hash_without!(global_options, %w[ params ])
98
+ Authorization.delete id, params, global_options
81
99
  end
82
100
 
83
101
  end # Authorizations
@@ -7,12 +7,18 @@ module GithubCLI
7
7
 
8
8
  desc 'list <user> <repo>', 'List repository hooks'
9
9
  def list(user, repo)
10
- Hook.all user, repo, options[:params], options[:format]
10
+ global_options = options.dup
11
+ params = options[:params].dup
12
+ Util.hash_without!(global_options, %w[ params ])
13
+ Hook.all user, repo, params, global_options
11
14
  end
12
15
 
13
16
  desc 'get <user> <repo> <id>', 'Get a hook'
14
17
  def get(user, repo, id)
15
- Hook.get user, repo, id, options[:params], options[:format]
18
+ global_options = options.dup
19
+ params = options[:params].dup
20
+ Util.hash_without!(global_options, %w[ params ])
21
+ Hook.get user, repo, id, params, global_options
16
22
  end
17
23
 
18
24
  option :name, :type => :string, :required => true, :banner => "service",
@@ -33,13 +39,14 @@ module GithubCLI
33
39
  active - Optional boolean - Determines whether the hook is actually triggered on pushes.
34
40
  DESC
35
41
  def create(user, repo)
42
+ global_options = options.dup
36
43
  params = options[:params].dup
37
44
  params['name'] = options[:name]
38
45
  params['config'] = options[:config]
39
46
  params['events'] = options[:events] if options[:events]
40
47
  params['active'] = options[:active] if options[:active]
41
-
42
- Hook.create user, repo, params, options[:format]
48
+ Util.hash_without!(global_options, %w[ params name config events active ])
49
+ Hook.create user, repo, params, global_options
43
50
  end
44
51
 
45
52
  option :name, :type => :string, :required => true, :banner => "service",
@@ -66,6 +73,7 @@ module GithubCLI
66
73
  active - Optional boolean - Determines whether the hook is actually triggered on pushes. \n
67
74
  DESC
68
75
  def edit(user, repo, id)
76
+ global_options = options.dup
69
77
  params = options[:params].dup
70
78
  params['name'] = options[:name]
71
79
  params['config'] = options[:config]
@@ -73,18 +81,24 @@ module GithubCLI
73
81
  params['add_events'] = options[:add_events] if options[:add_events]
74
82
  params['remove_events'] = options[:remove_events] if options[:remove_events]
75
83
  params['active'] = options[:active] if options[:active]
76
-
77
- Hook.edit user, repo, id, params, options[:format]
84
+ Util.hash_without!(global_options, %w[ params name config events add_events remove_events active ])
85
+ Hook.edit user, repo, id, params, global_options
78
86
  end
79
87
 
80
88
  desc 'test <user> <repo> <id>', 'Test a hook'
81
89
  def test(user, repo, id)
82
- Hook.test user, repo, id, options[:params], options[:format]
90
+ global_options = options.dup
91
+ params = options[:params].dup
92
+ Util.hash_without!(global_options, %w[ params ])
93
+ Hook.test user, repo, id, params, global_options
83
94
  end
84
95
 
85
96
  desc 'delete <user> <repo> <id>', 'Delete a hook'
86
97
  def delete(user, repo, id)
87
- Hook.delete user, repo, id, options[:params], options[:format]
98
+ global_options = options.dup
99
+ params = options[:params].dup
100
+ Util.hash_without!(global_options, %w[ params ])
101
+ Hook.delete user, repo, id, params, global_options
88
102
  end
89
103
 
90
104
  end # Hooks
@@ -19,6 +19,7 @@ module GithubCLI
19
19
  :desc => "asc or desc, default: when using full_name: asc, otherwise desc."
20
20
  desc 'list', 'Lists all repositories for the authenticated user'
21
21
  def list
22
+ global_options = options.dup
22
23
  params = options[:params].dup
23
24
  params['org'] = options[:org] if options[:org]
24
25
  params['user'] = options[:user] if options[:user]
@@ -26,12 +27,16 @@ module GithubCLI
26
27
  params['type'] = options[:type] if options[:type]
27
28
  params['sort'] = options[:sort] if options[:sort]
28
29
  params['direction'] = options[:direction] if options[:direction]
29
- Repository.all params, options[:format]
30
+ Util.hash_without!(global_options, params.keys + ['params'])
31
+ Repository.all params, global_options
30
32
  end
31
33
 
32
34
  desc 'get <user> <repo>', 'Get a repository'
33
35
  def get(user, repo)
34
- Repository.get user, repo, options[:params], options[:format]
36
+ global_options = options.dup
37
+ params = options[:params].dup
38
+ Util.hash_without!(global_options, %w[ params ])
39
+ Repository.get user, repo, params, global_options
35
40
  end
36
41
 
37
42
  option :org, :type => :string, :aliases => ["-o"],
@@ -39,17 +44,18 @@ module GithubCLI
39
44
  :banner => '<organization>'
40
45
  option :desc, :type => :string, :banner => "description"
41
46
  option :home, :type => :string, :banner => "homepage"
42
- option :private, :type => :boolean,
47
+ option :private, :type => :boolean, :default => false,
43
48
  :desc => "true to create a private repository, false to create a public one"
44
- option :issues, :type => :boolean, :banner => "has_issues",
49
+ option :issues, :type => :boolean, :banner => "has_issues", :default => true,
45
50
  :desc => "true to enable issues for this repository, false to disable them"
46
- option :wiki, :type => :boolean, :banner => "has_wiki",
51
+ option :wiki, :type => :boolean, :banner => "has_wiki", :default => true,
47
52
  :desc => "true to enable the wiki for this repository, false to disable it. Default is true"
48
53
  option :downloads, :type => :boolean, :banner => "has_downloads",
54
+ :default => true,
49
55
  :desc => "true to enable downloads for this repository "
50
- option :team, :type => :string, :banner => "team <id>",
56
+ option :team, :type => :numeric, :banner => "team <id>",
51
57
  :desc => "The id of the team that will be granted access to this repository. This is only valid when creating a repo in an organization"
52
- option :auto, :type => :string, :banner => "auto_init",
58
+ option :auto, :type => :string, :banner => "auto_init", :default => false,
53
59
  :desc => "true to create an initial commit with empty README. Default is false."
54
60
  option :gitignore, :type => :string, :banner => "gitignore_template",
55
61
  :desc => "Desired language or platform .gitignore template to apply."
@@ -71,32 +77,36 @@ module GithubCLI
71
77
  gitignore_template - Optional string - Desired language or platform .gitignore template to apply. Use the name of the template without the extension. For example, “Haskell” Ignored if auto_init parameter is not provided.
72
78
  DESC
73
79
  def create(args)
80
+ global_options = options.dup
74
81
  params = options[:params].dup
75
82
  org, params['name'] = Arguments.new(args).parse
76
- params['org'] = org if org
77
- params['org'] = options[:org] if options[:org]
78
- params['description'] = options[:desc] if options[:desc]
79
- params['homepage'] = options[:home] if options[:home]
80
- params['private'] = options[:private] if options[:private]
81
- params['has_issues'] = options[:issues] if options[:issues]
82
- params['has_wiki'] = options[:wiki] if options[:wiki]
83
- params['has_downloads'] = options[:downloads] if options[:downloads]
84
- params['team_id'] = options[:team] if options[:team]
85
- params['auto_init'] = options[:auto] if options[:auto]
83
+ params['org'] = org if org
84
+ params['org'] = options[:org] if options[:org]
85
+ params['description'] = options[:desc] if options[:desc]
86
+ params['homepage'] = options[:home] if options[:home]
87
+ params['private'] = options[:private]
88
+ params['has_issues'] = options[:issues]
89
+ params['has_wiki'] = options[:wiki]
90
+ params['has_downloads'] = options[:downloads]
91
+ params['team_id'] = options[:team] if options[:team]
92
+ params['auto_init'] = options[:auto]
86
93
  params['gitignore_template'] = options[:gitignore] if options[:gitignore]
87
94
 
88
- Repository.create params, options[:format]
95
+ Util.hash_without!(global_options,
96
+ params.keys + %w[ params issues wiki downloads team auto gitignore ])
97
+ Repository.create params, global_options
89
98
  end
90
99
 
91
100
  option :desc, :type => :string, :banner => "description"
92
101
  option :home, :type => :string, :banner => "homepage"
93
- option :private, :type => :boolean,
102
+ option :private, :type => :boolean, :default => false,
94
103
  :desc => "true to create a private repository, false to create a public one"
95
- option :issues, :type => :boolean, :banner => "has_issues",
104
+ option :issues, :type => :boolean, :banner => "has_issues", :default => true,
96
105
  :desc => "true to enable issues for this repository, false to disable them"
97
- option :wiki, :type => :boolean, :banner => "has_wiki",
106
+ option :wiki, :type => :boolean, :banner => "has_wiki", :default => true,
98
107
  :desc => "true to enable the wiki for this repository, false to disable it. Default is true"
99
108
  option :downloads, :type => :boolean, :banner => "has_downloads",
109
+ :default => true,
100
110
  :desc => "true to enable downloads for this repository "
101
111
  option :branch, :type => :string, :banner => "default branch",
102
112
  :desc => "Update the default branch for this repository."
@@ -116,52 +126,76 @@ module GithubCLI
116
126
  default_branch - Optional string - update the default branch for this repository \n
117
127
  DESC
118
128
  def edit(user, repo, name)
129
+ global_options = options.dup
119
130
  params = options[:params].dup
120
131
  params['name'] = name
121
- params['description'] = options[:desc] if options[:desc]
122
- params['homepage'] = options[:home] if options[:home]
123
- params['private'] = options[:private] if options[:private]
124
- params['has_issues'] = options[:issues] if options[:issues]
125
- params['has_wiki'] = options[:wiki] if options[:wiki]
126
- params['has_downloads'] = options[:downloads] if options[:downloads]
127
- params['default_branch'] = options[:branch] if options[:branch]
128
-
129
- Repository.edit user, repo, params, options[:format]
132
+ params['description'] = options[:desc] if options[:desc]
133
+ params['homepage'] = options[:home] if options[:home]
134
+ params['private'] = options[:private]
135
+ params['has_issues'] = options[:issues]
136
+ params['has_wiki'] = options[:wiki]
137
+ params['has_downloads'] = options[:downloads]
138
+ params['default_branch'] = options[:branch] if options[:branch]
139
+
140
+ Util.hash_without!(global_options,
141
+ params.keys + %w[ wiki issues downloads params] )
142
+ Repository.edit user, repo, params, global_options
130
143
  end
131
144
 
132
145
  desc 'delete <user> <repo>', 'Delete a repository'
133
146
  def delete(user, repo)
134
- Repository.delete user, repo, options[:params], options[:format]
147
+ global_options = options.dup
148
+ params = options[:params].dup
149
+ Util.hash_without!(global_options, params.keys + ['params'])
150
+ Repository.delete user, repo, params, global_options
135
151
  end
136
152
 
137
153
  desc 'branches <user> <repo>', 'List branches'
138
154
  def branches(user, repo)
139
- Repository.branches user, repo, options[:params], options[:format]
155
+ global_options = options.dup
156
+ params = options[:params].dup
157
+ Util.hash_without!(global_options, params.keys + ['params'])
158
+ Repository.branches user, repo, params, global_options
140
159
  end
141
160
 
142
161
  desc 'branch <user> <repo> <name>', 'Get branch'
143
162
  def branch(user, repo, name)
144
- Repository.branch user, repo, name, options[:params], options[:format]
163
+ global_options = options.dup
164
+ params = options[:params].dup
165
+ Util.hash_without!(global_options, params.keys + ['params'])
166
+ Repository.branch user, repo, name, params, global_options
145
167
  end
146
168
 
147
169
  desc 'contribs <user> <repo>', 'List contributors'
148
170
  def contribs(user, repo)
149
- Repository.contributors user, repo, options[:params], options[:format]
171
+ global_options = options.dup
172
+ params = options[:params].dup
173
+ Util.hash_without!(global_options, params.keys + ['params'])
174
+ Repository.contributors user, repo, params, global_options
150
175
  end
151
176
 
152
177
  desc 'langs <user> <repo>', 'Listing all languages'
153
178
  def langs(user, repo)
154
- Repository.languages user, repo, options[:params], options[:format]
179
+ global_options = options.dup
180
+ params = options[:params].dup
181
+ Util.hash_without!(global_options, params.keys + ['params'])
182
+ Repository.languages user, repo, params, global_options
155
183
  end
156
184
 
157
185
  desc 'tags <user> <repo>', 'Listing all tags'
158
186
  def tags(user, repo)
159
- Repository.tags user, repo, options[:params], options[:format]
187
+ global_options = options.dup
188
+ params = options[:params].dup
189
+ Util.hash_without!(global_options, params.keys + ['params'])
190
+ Repository.tags user, repo, params, global_options
160
191
  end
161
192
 
162
193
  desc 'teams <user> <repo>', 'Listing all teams'
163
194
  def teams(user, repo)
164
- Repository.teams user, repo, options[:params], options[:format]
195
+ global_options = options.dup
196
+ params = options[:params].dup
197
+ Util.hash_without!(global_options, params.keys + ['params'])
198
+ Repository.teams user, repo, params, global_options
165
199
  end
166
200
 
167
201
  end # Repositories
@@ -5,16 +5,18 @@ module GithubCLI
5
5
  # It delegates to other objects like Formatter::Table
6
6
  # to perform actual rendering.
7
7
  class Formatter
8
- attr_reader :response, :format, :message
8
+ attr_reader :response, :format, :message, :quiet
9
9
 
10
10
  def initialize(response, options={})
11
11
  @response = response
12
12
  @message = options[:message]
13
13
  @format = options[:format]
14
+ @quiet = options[:quiet]
14
15
  end
15
16
 
16
17
  def render_output
17
18
  render_status
19
+ return if quiet
18
20
  Terminal.paged_output
19
21
  determine_output_formatter
20
22
  render_message
@@ -20,6 +20,10 @@ module GithubCLI
20
20
  return new_hash
21
21
  end
22
22
 
23
+ def hash_without!(hash, keys)
24
+ hash.reject! { |key| keys.include?(key) }
25
+ end
26
+
23
27
  def convert_values(values)
24
28
  values_copy = values.dup
25
29
  collected = []
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module GithubCLI
4
- VERSION = "0.5.8"
4
+ VERSION = "0.5.9"
5
5
  end
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GithubCLI::Commands::Authorizations do
6
- let(:format) { 'table' }
6
+ let(:format) { {'format' => 'table'} }
7
7
  let(:id) { 1 }
8
8
  let(:api_class) { GithubCLI::Authorization }
9
9
 
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GithubCLI::Commands::Hooks 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(:id) { 1 }
@@ -3,7 +3,7 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe GithubCLI::Commands::Repositories 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(:org) { 'rails' }
@@ -37,34 +37,44 @@ describe GithubCLI::Commands::Repositories do
37
37
  end
38
38
 
39
39
  it "invokes repo:create name" do
40
- api_class.should_receive(:create).with({'name' => repo}, format)
40
+ api_class.should_receive(:create).with({
41
+ 'name' => repo, 'private' => nil, 'has_issues' => nil,
42
+ 'has_wiki' => nil, 'has_downloads' => nil, 'auto_init' => nil}, format)
41
43
  subject.invoke "repo:create", [repo]
42
44
  end
43
45
 
44
46
  it "invokes repo:create org/name" do
45
- api_class.should_receive(:create).with({'name' => repo, 'org' => org}, format)
47
+ api_class.should_receive(:create).with({
48
+ 'name' => repo, 'org' => org, 'private' => nil, 'has_issues' => nil,
49
+ 'has_wiki' => nil, 'has_downloads' => nil, 'auto_init' => nil}, format)
46
50
  subject.invoke "repo:create", ["#{org}/#{repo}"]
47
51
  end
48
52
 
49
53
  it "invokes repo:create name --org" do
50
- api_class.should_receive(:create).with({'name' => repo, 'org' => org}, format)
54
+ api_class.should_receive(:create).with({
55
+ 'name' => repo, 'org' => org, 'private' => nil, 'has_issues' => nil,
56
+ 'has_wiki' => nil, 'has_downloads' => nil, 'auto_init' => nil}, format)
51
57
  subject.invoke "repo:create", [repo], :org => org
52
58
  end
53
59
 
54
60
  it "invokes repo:create name --wiki --issues --downloads --auto_init" do
55
- api_class.should_receive(:create).with({'name' => repo, "has_wiki" => true,
61
+ api_class.should_receive(:create).with({
62
+ 'name' => repo, "has_wiki" => true, 'private' => nil,
56
63
  "has_issues" => true, "has_downloads" => true, "auto_init" => true}, format)
57
64
  subject.invoke "repo:create", [repo], :wiki => true, :issues => true,
58
65
  :downloads => true, :auto => true
59
66
  end
60
67
 
61
68
  it "invokes repo:edit user repo name" do
62
- api_class.should_receive(:edit).with(user, repo, {'name' => 'new'}, format)
69
+ api_class.should_receive(:edit).with(user, repo, {
70
+ 'name' => 'new', 'private' => nil,
71
+ "has_wiki" => nil, "has_issues" => nil, "has_downloads" => nil}, format)
63
72
  subject.invoke "repo:edit", [user, repo, 'new']
64
73
  end
65
74
 
66
75
  it "invokes repo:edit user repo name --wiki --issues --downloads --auto_init" do
67
- api_class.should_receive(:edit).with(user, repo, {'name' => 'new',
76
+ api_class.should_receive(:edit).with(user, repo, {
77
+ 'name' => 'new', 'private' => nil,
68
78
  "has_wiki" => true, "has_issues" => true, "has_downloads" => true}, format)
69
79
  subject.invoke "repo:edit", [user, repo, 'new'], :wiki => true,
70
80
  :issues => true, :downloads => true
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.5.8
4
+ version: 0.5.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-14 00:00:00.000000000Z
12
+ date: 2013-04-17 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: github_api
16
- requirement: &2153460920 !ruby/object:Gem::Requirement
16
+ requirement: &2160827640 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0.9'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2153460920
24
+ version_requirements: *2160827640
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &2153460520 !ruby/object:Gem::Requirement
27
+ requirement: &2160826680 !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: :development
34
34
  prerelease: false
35
- version_requirements: *2153460520
35
+ version_requirements: *2160826680
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: aruba
38
- requirement: &2153459940 !ruby/object:Gem::Requirement
38
+ requirement: &2160823300 !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: *2153459940
46
+ version_requirements: *2160823300
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &2153459420 !ruby/object:Gem::Requirement
49
+ requirement: &2160822640 !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: *2153459420
57
+ version_requirements: *2160822640
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: communist
60
- requirement: &2153458960 !ruby/object:Gem::Requirement
60
+ requirement: &2160822040 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2153458960
68
+ version_requirements: *2160822040
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ronn
71
- requirement: &2153458380 !ruby/object:Gem::Requirement
71
+ requirement: &2160821340 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *2153458380
79
+ version_requirements: *2160821340
80
80
  description: CLI-based access to GitHub API v3
81
81
  email:
82
82
  - ''