net-ssh-cli 0.3.0 → 1.0.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
  SHA256:
3
- metadata.gz: 36080ea8a1e4e289bc73d79d9a665a0848925799db74242e5705814a8c6081c9
4
- data.tar.gz: 85cbb73ba6ff4925b39955c7416934a5c9124b8e4e5cbf0eeafc67af1bb2193f
3
+ metadata.gz: a38667881b73d31aba590fffbc7856fd94cb2e477b93c1f93097a955bb959dd1
4
+ data.tar.gz: 6afd84f95e15e87a1a9311876ad85c99d87122b36000665d2aea8dbe6d5b826f
5
5
  SHA512:
6
- metadata.gz: 0e3a0db15b0bb3d14e9cc2f7a1bd8c5e3379c8e2829e09fc8e3f63a445514f6b5a467cc3de76be5da34ec33632e8545bf8eea10ea2898eade24496f6fca222cb
7
- data.tar.gz: 9b15edce5dc418753069b56004480bd9836104bfd9508b3e2dc89c31acdf3433253b76717bde7959dc6e4dcc53fcbbdedea1f8dee79f95359f2615feb37f402f
6
+ metadata.gz: e7faec7d0e2ee50fc63be7e5847190b85f5aca55fcf8fc5ff038802ee43f7e4bec3bfee6f46e8259529ee57b92cb05e9c2981ecdbd57f040e4c67291bbbae5c1
7
+ data.tar.gz: 8292831d9fe0c513ae98a102830b252fb698a9ae7f6872714189e039d59d89d9f56250bcbdcec20c6c2bce6adf7ffd1d3b52e20a7fc9e7da1d49cff0ed2aeef7
data/bin/runner CHANGED
@@ -7,4 +7,4 @@ require 'net/ssh/cli'
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
9
9
 
10
- ARGV.each {|arg| eval arg}
10
+ ARGV.each { |arg| eval arg }
@@ -55,7 +55,7 @@ module Net
55
55
  def options
56
56
  @options ||= begin
57
57
  opts = OPTIONS.clone
58
- opts.each do |key,value|
58
+ opts.each do |key, value|
59
59
  opts[key] = value.clone if value.is_a?(Hash)
60
60
  end
61
61
  opts
@@ -100,9 +100,9 @@ module Net
100
100
  end
101
101
 
102
102
  def on_stdout(data)
103
- before_on_stdout_procs.each { |_name, a_proc| a_proc.call }
103
+ before_on_stdout_procs.each { |_name, a_proc| instance_eval(&a_proc) }
104
104
  stdout << data
105
- after_on_stdout_procs.each { |_name, a_proc| a_proc.call }
105
+ after_on_stdout_procs.each { |_name, a_proc| instance_eval(&a_proc) }
106
106
  process # if we receive data, we probably receive more - improves performance
107
107
  stdout
108
108
  end
@@ -150,6 +150,7 @@ module Net
150
150
  end
151
151
  self.default_prompt = read[/\n?^.*\z/]
152
152
  raise Error::PromptDetection, "couldn't detect a prompt" unless default_prompt.present?
153
+
153
154
  default_prompt
154
155
  end
155
156
 
@@ -184,14 +185,14 @@ module Net
184
185
  end
185
186
 
186
187
  def dialog(command, prompt, **opts)
187
- opts = opts.clone.merge(prompt: prompt)
188
+ opts = opts.clone.merge(prompt: prompt)
188
189
  cmd(command, opts)
189
190
  end
190
191
 
191
192
  # 'read' first on purpuse as a feature. once you cmd you ignore what happend before. otherwise use read|write directly.
192
193
  # this should avoid many horrible state issues where the prompt is not the last prompt
193
194
  def cmd(command, pre_read: true, rm_prompt: cmd_rm_prompt, rm_command: cmd_rm_command, prompt: current_prompt, **opts)
194
- opts = opts.clone.merge(pre_read: pre_read, rm_prompt: rm_prompt, rm_command: rm_command, prompt: prompt)
195
+ opts = opts.clone.merge(pre_read: pre_read, rm_prompt: rm_prompt, rm_command: rm_command, prompt: prompt)
195
196
  if pre_read
196
197
  pre_read_data = read
197
198
  logger.debug { "#cmd ignoring pre-command output: #{pre_read_data.inspect}" } if pre_read_data.present?
@@ -205,8 +206,8 @@ module Net
205
206
  alias command cmd
206
207
  alias exec cmd
207
208
 
208
- def cmds(commands, **opts)
209
- commands.map { |command| [command, cmd(command, **opts)] }
209
+ def cmds(*commands, **opts)
210
+ commands.flatten.map { |command| [command, cmd(command, **opts)] }
210
211
  end
211
212
  alias commands cmds
212
213
 
@@ -236,7 +237,7 @@ module Net
236
237
  return @net_ssh if @net_ssh
237
238
 
238
239
  logger.debug { 'Net:SSH #start' }
239
- self.net_ssh = Net::SSH.start(net_ssh_options[:ip] || net_ssh_options[:host] || "localhost", net_ssh_options[:user] || ENV['USER'], formatted_net_ssh_options)
240
+ self.net_ssh = Net::SSH.start(net_ssh_options[:ip] || net_ssh_options[:host] || 'localhost', net_ssh_options[:user] || ENV['USER'], formatted_net_ssh_options)
240
241
  rescue StandardError => error
241
242
  self.net_ssh = nil
242
243
  raise
@@ -244,7 +245,7 @@ module Net
244
245
  alias proxy net_ssh
245
246
 
246
247
  # have a deep look at the source of Net::SSH
247
- # session#process https://github.com/net-ssh/net-ssh/blob/dd13dd44d68b7fa82d4ca9a3bbe18e30c855f1d2/lib/net/ssh/connection/session.rb#L227
248
+ # session#process https://github.com/net-ssh/net-ssh/blob/dd13dd44d68b7fa82d4ca9a3bbe18e30c855f1d2/lib/net/ssh/connection/session.rb#L227
248
249
  # session#loop https://github.com/net-ssh/net-ssh/blob/dd13dd44d68b7fa82d4ca9a3bbe18e30c855f1d2/lib/net/ssh/connection/session.rb#L179
249
250
  # because the (cli) channel stays open, we always need to ensure that the ssh layer gets "processed" further. This can be done inside here automatically or outside in a separate event loop for the net_ssh connection.
250
251
  def process(time = process_time)
@@ -254,7 +255,7 @@ module Net
254
255
  end
255
256
 
256
257
  def open_channel # cli_channel
257
- before_open_channel_procs.each { |_name, a_proc| a_proc.call }
258
+ before_open_channel_procs.each { |_name, a_proc| instance_eval(&a_proc) }
258
259
  ::Timeout.timeout(open_channel_timeout, Error::OpenChannelTimeout) do
259
260
  net_ssh.open_channel do |new_channel|
260
261
  logger.debug 'channel is open'
@@ -268,13 +269,13 @@ module Net
268
269
  new_channel.on_data do |_ch, data|
269
270
  on_stdout(data)
270
271
  end
271
- #new_channel.on_extended_data do |_ch, type, data| end
272
- #new_channel.on_close do end
272
+ # new_channel.on_extended_data do |_ch, type, data| end
273
+ # new_channel.on_close do end
273
274
  end
274
275
  until channel do process end
275
276
  end
276
277
  logger.debug 'channel is ready, running callbacks now'
277
- after_open_channel_procs.each { |_name, a_proc| a_proc.call }
278
+ after_open_channel_procs.each { |_name, a_proc| instance_eval(&a_proc) }
278
279
  process
279
280
  self
280
281
  end
@@ -284,7 +285,7 @@ module Net
284
285
  self.channel = nil
285
286
  end
286
287
 
287
- private
288
+ private
288
289
 
289
290
  def with_prompts
290
291
  @with_prompts ||= []
@@ -312,7 +313,7 @@ end
312
313
  class Net::SSH::Connection::Session
313
314
  attr_accessor :cli_channels
314
315
  def cli(**opts)
315
- cli_session = Net::SSH::CLI::Session.new({net_ssh: self}.merge(opts))
316
+ cli_session = Net::SSH::CLI::Session.new({ net_ssh: self }.merge(opts))
316
317
  cli_session.open_channel
317
318
  cli_session
318
319
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Net
2
4
  module SSH
3
5
  module CLI
4
- VERSION = "0.3.0"
6
+ VERSION = '1.0.0'
5
7
  end
6
8
  end
7
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: 0.3.0
4
+ version: 1.0.0
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-03-14 00:00:00.000000000 Z
11
+ date: 2019-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
126
126
  - !ruby/object:Gem::Version
127
127
  version: '0'
128
128
  requirements: []
129
- rubygems_version: 3.0.2
129
+ rubygems_version: 3.0.3
130
130
  signing_key:
131
131
  specification_version: 4
132
132
  summary: 'Net::SSH::CLI: A library to handle CLI Sessions'