gaman 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -2
- data/bin/gaman +1 -1
- data/gaman.gemspec +6 -4
- data/lib/gaman/cli.rb +82 -61
- data/lib/gaman/messenger.rb +0 -11
- data/lib/gaman/version.rb +1 -1
- data/spec/file_helper_spec.rb +1 -1
- data/spec/messenger_spec.rb +3 -3
- metadata +14 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c581bb32b307b6fbdb24c968574ce7fe11d17d21
|
4
|
+
data.tar.gz: b61a1645e5954e84f4088e707fded95ca48cd8d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67b8d2c74000cbad9c98ce945d8139f2ad939ebf7cb8227b411c8d766ec4ea4327d9152837ef149e80a0ae0d168d70a39df3072e1d52b920bc896c1beb5fff11
|
7
|
+
data.tar.gz: 1e8f89881d16ec8a0ebdb419c7b2ca521ba47f71948e0ac7f3f380ed8f90255a0233e4d81d177a986167b3835be5e17359259d8ca940160fbc291188d55dcdc8
|
data/README.md
CHANGED
@@ -41,6 +41,12 @@ Install as you would any other ruby gem:
|
|
41
41
|
|
42
42
|
And then follow the inline-instruction.
|
43
43
|
|
44
|
+
Or
|
45
|
+
|
46
|
+
$ gaman switch key_index
|
47
|
+
|
48
|
+
with key_index is a `number` shown in `list` method.
|
49
|
+
|
44
50
|
### Create new ssh key
|
45
51
|
|
46
52
|
$ gaman new -e your_email@domain.com
|
@@ -49,16 +55,19 @@ And then follow the inline-instruction.
|
|
49
55
|
|
50
56
|
$ gaman current_user
|
51
57
|
|
58
|
+
### Check Gaman version
|
59
|
+
|
60
|
+
$ gaman -v (or `--version`)
|
52
61
|
|
53
62
|
Params: `--server` (or `-s`): github/bitbucket
|
54
63
|
|
55
64
|
If there is no param passed, github will be used as default
|
56
65
|
|
57
66
|
## Contributors
|
58
|
-
[@
|
67
|
+
[@CQBinh](https://github.com/CQBinh) from [AsianTech](http://asiantech.vn) with love.
|
59
68
|
## Contributing
|
60
69
|
|
61
|
-
1. Fork [
|
70
|
+
1. Fork [https://github.com/CQBinh/gaman](https://github.com/CQBinh/gaman)
|
62
71
|
2. Create your feature branch (`git checkout -b my-awesome-feature`)
|
63
72
|
3. Commit your changes (`git commit -m 'Add some feature'`)
|
64
73
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/bin/gaman
CHANGED
data/gaman.gemspec
CHANGED
@@ -6,11 +6,13 @@ require 'gaman/version'
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = 'gaman'
|
8
8
|
spec.version = Gaman::VERSION
|
9
|
+
spec.platform = Gem::Platform::RUBY
|
9
10
|
spec.authors = ['CAO Quang Binh']
|
10
|
-
spec.email = ['
|
11
|
+
spec.email = ['binh.cao@appconus.com']
|
11
12
|
|
12
|
-
spec.summary = '
|
13
|
-
spec.description = 'Switch ssh
|
13
|
+
spec.summary = 'Git Account MANager.'
|
14
|
+
spec.description = 'Switch git ssh connection'
|
15
|
+
spec.homepage = 'https://github.com/CQBinh/gaman'
|
14
16
|
spec.license = 'MIT'
|
15
17
|
|
16
18
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -23,7 +25,6 @@ Gem::Specification.new do |spec|
|
|
23
25
|
spec.add_development_dependency 'bundler', '~> 1.11.2'
|
24
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
25
27
|
spec.add_development_dependency 'rspec'
|
26
|
-
spec.add_development_dependency 'pry'
|
27
28
|
spec.add_development_dependency 'rubocop'
|
28
29
|
|
29
30
|
# comment linter directly on pull request
|
@@ -32,4 +33,5 @@ Gem::Specification.new do |spec|
|
|
32
33
|
spec.add_development_dependency 'rubocop-checkstyle_formatter'
|
33
34
|
|
34
35
|
spec.add_dependency 'thor'
|
36
|
+
spec.add_dependency 'pry'
|
35
37
|
end
|
data/lib/gaman/cli.rb
CHANGED
@@ -4,10 +4,17 @@ require_relative 'messenger'
|
|
4
4
|
require_relative 'file_helper'
|
5
5
|
|
6
6
|
module Gaman
|
7
|
-
class
|
7
|
+
class GitAccountManager < Thor
|
8
8
|
include Gaman::Messenger
|
9
9
|
include Gaman::FileHelper
|
10
10
|
|
11
|
+
desc 'version', 'Show the Gaman version'
|
12
|
+
map %w(-v --version) => :version
|
13
|
+
|
14
|
+
def version
|
15
|
+
puts "Gaman version #{::Gaman::VERSION} on Ruby #{RUBY_VERSION}"
|
16
|
+
end
|
17
|
+
|
11
18
|
desc 'current_user', 'Show current github account that ssh connects to'
|
12
19
|
long_desc <<-current_user
|
13
20
|
|
@@ -18,33 +25,22 @@ module Gaman
|
|
18
25
|
current_user
|
19
26
|
method_option :server, aliases: '-s'
|
20
27
|
def current_user
|
21
|
-
|
22
|
-
case server
|
23
|
-
when 'github'
|
24
|
-
check_current_user_github
|
25
|
-
when 'bitbucket'
|
26
|
-
check_current_user_bitbucket
|
27
|
-
else
|
28
|
-
check_current_user_github
|
29
|
-
end
|
28
|
+
check_current_user options.fetch('server', 'github')
|
30
29
|
end
|
31
30
|
|
32
31
|
desc 'show', 'Show public key so you can copy to clipboard'
|
33
32
|
def show
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
else
|
39
|
-
get_user_input_number_and_then_show(ssh_keys)
|
33
|
+
eval_ssh_agent_s
|
34
|
+
|
35
|
+
get_user_input_number(all_public_ssh_file) do |number, ssh_keys|
|
36
|
+
show_ssh_key(number, ssh_keys)
|
40
37
|
end
|
41
38
|
end
|
42
39
|
|
43
40
|
desc 'list', 'Check list ssh keys on machine'
|
44
41
|
def list
|
45
42
|
notice_message('Checking ssh keys in your machine...')
|
46
|
-
|
47
|
-
display_ssh_keys(ssh_keys)
|
43
|
+
display_ssh_keys(all_public_ssh_file)
|
48
44
|
end
|
49
45
|
|
50
46
|
desc 'new', 'Generate new ssh key'
|
@@ -53,37 +49,81 @@ module Gaman
|
|
53
49
|
system("ssh-keygen -t rsa -b 4096 -C #{options[:email]}")
|
54
50
|
end
|
55
51
|
|
56
|
-
desc 'switch', 'Switch to another ssh key'
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
52
|
+
desc 'switch', 'Switch to another ssh key (pass key_index to directly switch)'
|
53
|
+
long_desc <<-switch
|
54
|
+
|
55
|
+
Params: key_index: key index from "list" method
|
56
|
+
|
57
|
+
switch
|
58
|
+
def switch(key_index = nil)
|
59
|
+
if key_index.nil?
|
60
|
+
switch_by_showing_list_keys
|
62
61
|
else
|
63
|
-
|
62
|
+
switch_by_key_index(key_index.to_i)
|
64
63
|
end
|
65
64
|
end
|
66
65
|
|
66
|
+
no_commands{
|
67
|
+
def display_ssh_keys(ssh_keys)
|
68
|
+
fail ArgumentError, 'ssh_keys must be an Array' unless ssh_keys.is_a? Array
|
69
|
+
|
70
|
+
notice_message('You have no ssh key.') if ssh_keys.empty?
|
71
|
+
|
72
|
+
ssh_keys.each_with_index do |key, index|
|
73
|
+
puts "[#{Rainbow(index).underline.bright.cyan}] - #{key}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
}
|
77
|
+
|
67
78
|
private
|
68
79
|
|
80
|
+
def switch_by_key_index(key_index)
|
81
|
+
ssh_keys = all_public_ssh_file
|
82
|
+
return error_message('There are no ssh keys. Exiting...') if ssh_keys.empty?
|
83
|
+
check_number_and_yield_if_valid(key_index, ssh_keys) do |number, ssh_keys|
|
84
|
+
switch_ssh_key(number, ssh_keys)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
def switch_by_showing_list_keys
|
89
|
+
eval_ssh_agent_s
|
90
|
+
|
91
|
+
get_user_input_number(all_public_ssh_file) do |number, ssh_keys|
|
92
|
+
switch_ssh_key(number, ssh_keys)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
def eval_ssh_agent_s
|
97
|
+
system('eval "$(ssh-agent -s)"')
|
98
|
+
end
|
99
|
+
|
69
100
|
def all_public_ssh_file
|
70
101
|
if File.exist?(ssh_path)
|
71
|
-
|
72
|
-
files = files.select { |f| f.include?('.pub') && files.include?(f[0..-5]) }
|
73
|
-
files
|
102
|
+
Dir["#{ssh_path}/*.pub"]
|
74
103
|
else
|
75
104
|
notice_message('You have no ssh key. To create new one, run this command:')
|
76
105
|
puts Rainbow('$ gaman new -e your_email@domain.com').blue
|
77
|
-
|
106
|
+
[]
|
78
107
|
end
|
79
108
|
end
|
80
109
|
|
81
|
-
def
|
82
|
-
|
110
|
+
def get_user_input_number(ssh_keys)
|
111
|
+
return error_message('There are no ssh keys. Exiting...') if ssh_keys.empty?
|
112
|
+
|
113
|
+
notice_message('Current ssh keys on your system:')
|
83
114
|
message = 'Which key do you want to switch? [Input number]'
|
84
115
|
number = input_number(ssh_keys, message)
|
85
116
|
if number_valid?(number, ssh_keys)
|
86
|
-
|
117
|
+
block_given? ? yield(number, ssh_keys) : [number, ssh_keys]
|
118
|
+
else
|
119
|
+
error_message('Wrong value. Exiting...')
|
120
|
+
end
|
121
|
+
# check_number_and_yield_if_valid(number, ssh_keys)
|
122
|
+
end
|
123
|
+
|
124
|
+
def check_number_and_yield_if_valid(number, ssh_keys)
|
125
|
+
if number_valid?(number, ssh_keys)
|
126
|
+
block_given? ? yield(number, ssh_keys) : [number, ssh_keys]
|
87
127
|
else
|
88
128
|
error_message('Wrong value. Exiting...')
|
89
129
|
end
|
@@ -103,42 +143,23 @@ module Gaman
|
|
103
143
|
!number.nil? && number >= 0 && number <= ssh_keys.size - 1
|
104
144
|
end
|
105
145
|
|
106
|
-
def
|
107
|
-
key = ssh_keys[number]
|
108
|
-
key_path = "#{ssh_path}/#{key[0..-5]}"
|
146
|
+
def switch_ssh_key(number, ssh_keys)
|
147
|
+
key = ssh_keys[number][0..-5]
|
109
148
|
system('ssh-add -D')
|
110
|
-
notice_message("Adding #{
|
111
|
-
system("ssh-add #{
|
149
|
+
notice_message("Adding #{key}")
|
150
|
+
system("ssh-add #{key}")
|
112
151
|
current_user
|
113
152
|
end
|
114
153
|
|
115
|
-
def
|
116
|
-
|
117
|
-
|
118
|
-
system(
|
119
|
-
end
|
120
|
-
|
121
|
-
def check_current_user_bitbucket
|
122
|
-
notice_message('Checking ssh conection to bitbucket...')
|
123
|
-
check_ssh_github = 'ssh -T git@bitbucket.org'
|
124
|
-
system(check_ssh_github)
|
125
|
-
end
|
126
|
-
|
127
|
-
def get_user_input_number_and_then_show(ssh_keys)
|
128
|
-
notice_message('Current ssh keyson your system:')
|
129
|
-
message = 'Which key do you want to show? [Input number]'
|
130
|
-
number = input_number(ssh_keys, message)
|
131
|
-
if number_valid?(number, ssh_keys)
|
132
|
-
perform_show_ssh_key(number, ssh_keys)
|
133
|
-
else
|
134
|
-
error_message('Wrong value. Exiting...')
|
135
|
-
end
|
154
|
+
def check_current_user(server)
|
155
|
+
servers = { 'github' => 'github.com', 'bitbucket' => 'bitbucket.org' }
|
156
|
+
notice_message("Checking ssh conection to #{server}...")
|
157
|
+
system("ssh -T git@#{servers[server]}")
|
136
158
|
end
|
137
159
|
|
138
|
-
def
|
160
|
+
def show_ssh_key(number, ssh_keys)
|
139
161
|
key = ssh_keys[number]
|
140
|
-
|
141
|
-
system("cat #{key_path}")
|
162
|
+
system("cat #{key}")
|
142
163
|
end
|
143
164
|
end
|
144
165
|
end
|
data/lib/gaman/messenger.rb
CHANGED
@@ -7,16 +7,5 @@ module Gaman
|
|
7
7
|
def error_message(message)
|
8
8
|
puts Rainbow(message).red
|
9
9
|
end
|
10
|
-
|
11
|
-
def display_ssh_keys(ssh_keys)
|
12
|
-
if ssh_keys.nil?
|
13
|
-
notice_message('You have no ssh key.')
|
14
|
-
else
|
15
|
-
fail ArgumentError, 'ssh_keys must be an Array' unless ssh_keys.class.eql? Array
|
16
|
-
ssh_keys.each_with_index do |key, index|
|
17
|
-
puts "[#{Rainbow(index).underline.bright.cyan}] - #{key}"
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
10
|
end
|
22
11
|
end
|
data/lib/gaman/version.rb
CHANGED
data/spec/file_helper_spec.rb
CHANGED
data/spec/messenger_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require 'spec_helper'
|
|
2
2
|
require 'gaman/messenger'
|
3
3
|
|
4
4
|
RSpec.describe 'Messenger' do
|
5
|
-
let(:gaman) { Gaman::
|
5
|
+
let(:gaman) { Gaman::GitAccountManager.new }
|
6
6
|
|
7
7
|
context 'display_ssh_keys' do
|
8
|
-
it 'notice when
|
9
|
-
expect { gaman.display_ssh_keys(
|
8
|
+
it 'notice when empty array passed' do
|
9
|
+
expect { gaman.display_ssh_keys([]) }.to output(/no ssh key/).to_stdout
|
10
10
|
end
|
11
11
|
|
12
12
|
it 'raise ArgumentError when ssh_keys are not Array' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gaman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- CAO Quang Binh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-02-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: saddler
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -95,7 +95,7 @@ dependencies:
|
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
|
-
name: saddler
|
98
|
+
name: saddler-reporter-github
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
101
|
- - ">="
|
@@ -109,7 +109,7 @@ dependencies:
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
112
|
+
name: rubocop-checkstyle_formatter
|
113
113
|
requirement: !ruby/object:Gem::Requirement
|
114
114
|
requirements:
|
115
115
|
- - ">="
|
@@ -123,13 +123,13 @@ dependencies:
|
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
126
|
+
name: thor
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
128
128
|
requirements:
|
129
129
|
- - ">="
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
|
-
type: :
|
132
|
+
type: :runtime
|
133
133
|
prerelease: false
|
134
134
|
version_requirements: !ruby/object:Gem::Requirement
|
135
135
|
requirements:
|
@@ -137,7 +137,7 @@ dependencies:
|
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
139
|
- !ruby/object:Gem::Dependency
|
140
|
-
name:
|
140
|
+
name: pry
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
143
|
- - ">="
|
@@ -150,9 +150,9 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
description: Switch ssh
|
153
|
+
description: Switch git ssh connection
|
154
154
|
email:
|
155
|
-
-
|
155
|
+
- binh.cao@appconus.com
|
156
156
|
executables:
|
157
157
|
- checker.sh
|
158
158
|
- console
|
@@ -187,7 +187,7 @@ files:
|
|
187
187
|
- spec/gaman_spec.rb
|
188
188
|
- spec/messenger_spec.rb
|
189
189
|
- spec/spec_helper.rb
|
190
|
-
homepage:
|
190
|
+
homepage: https://github.com/CQBinh/gaman
|
191
191
|
licenses:
|
192
192
|
- MIT
|
193
193
|
metadata: {}
|
@@ -207,10 +207,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
207
207
|
version: '0'
|
208
208
|
requirements: []
|
209
209
|
rubyforge_project:
|
210
|
-
rubygems_version: 2.4.5
|
210
|
+
rubygems_version: 2.4.5
|
211
211
|
signing_key:
|
212
212
|
specification_version: 4
|
213
|
-
summary:
|
213
|
+
summary: Git Account MANager.
|
214
214
|
test_files:
|
215
215
|
- spec/file_helper_spec.rb
|
216
216
|
- spec/gaman_spec.rb
|