net-ssh-cli 1.7.0 → 1.8.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 +4 -4
- data/README.md +53 -1
- data/lib/net/ssh/cli.rb +5 -3
- data/lib/net/ssh/cli/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3557b2b202abb2f722b950d3f16d0e1c36a57716289f138d4c7f04edb453546
|
4
|
+
data.tar.gz: 8e58d5fa7d2e89021ffcb10751fff17526542d1d16314f79769f7e5f67451ea0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 447b6ac1b58038620c3886241352e48bf5b89cbe0512a9506e08ab359378f62d3629f0007516bbcf4c360e204ea259d865d65e6396ee66d5d10c8c05275ede08
|
7
|
+
data.tar.gz: a898d86bf7d7fdde7977bd6161e1801606da032b96e3fb04ba6c55a6e104d1d2db0e8f68b12763afb63fee036c19e3c087af203563323543d4328a5fb61c487d
|
data/README.md
CHANGED
@@ -60,6 +60,12 @@ end
|
|
60
60
|
# => "echo 'bananas'\nbananas"
|
61
61
|
cli.cmd "echo 'bananas'", rm_command: true, rm_prompt: true
|
62
62
|
# => "bananas"
|
63
|
+
cli.cmd "echo 'bananas'", rm_command: true, rm_prompt: true, minimum_duration: 9
|
64
|
+
# => "bananas"
|
65
|
+
cli.cmd "echo 'bananas'", rm_command: true, rm_prompt: true, prompt: /\nuser@host:/m
|
66
|
+
# => "bananas"
|
67
|
+
cli.cmd "echo 'bananas'", rm_command: true, rm_prompt: true, timeout: 60
|
68
|
+
# => "bananas"
|
63
69
|
```
|
64
70
|
|
65
71
|
Remove the command and the prompt for #cmd & #dialog by default
|
@@ -69,9 +75,23 @@ Remove the command and the prompt for #cmd & #dialog by default
|
|
69
75
|
# => "bananas"
|
70
76
|
```
|
71
77
|
|
78
|
+
You can define a timeout for a `#cmd` in order to avoid hanging commands. The timeout gets passed into the underlying function #read_till.
|
79
|
+
This is usefull in case your prompt won't match because of an unexpected behaviour or undefined behaviour. For example some form of unexpected dialog.
|
80
|
+
The underlying implementation is using a soft timeout because `Timeout.timeout` is dangerous. In order to deal anyway with hanging low level issues, `Timeout.timeout` is used too, but with a higher value than the soft timeout.
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
cli = ssh.cli(default_prompt: /(\nuser@host):/m, read_till_timeout: 11)
|
84
|
+
cli.cmd "echo 'bananas'" # timeout is set to 11
|
85
|
+
# => "bananas"
|
86
|
+
cli.cmd "echo 'bananas'", timeout: 22 # timeout is set to 22
|
87
|
+
# => "bananas"
|
88
|
+
cli.cmd "sleep 33", timeout: 22 # timeout is set to 22
|
89
|
+
# Net::SSH::CLI::Error::CMD
|
90
|
+
```
|
91
|
+
|
72
92
|
### #cmds
|
73
93
|
|
74
|
-
It's the same as
|
94
|
+
It's the same as `#cmd` but for multiple commands.
|
75
95
|
|
76
96
|
```ruby
|
77
97
|
cli.cmds ["echo 'bananas'", "echo 'apples'"], rm_command: true, rm_prompt: true
|
@@ -236,6 +256,38 @@ This works usually, but is not guaranteed to work well.
|
|
236
256
|
# => "[my prompt]"
|
237
257
|
```
|
238
258
|
|
259
|
+
### An outdated view of all available Options
|
260
|
+
|
261
|
+
Please check the file `lib/net/ssh/cli.rb` `OPTIONS` in order to get an up-to-date view of all available options, flags and arguments.
|
262
|
+
|
263
|
+
```ruby
|
264
|
+
OPTIONS = ActiveSupport::HashWithIndifferentAccess.new(
|
265
|
+
default_prompt: /\n?^(\S+@.*)\z/, # the default prompt to search for
|
266
|
+
cmd_rm_prompt: false, # whether the prompt should be removed in the output of #cmd
|
267
|
+
cmd_rm_command: false, # whether the given command should be removed in the output of #cmd
|
268
|
+
cmd_rm_command_tail: "\n", # which format does the end of line return after a command has been submitted. Could be something like "ls\n" "ls\r\n" or "ls \n" (extra spaces)
|
269
|
+
run_impact: false, # whether to run #impact commands. This might align with testing|development|production. example #impact("reboot")
|
270
|
+
read_till_timeout: nil, # timeout for #read_till to find the match
|
271
|
+
read_till_hard_timeout: nil, # hard timeout for #read_till to find the match using Timeout.timeout(hard_timeout) {}. Might creates unpredicted sideffects
|
272
|
+
read_till_hard_timeout_factor: 1.2, # hard timeout factor in case read_till_hard_timeout is true
|
273
|
+
named_prompts: ActiveSupport::HashWithIndifferentAccess.new, # you can used named prompts for #with_prompt {}
|
274
|
+
before_cmd_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call before #cmd
|
275
|
+
after_cmd_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call after #cmd
|
276
|
+
before_on_stdout_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call before data arrives from the underlying connection
|
277
|
+
after_on_stdout_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call after data arrives from the underlying connection
|
278
|
+
before_on_stdin_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call before data is sent to the underlying channel
|
279
|
+
after_on_stdin_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call after data is sent to the underlying channel
|
280
|
+
before_open_channel_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call before opening a channel
|
281
|
+
after_open_channel_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call after opening a channel, for example you could call #detect_prompt or #read_till
|
282
|
+
open_channel_timeout: nil, # timeout to open the channel
|
283
|
+
net_ssh_options: ActiveSupport::HashWithIndifferentAccess.new, # a wrapper for options to pass to Net::SSH.start in case net_ssh is undefined
|
284
|
+
process_time: 0.00001, # how long #process is processing net_ssh#process or sleeping (waiting for something)
|
285
|
+
background_processing: false, # default false, whether the process method maps to the underlying net_ssh#process or the net_ssh#process happens in a separate loop
|
286
|
+
on_stdout_processing: 100, # whether to optimize the on_stdout performance by calling #process #optimize_on_stdout-times in case more data arrives
|
287
|
+
sleep_procs: ActiveSupport::HashWithIndifferentAccess.new, # procs to call instead of Kernel.sleep(), perfect for async hooks
|
288
|
+
)
|
289
|
+
```
|
290
|
+
|
239
291
|
## Development
|
240
292
|
|
241
293
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/net/ssh/cli.rb
CHANGED
@@ -40,10 +40,11 @@ module Net
|
|
40
40
|
attr_accessor :channel, :stdout, :net_ssh, :logger, :new_data, :process_count
|
41
41
|
|
42
42
|
OPTIONS = ActiveSupport::HashWithIndifferentAccess.new(
|
43
|
-
default_prompt: /\n?^(\S+@.*)\z/, # the default prompt to search for
|
43
|
+
default_prompt: /\n?^(\S+@.*)\z/, # the default prompt to search for. It is recommended to use \z to ensure you don't match the prompt too early.
|
44
44
|
cmd_rm_prompt: false, # whether the prompt should be removed in the output of #cmd
|
45
45
|
cmd_rm_command: false, # whether the given command should be removed in the output of #cmd
|
46
46
|
cmd_rm_command_tail: "\n", # which format does the end of line return after a command has been submitted. Could be something like "ls\n" "ls\r\n" or "ls \n" (extra spaces)
|
47
|
+
cmd_minimum_duration: 0, # how long do you want to wait/sleep after sending the command. After this waiting time, the output will be processed and the prompt will be searched.
|
47
48
|
run_impact: false, # whether to run #impact commands. This might align with testing|development|production. example #impact("reboot")
|
48
49
|
read_till_timeout: nil, # timeout for #read_till to find the match
|
49
50
|
read_till_hard_timeout: nil, # hard timeout for #read_till to find the match using Timeout.timeout(hard_timeout) {}. Might creates unpredicted sideffects
|
@@ -253,9 +254,9 @@ module Net
|
|
253
254
|
# 2. continues to process the ssh connection until the prompt is found in the stdout
|
254
255
|
# 3. prepares the output using your callbacks
|
255
256
|
# 4. returns the output of your command
|
256
|
-
# Hint: 'read' first on
|
257
|
+
# Hint: 'read' first on purpose as a feature. once you cmd you ignore what happend before. otherwise use read|write directly.
|
257
258
|
# this should avoid many horrible state issues where the prompt is not the last prompt
|
258
|
-
def cmd(command, pre_read: true, rm_prompt: cmd_rm_prompt, rm_command: cmd_rm_command, prompt: current_prompt, **opts)
|
259
|
+
def cmd(command, pre_read: true, rm_prompt: cmd_rm_prompt, rm_command: cmd_rm_command, prompt: current_prompt, minimum_duration: cmd_minimum_duration, **opts)
|
259
260
|
opts = opts.clone.merge(pre_read: pre_read, rm_prompt: rm_prompt, rm_command: rm_command, prompt: prompt)
|
260
261
|
if pre_read
|
261
262
|
pre_read_data = read
|
@@ -263,6 +264,7 @@ module Net
|
|
263
264
|
end
|
264
265
|
before_cmd_procs.each { |_name, a_proc| instance_eval(&a_proc) }
|
265
266
|
write_n command
|
267
|
+
sleep(minimum_duration)
|
266
268
|
output = read_till(**opts)
|
267
269
|
rm_prompt!(output, **opts)
|
268
270
|
rm_command!(output, command, **opts)
|
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.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fabian Stillhart
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-04-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -125,7 +125,7 @@ homepage: https://github.com/swisscom/net-ssh-cli
|
|
125
125
|
licenses:
|
126
126
|
- MIT
|
127
127
|
metadata: {}
|
128
|
-
post_install_message:
|
128
|
+
post_install_message:
|
129
129
|
rdoc_options: []
|
130
130
|
require_paths:
|
131
131
|
- lib
|
@@ -140,8 +140,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
140
140
|
- !ruby/object:Gem::Version
|
141
141
|
version: '0'
|
142
142
|
requirements: []
|
143
|
-
rubygems_version: 3.2.
|
144
|
-
signing_key:
|
143
|
+
rubygems_version: 3.2.15
|
144
|
+
signing_key:
|
145
145
|
specification_version: 4
|
146
146
|
summary: 'Net::SSH::CLI: A library to handle CLI Sessions'
|
147
147
|
test_files: []
|