git_switch 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/git-switch +4 -0
- data/lib/git_switch/switcher.rb +74 -0
- data/lib/git_switch/version.rb +3 -0
- data/lib/git_switch.rb +1 -0
- metadata +119 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 979e33bfaa8c41d5324cba459f6c7ad00fea0494
|
4
|
+
data.tar.gz: e4bf15bfcb2b5ac536d22f07341b95fee2755614
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 003bb961cdb0e29eef263b808b1ed56ab7cd5e3a412f7426b93e75b2b676b1c0741ddf4587e62c4e4f65a0fd0617fe09c8cdcba38e057a186615b3f3a07cb10e
|
7
|
+
data.tar.gz: a10e1b3d1d3c46c55b7a1ee107aacb4c98a67968555b0da9c31adca826720979874d43130f8d343f63f4d11621f81a85c597ed87e1d24b67125bc78c16f2b48e
|
data/bin/git-switch
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# require 'version'
|
2
|
+
require 'yaml'
|
3
|
+
require_relative './version'
|
4
|
+
require 'byebug'
|
5
|
+
|
6
|
+
module GitSwitch
|
7
|
+
class Switcher
|
8
|
+
attr_reader :config, :profile, :valid, :global
|
9
|
+
# Your code goes here...
|
10
|
+
def initialize(args)
|
11
|
+
raise ArgumentError unless args.is_a? Array
|
12
|
+
@config = YAML.load_file(File.expand_path('~/.gitswitch'))
|
13
|
+
@global = check_global(args)
|
14
|
+
@profile = get_profile(args)
|
15
|
+
@valid = valid_args?(args)
|
16
|
+
end
|
17
|
+
|
18
|
+
def check_global(args)
|
19
|
+
(args.include? '-g') || (args.include? '--global')
|
20
|
+
end
|
21
|
+
|
22
|
+
def get_profile(args)
|
23
|
+
# TODO: RCR - Verify profile exists in config file
|
24
|
+
# TODO: RCR - Handle missing or empty config file
|
25
|
+
args.detect {|a| !a.start_with? '-'}
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_args?(args)
|
29
|
+
no_flags?(args) || one_flag?(args)
|
30
|
+
end
|
31
|
+
|
32
|
+
def no_flags?(args)
|
33
|
+
args.length == 1 && args.count {|a| a.start_with? '-'} == 0
|
34
|
+
end
|
35
|
+
|
36
|
+
def one_flag?(args)
|
37
|
+
args.length == 2 && args.count {|a| a.start_with?('-')} == 1
|
38
|
+
end
|
39
|
+
|
40
|
+
def set!
|
41
|
+
return unless valid
|
42
|
+
flag = global ? '--global' : ''
|
43
|
+
|
44
|
+
puts "\nGit Config:"
|
45
|
+
`git config #{flag} user.name "#{name}"`
|
46
|
+
`git config #{flag} user.username "#{username}"`
|
47
|
+
`git config #{flag} user.email "#{email}"`
|
48
|
+
puts `git config #{flag} -l --show-origin | grep user`
|
49
|
+
|
50
|
+
puts "\nSSH:"
|
51
|
+
`ssh-add -D`
|
52
|
+
`ssh-add #{ssh}`
|
53
|
+
puts `ssh-add -l`
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def name
|
59
|
+
config[profile]["name"]
|
60
|
+
end
|
61
|
+
|
62
|
+
def username
|
63
|
+
config[profile]["username"]
|
64
|
+
end
|
65
|
+
|
66
|
+
def email
|
67
|
+
config[profile]["email"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def ssh
|
71
|
+
config[profile]["ssh"]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/git_switch.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative 'git_switch/switcher'
|
metadata
ADDED
@@ -0,0 +1,119 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_switch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Randall Reed, Jr.
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-07-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec_junit_formatter
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.4.1
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.4.1
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Easily switch between git profiles (name, username, email) and ssh keys
|
84
|
+
email:
|
85
|
+
- randallreedjr@gmail.com
|
86
|
+
executables:
|
87
|
+
- git-switch
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- bin/git-switch
|
92
|
+
- lib/git_switch.rb
|
93
|
+
- lib/git_switch/switcher.rb
|
94
|
+
- lib/git_switch/version.rb
|
95
|
+
homepage: https://www.github.com/randallreedjr/git_switch
|
96
|
+
licenses:
|
97
|
+
- MIT
|
98
|
+
metadata: {}
|
99
|
+
post_install_message:
|
100
|
+
rdoc_options: []
|
101
|
+
require_paths:
|
102
|
+
- lib
|
103
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
104
|
+
requirements:
|
105
|
+
- - ">="
|
106
|
+
- !ruby/object:Gem::Version
|
107
|
+
version: '0'
|
108
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: '0'
|
113
|
+
requirements: []
|
114
|
+
rubyforge_project:
|
115
|
+
rubygems_version: 2.5.2.3
|
116
|
+
signing_key:
|
117
|
+
specification_version: 4
|
118
|
+
summary: Switch between git profiles
|
119
|
+
test_files: []
|