net-ssh-cli 1.3.1 → 1.4.1

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
  SHA256:
3
- metadata.gz: edf3e84c80ca5ee2c6b67efee26c5f5b4f4b51a6c3425c4b7093e1d20eee4816
4
- data.tar.gz: 59b804e5249298c0f6de5debb26a89eacc3221e0a7d1bf3fe47aa08c5c2e89fa
3
+ metadata.gz: 8d734f75313a3aea3cbb85a47335ddf7296a3e8f14decdc9f7b20e1ee0b54471
4
+ data.tar.gz: c9a577d837e7b5854e7b5e88ee7efa0838872948eb3d6fe51cdf39e57acdd970
5
5
  SHA512:
6
- metadata.gz: 0d1046b9eab50cf26d5a1acab9d9301fa90225204df55168c64dcb9d985310aacdee023fe2c4ce2628cf016847e891feed6f94da3c0423c6555f41f3727262da
7
- data.tar.gz: 2c70b909d56f711d972b8381f4eef838e785b1b78d63d11786fded541b00d0b03b487fa66418b791965d4c13c0a02c28f65751cab5fa917a459c5ccdffa00ae6
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
- - #before_open_channel
152
- - #after_open_channel
153
- - #before_on_data
154
- - #before_on_data
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, "Timeout after #{timeout}s, #{current_prompt.inspect} never matched #{stdout.inspect}"
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] = ''
@@ -3,7 +3,7 @@
3
3
  module Net
4
4
  module SSH
5
5
  module CLI
6
- VERSION = '1.3.1'
6
+ VERSION = '1.4.1'
7
7
  end
8
8
  end
9
9
  end
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.3.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: 2019-07-15 00:00:00.000000000 Z
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.0.4
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'