gaman 0.1.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2bfff483fd003fcce776b4f225f452c5caa70370
4
- data.tar.gz: fc8ea165cd950277e504fc8a59e507467082ee0c
3
+ metadata.gz: a1bb3ddc1f0dd82e035bb3a594190abb67a9c816
4
+ data.tar.gz: 8530ad1c3375a2a28b9026387c512084f18e4a22
5
5
  SHA512:
6
- metadata.gz: b03229e348939c6d296512d57f3aca0052202332c9f0876f538304f4b7f8da89acbbad93affe2a4d070a83515c14a914e20fee78cf81388d957f3d6c4c193140
7
- data.tar.gz: 8682394d12cb2941175cd40a08ad4481c0b7fdf9e55b9dc945ab7d16e639a4ab5462225cc0eefedb200a749115ed60be530ad567c585608e45c8d3b45bdb670f
6
+ metadata.gz: aedd5aeb0607df45439b3ac7bb0f5bd5a8821ec23d2b81b37f50a5eb0c750d8b52f79ef2c54f0cb0a6c4171c9b809158234c8b8c2df594c06d00bc58c6e68ef6
7
+ data.tar.gz: 9640b8642be069a81a840c0e60fc29581c895d926c06197c5b81f660a13843e32d715c9c60a104a3b26d1adaed8dfd62c5cb40403840eeb22d034c92d5fc7bfe
@@ -0,0 +1,5 @@
1
+ Documentation:
2
+ Enabled: false
3
+
4
+ Metrics/LineLength:
5
+ Max: 120
data/Rakefile CHANGED
@@ -1,6 +1,6 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
3
 
4
4
  RSpec::Core::RakeTask.new(:spec)
5
5
 
6
- task :default => :spec
6
+ task default: :spec
@@ -1,14 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "gaman"
3
+ require 'bundler/setup'
4
+ require 'gaman'
5
5
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
6
+ require 'irb'
14
7
  IRB.start
data/bin/gaman CHANGED
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'gaman'
4
- Gaman::Foo.start(ARGV)
4
+ Gaman::GithubAccountManager.start(ARGV)
@@ -4,23 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'gaman/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
- spec.name = "gaman"
7
+ spec.name = 'gaman'
8
8
  spec.version = Gaman::VERSION
9
- spec.authors = ["CAO Quang Binh"]
10
- spec.email = ["binhcq@asiantech.vn"]
9
+ spec.authors = ['CAO Quang Binh']
10
+ spec.email = ['binhcq@asiantech.vn']
11
11
 
12
- spec.summary = %q{Github account manager.}
13
- spec.description = %q{Switch ssh github.}
14
- spec.license = "MIT"
12
+ spec.summary = 'Github account manager.'
13
+ spec.description = 'Switch ssh github'
14
+ spec.license = 'MIT'
15
15
 
16
16
  spec.files = `git ls-files -z`.split("\x0")
17
17
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
19
+ spec.require_paths = ['lib']
20
20
 
21
- spec.add_development_dependency "bundler", "~> 1.10"
22
- spec.add_development_dependency "rake", "~> 10.0"
23
- spec.add_development_dependency "rspec"
21
+ spec.add_runtime_dependency('rainbow', '2.0')
22
+
23
+ spec.add_development_dependency 'bundler', '~> 1.10'
24
+ spec.add_development_dependency 'rake', '~> 10.0'
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'pry'
27
+ spec.add_development_dependency 'rubocop'
24
28
 
25
29
  spec.add_dependency 'thor'
26
30
  end
@@ -1,6 +1,6 @@
1
- require "gaman/version"
2
- require "gaman/cli"
1
+ require 'gaman/version'
2
+ require 'gaman/cli'
3
+ require 'pry'
3
4
 
4
5
  module Gaman
5
- # Your code goes here...
6
6
  end
@@ -1,25 +1,89 @@
1
1
  require 'thor'
2
+ require 'rainbow'
3
+ require_relative 'messenger'
4
+ require_relative 'file_helper'
2
5
 
3
6
  module Gaman
4
- class Foo < Thor
5
- desc "bar NAME", "This will greet you"
6
- long_desc <<-HELLO_WORLD
7
-
8
- `bar NAME` will print out a message to the person of your choosing.
9
-
10
- Brian Kernighan actually wrote the first "Hello, World!" program
11
- as part of the documentation for the BCPL programming language
12
- developed by Martin Richards. BCPL was used while C was being
13
- developed at Bell Labs a few years before the publication of
14
- Kernighan and Ritchie's C book in 1972.
15
-
16
- http://stackoverflow.com/a/12785204
17
- HELLO_WORLD
18
- option :upcase
19
- def bar(name)
20
- greeting = "Hello, #{name}"
21
- greeting.upcase! if options[:upcase]
22
- puts greeting
7
+ class GithubAccountManager < Thor
8
+ include Gaman::Messenger
9
+ include Gaman::FileHelper
10
+
11
+ desc 'current_user', 'Show current github account that ssh connects to'
12
+ def current_user
13
+ notice_message('Checking ssh conection to github...')
14
+ check_ssh_github = 'ssh -T git@github.com'
15
+ system(check_ssh_github)
16
+ end
17
+
18
+ desc 'list', 'Check list ssh keys on machine'
19
+ def list
20
+ notice_message('Checking ssh keys in your machine...')
21
+ ssh_keys = all_public_ssh_file
22
+ display_ssh_keys(ssh_keys)
23
+ end
24
+
25
+ desc 'new', 'Generate new ssh key'
26
+ method_option :email, required: true, aliases: '-e'
27
+ def new
28
+ system("ssh-keygen -t rsa -b 4096 -C #{options[:email]}")
29
+ end
30
+
31
+ desc 'switch', 'Switch to another ssh key'
32
+ def switch
33
+ system('eval "$(ssh-agent -s)"')
34
+ ssh_keys = all_public_ssh_file
35
+ if ssh_keys.nil?
36
+ error_message('There is no ssh key to switch. Exiting...')
37
+ else
38
+ get_user_input_number_and_then_check_switch(ssh_keys)
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ def all_public_ssh_file
45
+ if File.exist?(ssh_path)
46
+ files = Dir.entries(ssh_path)
47
+ files = files.select { |f| f.include?('.pub') && files.include?(f[0..-5]) }
48
+ files
49
+ else
50
+ notice_message('You have no ssh key. To create new one, run this command:')
51
+ puts Rainbow('$ gaman new -e your_email@domain.com').blue
52
+ nil
53
+ end
54
+ end
55
+
56
+ def get_user_input_number_and_then_check_switch(ssh_keys)
57
+ notice_message('Current ssh keyson your system:')
58
+ number = input_number(ssh_keys)
59
+ if number_valid?(number, ssh_keys)
60
+ perform_switch_ssh_key(number, ssh_keys)
61
+ else
62
+ error_message('Wrong value. Exiting...')
63
+ end
64
+ end
65
+
66
+ def input_number(ssh_keys)
67
+ display_ssh_keys(ssh_keys)
68
+ number = ask(notice_message('Which key do you want to switch? [Input number]'))
69
+ begin
70
+ Integer(number)
71
+ rescue
72
+ nil
73
+ end
74
+ end
75
+
76
+ def number_valid?(number, ssh_keys)
77
+ !number.nil? && number >= 0 && number <= ssh_keys.size - 1
78
+ end
79
+
80
+ def perform_switch_ssh_key(number, ssh_keys)
81
+ key = ssh_keys[number]
82
+ key_path = "#{ssh_path}/#{key[0..-5]}"
83
+ system('ssh-add -D')
84
+ notice_message("Adding #{key_path}")
85
+ system("ssh-add #{key_path}")
86
+ current_user
23
87
  end
24
88
  end
25
89
  end
@@ -0,0 +1,7 @@
1
+ module Gaman
2
+ module FileHelper
3
+ def ssh_path
4
+ "#{Dir.home}/.ssh"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module Gaman
2
+ module Messenger
3
+ def notice_message(message)
4
+ puts Rainbow(message).green
5
+ end
6
+
7
+ def error_message(message)
8
+ puts Rainbow(message).red
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
+ ssh_keys.each_with_index do |key, index|
16
+ puts "[#{Rainbow(index).underline.bright.cyan}] - #{key}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,3 +1,3 @@
1
1
  module Gaman
2
- VERSION = "0.1.1"
2
+ VERSION = '0.9.0'
3
3
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gaman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.9.0
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-01-13 00:00:00.000000000 Z
11
+ date: 2016-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rainbow
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -52,6 +66,34 @@ dependencies:
52
66
  - - ">="
53
67
  - !ruby/object:Gem::Version
54
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
55
97
  - !ruby/object:Gem::Dependency
56
98
  name: thor
57
99
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +108,7 @@ dependencies:
66
108
  - - ">="
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
- description: Switch ssh github.
111
+ description: Switch ssh github
70
112
  email:
71
113
  - binhcq@asiantech.vn
72
114
  executables:
@@ -78,6 +120,7 @@ extra_rdoc_files: []
78
120
  files:
79
121
  - ".gitignore"
80
122
  - ".rspec"
123
+ - ".rubocop.yml"
81
124
  - ".travis.yml"
82
125
  - CODE_OF_CONDUCT.md
83
126
  - Gemfile
@@ -90,6 +133,8 @@ files:
90
133
  - gaman.gemspec
91
134
  - lib/gaman.rb
92
135
  - lib/gaman/cli.rb
136
+ - lib/gaman/file_helper.rb
137
+ - lib/gaman/messenger.rb
93
138
  - lib/gaman/version.rb
94
139
  - spec/gaman_spec.rb
95
140
  - spec/spec_helper.rb