Chee 0.1.0 → 0.2.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.
- data/Chee.gemspec +1 -0
- data/README.md +20 -9
- data/lib/Chee.rb +10 -9
- data/lib/Chee/version.rb +1 -1
- data/spec/files/input.rb +35 -0
- data/spec/tests/Chee.rb +15 -29
- metadata +18 -1
data/Chee.gemspec
CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
s.add_development_dependency 'Bacon_Colored'
|
28
28
|
s.add_development_dependency 'pry'
|
29
29
|
s.add_development_dependency 'mocha-on-bacon'
|
30
|
+
s.add_development_dependency 'highline'
|
30
31
|
|
31
32
|
# Specify any dependencies here; for example:
|
32
33
|
s.add_runtime_dependency 'Get_Set'
|
data/README.md
CHANGED
@@ -25,15 +25,19 @@ Usage
|
|
25
25
|
|
26
26
|
require "Chee"
|
27
27
|
|
28
|
-
|
29
|
-
Chee.server
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
# If you configured server using ~/.ssh/config:
|
29
|
+
Chee.server "my_server"
|
30
|
+
|
31
|
+
# You can also use the same options you would send to
|
32
|
+
# Net::SSH:
|
33
|
+
Chee.server(
|
34
|
+
'localhost',
|
35
|
+
'me',
|
34
36
|
:password => "try to use private/public keys",
|
35
37
|
:timeout => 3
|
36
|
-
|
38
|
+
)
|
39
|
+
|
40
|
+
# Send a command
|
37
41
|
Chee.ssh %^ sudo add-apt-repository ppa:nginx/stable ^
|
38
42
|
<!-- sudo apt-get install nginx -->
|
39
43
|
<!-- ^ -->
|
@@ -60,8 +64,15 @@ To run the tests:
|
|
60
64
|
bundle update
|
61
65
|
bundle exec bacon spec/main.rb
|
62
66
|
|
63
|
-
|
64
|
-
private keys
|
67
|
+
The tests assume you use passwordless SSH login using
|
68
|
+
private keys and put the following in your ~/.ssh/config:
|
69
|
+
|
70
|
+
Host localhost
|
71
|
+
User *your username*
|
72
|
+
IdentityFile ~/.ssh/path_to_priv_key
|
73
|
+
|
74
|
+
|
75
|
+
The following is useful for Ubuntu users:
|
65
76
|
|
66
77
|
sudo apt-get install ufw openssh-server
|
67
78
|
sudo ufw allow from 127.0.0.1 to any port 22
|
data/lib/Chee.rb
CHANGED
@@ -23,6 +23,11 @@ class Chee
|
|
23
23
|
@server = args
|
24
24
|
end
|
25
25
|
|
26
|
+
def print_data &blok
|
27
|
+
return @print_data if blok.nil?
|
28
|
+
@print_data = blok
|
29
|
+
end
|
30
|
+
|
26
31
|
#
|
27
32
|
# Thread technique came from:
|
28
33
|
# http://stackoverflow.com/questions/6942279/ruby-net-ssh-channel-dies
|
@@ -102,8 +107,7 @@ class Chee
|
|
102
107
|
stdout << d # .sub(%r!\r?\n\Z!,'')
|
103
108
|
|
104
109
|
unless prev_cmd.to_s.strip == d.strip
|
105
|
-
|
106
|
-
STDOUT.flush
|
110
|
+
print_data.call d
|
107
111
|
end
|
108
112
|
|
109
113
|
prev_data = d
|
@@ -131,13 +135,6 @@ class Chee
|
|
131
135
|
rescue Net::SSH::AuthenticationFailed => e
|
132
136
|
raise e.class, "Using: #{server.inspect}"
|
133
137
|
|
134
|
-
#rescue Net::SSH::HostKeyMismatch => e
|
135
|
-
# if e.message[%r!fingerprint .+ does not match for!]
|
136
|
-
# print "Try this", "ssh-keygen -f \"~/.ssh/known_hosts\" -R #{server[:ip]}\n"
|
137
|
-
# raise Retry_Command, "Removed the RSA key."
|
138
|
-
# end
|
139
|
-
#
|
140
|
-
# raise e
|
141
138
|
ensure
|
142
139
|
get_input = false
|
143
140
|
t.exit if t
|
@@ -161,5 +158,9 @@ class Chee
|
|
161
158
|
end # === module DSL
|
162
159
|
|
163
160
|
extend DSL
|
161
|
+
print_data { |d|
|
162
|
+
print d
|
163
|
+
STDOUT.flush
|
164
|
+
}
|
164
165
|
|
165
166
|
end # === class Chee
|
data/lib/Chee/version.rb
CHANGED
data/spec/files/input.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
cmd = %^ bundle exec ruby #{File.expand_path __FILE__} ^
|
2
|
+
dir = File.expand_path('.')
|
3
|
+
|
4
|
+
if ARGV == ['STDIN']
|
5
|
+
require "highline/import"
|
6
|
+
input = ask("Input text: ")
|
7
|
+
puts "You entered: #{input.inspect}"
|
8
|
+
exit 0
|
9
|
+
end
|
10
|
+
|
11
|
+
if ARGV == ['Chee']
|
12
|
+
require 'Chee'
|
13
|
+
Chee.server 'localhost'
|
14
|
+
Chee.ssh "cd #{dir} && #{cmd} STDIN"
|
15
|
+
exit 0
|
16
|
+
end
|
17
|
+
|
18
|
+
require 'open3'
|
19
|
+
Open3.popen3( "#{cmd} Chee") do |i, o, e, w|
|
20
|
+
|
21
|
+
sleep 2
|
22
|
+
print o.gets(' ')
|
23
|
+
print o.gets(' ')
|
24
|
+
i.puts 'a'
|
25
|
+
|
26
|
+
while txt = o.gets do
|
27
|
+
puts txt
|
28
|
+
end
|
29
|
+
|
30
|
+
while txt = e.gets do
|
31
|
+
puts txt
|
32
|
+
end
|
33
|
+
# Process.kill 'INT', w[:pid]
|
34
|
+
end
|
35
|
+
|
data/spec/tests/Chee.rb
CHANGED
@@ -10,6 +10,11 @@ describe ":ssh_exec" do
|
|
10
10
|
]
|
11
11
|
|
12
12
|
Chee.server @localhost
|
13
|
+
@data = ''
|
14
|
+
|
15
|
+
Chee.print_data { |d|
|
16
|
+
@data << d
|
17
|
+
}
|
13
18
|
end
|
14
19
|
|
15
20
|
it 'accepts a String for the server info.' do
|
@@ -22,10 +27,20 @@ describe ":ssh_exec" do
|
|
22
27
|
Chee.ssh("echo 'b'").out.should == 'b'
|
23
28
|
end
|
24
29
|
|
30
|
+
it 'uses :print_data to print data' do
|
31
|
+
Chee.ssh 'echo c'
|
32
|
+
@data.strip.should == 'c'
|
33
|
+
end
|
34
|
+
|
25
35
|
it 'uses a PTY' do
|
26
36
|
Chee.ssh("tty").out.should.match %r!/dev/pts/\d+!
|
27
37
|
end
|
28
38
|
|
39
|
+
it 'accepts input from STDIN' do
|
40
|
+
`bundle exec ruby spec/files/input.rb 2>&1`.strip
|
41
|
+
.should == %@Input text: a\nYou entered: "a"@
|
42
|
+
end
|
43
|
+
|
29
44
|
it 'returns a SSH::Results' do
|
30
45
|
Chee.ssh("hostname").should.be.is_a Chee::Result
|
31
46
|
end
|
@@ -41,7 +56,6 @@ describe ":ssh_exec" do
|
|
41
56
|
Chee.ssh "hostname"
|
42
57
|
}.should.raise(Net::SSH::AuthenticationFailed)
|
43
58
|
.message.should.match %r!Using: ..github.com..!
|
44
|
-
|
45
59
|
end
|
46
60
|
|
47
61
|
it 'raises Chee::Exit_Error if return status is not zero' do
|
@@ -54,31 +68,3 @@ describe ":ssh_exec" do
|
|
54
68
|
|
55
69
|
end # === describe :ssh_exec
|
56
70
|
|
57
|
-
__END__
|
58
|
-
describe ":ssh_exits" do
|
59
|
-
|
60
|
-
it 'captures exits based on key => int, val => Regexp' do
|
61
|
-
lambda {
|
62
|
-
ignore_exits("cat something.txt", 1=>%r!something\.txt\: No such file or directory!)
|
63
|
-
}.should.not.raise
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'captures exits based on key => int, val => String' do
|
67
|
-
lambda {
|
68
|
-
ignore_exits("cat something.txt", 1=>'something.txt: No such file or directory')
|
69
|
-
}.should.not.raise
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'returns SSH::Results for a non-zero exit status' do
|
73
|
-
ignore_exits("cat something.txt", 1=>'something.txt: No such file or directory')
|
74
|
-
.should.be.is_a Unified_IO::Remote::SSH::Results
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'returns SSH::Results for a zero exit status' do
|
78
|
-
ignore_exits("uptime", 1=>'something.txt: No such file or directory')
|
79
|
-
.should.be.is_a Unified_IO::Remote::SSH::Results
|
80
|
-
end
|
81
|
-
|
82
|
-
end # === describe :ssh_exits
|
83
|
-
|
84
|
-
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: Chee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: highline
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
- !ruby/object:Gem::Dependency
|
95
111
|
name: Get_Set
|
96
112
|
requirement: !ruby/object:Gem::Requirement
|
@@ -158,6 +174,7 @@ files:
|
|
158
174
|
- lib/Chee/version.rb
|
159
175
|
- spec/files/errors_with_exit_0.rb
|
160
176
|
- spec/files/exit_with_2.rb
|
177
|
+
- spec/files/input.rb
|
161
178
|
- spec/helper.rb
|
162
179
|
- spec/main.rb
|
163
180
|
- spec/tests/Chee.rb
|