net-ssh-cli 1.3.1 → 1.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -4
- data/lib/net/ssh/cli.rb +8 -8
- data/lib/net/ssh/cli/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d734f75313a3aea3cbb85a47335ddf7296a3e8f14decdc9f7b20e1ee0b54471
|
4
|
+
data.tar.gz: c9a577d837e7b5854e7b5e88ee7efa0838872948eb3d6fe51cdf39e57acdd970
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74d34dc0d28a962a801ba14f0d0accbd36b7ba88eecf99c845714a23cc79ca1f196e626ab88c9f178aa9dc01cf1af0285d9f395bb2103670ecbcc34afd629702
|
7
|
+
data.tar.gz: 107dd734b5d01ec26edb80e3bcfd0bc023358e16f77ebf6c1b4157ae5ccc4d81a26a9669634e84bd64b16e0dadbd9839aac7690c77b156477d1c0cd633b81f95
|
data/README.md
CHANGED
@@ -79,12 +79,22 @@ It's the same as #cmd but for multiple commands.
|
|
79
79
|
```
|
80
80
|
|
81
81
|
### #dialog
|
82
|
+
|
83
|
+
Use this method to specify a differnt 'prompt' for once. This is perfect for interactive commands.
|
84
|
+
|
82
85
|
```ruby
|
83
86
|
cli.dialog "echo 'are you sure?' && read -p 'yes|no>'", /\nyes|no>/
|
84
87
|
# => "echo 'are you sure?' && read -p 'yes|no>'\nyes|no>"
|
85
88
|
cli.cmd "yes"
|
86
89
|
```
|
87
90
|
|
91
|
+
```ruby
|
92
|
+
cli.dialog "passwd", /Current Password:/i
|
93
|
+
cli.dialog "Old Password", /New Password:/i
|
94
|
+
cli.dialog "New Password", /Repeat Password:/i
|
95
|
+
cli.cmd "New Password"
|
96
|
+
```
|
97
|
+
|
88
98
|
### #impact
|
89
99
|
|
90
100
|
The very same as `#cmd` but it respects a flag whether to run commands with 'impact'.
|
@@ -148,10 +158,10 @@ Nearly everything can be configured.
|
|
148
158
|
### Callbacks
|
149
159
|
|
150
160
|
The following callbacks are available
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
-
|
161
|
+
- before_open_channel
|
162
|
+
- after_open_channel
|
163
|
+
- before_on_stdout
|
164
|
+
- after_on_stdout
|
155
165
|
|
156
166
|
```ruby
|
157
167
|
cli.before_open_channel do
|
@@ -166,6 +176,20 @@ cli.after_open_channel do
|
|
166
176
|
end
|
167
177
|
```
|
168
178
|
|
179
|
+
Using the callbacks you can define a debugger which shows the `stdout` buffer content each time new data is received.
|
180
|
+
|
181
|
+
```ruby
|
182
|
+
cli.after_on_stdout do
|
183
|
+
warn stdout
|
184
|
+
end
|
185
|
+
```
|
186
|
+
|
187
|
+
```ruby
|
188
|
+
cli.after_on_stdout do
|
189
|
+
stdout.gsub!("\r\n", "\n")
|
190
|
+
end
|
191
|
+
```
|
192
|
+
|
169
193
|
### #hostname #host #to_s
|
170
194
|
|
171
195
|
```ruby
|
data/lib/net/ssh/cli.rb
CHANGED
@@ -176,12 +176,12 @@ module Net
|
|
176
176
|
|
177
177
|
hard_timeout = timeout
|
178
178
|
hard_timeout += 0.5 if timeout
|
179
|
-
::Timeout.timeout(hard_timeout, Error::ReadTillTimeout) do
|
179
|
+
::Timeout.timeout(hard_timeout, Error::ReadTillTimeout, "#{current_prompt.inspect} didn't match on #{stdout.inspect} within #{timeout}s") do
|
180
180
|
with_prompt(prompt) do
|
181
181
|
soft_timeout = Time.now + timeout if timeout
|
182
182
|
until stdout[current_prompt] do
|
183
183
|
if timeout and soft_timeout < Time.now
|
184
|
-
raise Error::ReadTillTimeout, "
|
184
|
+
raise Error::ReadTillTimeout, "#{current_prompt.inspect} didn't match on #{stdout.inspect} within #{timeout}s"
|
185
185
|
end
|
186
186
|
process
|
187
187
|
sleep 0.1
|
@@ -198,7 +198,7 @@ module Net
|
|
198
198
|
|
199
199
|
def dialog(command, prompt, **opts)
|
200
200
|
opts = opts.clone.merge(prompt: prompt)
|
201
|
-
cmd(command, opts)
|
201
|
+
cmd(command, **opts)
|
202
202
|
end
|
203
203
|
|
204
204
|
# 'read' first on purpuse as a feature. once you cmd you ignore what happend before. otherwise use read|write directly.
|
@@ -210,9 +210,9 @@ module Net
|
|
210
210
|
logger.debug { "#cmd ignoring pre-command output: #{pre_read_data.inspect}" } if pre_read_data.present?
|
211
211
|
end
|
212
212
|
write_n command
|
213
|
-
output = read_till(opts)
|
214
|
-
rm_prompt!(output, opts)
|
215
|
-
rm_command!(output, command, opts)
|
213
|
+
output = read_till(**opts)
|
214
|
+
rm_prompt!(output, **opts)
|
215
|
+
rm_command!(output, command, **opts)
|
216
216
|
output
|
217
217
|
end
|
218
218
|
alias command cmd
|
@@ -224,11 +224,11 @@ module Net
|
|
224
224
|
alias commands cmds
|
225
225
|
|
226
226
|
def rm_command!(output, command, **opts)
|
227
|
-
output[command + "\n"] = '' if rm_command?(opts) && output[command + "\n"]
|
227
|
+
output[command + "\n"] = '' if rm_command?(**opts) && output[command + "\n"]
|
228
228
|
end
|
229
229
|
|
230
230
|
def rm_prompt!(output, **opts)
|
231
|
-
if rm_prompt?(opts)
|
231
|
+
if rm_prompt?(**opts)
|
232
232
|
prompt = opts[:prompt] || current_prompt
|
233
233
|
if output[prompt]
|
234
234
|
prompt.is_a?(Regexp) ? output[prompt, 1] = '' : output[prompt] = ''
|
data/lib/net/ssh/cli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: net-ssh-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabian Stillhart
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -140,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.
|
143
|
+
rubygems_version: 3.1.2
|
144
144
|
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: 'Net::SSH::CLI: A library to handle CLI Sessions'
|