net-ssh-cli 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df1b678f96b5758f1c1d5c17af957b177d2ca266e3c184a1e1df0e6124c3cd2f
4
- data.tar.gz: a645c159917d066d1c86f7a6afb69fc7932c1ff7059524cbf296864673fc6454
3
+ metadata.gz: fab3c1030af162f3166a59820d542a60e020b1cb14dbf11cf9ebc4421242fa3a
4
+ data.tar.gz: cb0391c25fea6a1a2f5762eb6131a737bd51bf6a00e48807fdf486a3d9a4aa96
5
5
  SHA512:
6
- metadata.gz: fa3eef297fc1650a67a4c5245bee743640ab146e615e683afd2349a0d996760d7ad7076a29fb3922880f92a76532f1b69f54d0209241925f1fb53d2b6ef3509a
7
- data.tar.gz: c438a6ec62a4416847dec30ce3fd2c0365bf05c5e9a18f3791b6c8405ac1e516dbad45e452c8f9d781008d2992a40a50b4a8364e789fb1b37c1db888e57dce38
6
+ metadata.gz: 825b5a40f8ffd7ad64ba817c8de01bd9a9fdc15289ea400f18da3dd2f60b2e6ccf5a5ae75f453d1a3649a05fcf9e0a9722e6194ad264337f71211836290e5695
7
+ data.tar.gz: ecfefd65bb0c0f9132bfd911e4a42b8640e85281dabd19311fc6fd7240549d9220f2280bb461fd440780ff1df8b903c812cb1620e16a9fd7ce33c0996fd1f244
data/README.md CHANGED
@@ -69,6 +69,15 @@ Remove the command and the prompt for #cmd & #dialog by default
69
69
  # => "bananas"
70
70
  ```
71
71
 
72
+ ### #cmds
73
+
74
+ It's the same as #cmd but for multiple commands.
75
+
76
+ ```ruby
77
+ cli.cmds ["echo 'bananas'", "echo 'apples'"], rm_command: true, rm_prompt: true
78
+ # => ["bananas", "apples"]
79
+ ```
80
+
72
81
  ### #dialog
73
82
  ```ruby
74
83
  cli.dialog "echo 'are you sure?' && read -p 'yes|no>'", /\nyes|no>/
@@ -76,6 +85,25 @@ Remove the command and the prompt for #cmd & #dialog by default
76
85
  cli.cmd "yes"
77
86
  ```
78
87
 
88
+ ### #impact
89
+
90
+ The very same as `#cmd` but it respects a flag whether to run commands with 'impact'.
91
+ This can be used in a setup where you don't want to run certain commands under certain conditions.
92
+ For example in testing.
93
+
94
+ ```ruby
95
+ cli.run_impact?
96
+ # => false
97
+ cli.impact "reboot now"
98
+ # => "skip: 'reboot now'"
99
+ ```
100
+
101
+ ```ruby
102
+ cli.run_impact = true
103
+ cli.impact "reboot now"
104
+ # => connection closed
105
+ ```
106
+
79
107
  ### #read & #write
80
108
 
81
109
  ```ruby
@@ -94,17 +122,28 @@ Remove the command and the prompt for #cmd & #dialog by default
94
122
  ### #read_till
95
123
  keep on processing till the stdout matches to given|default prompt and then read the whole stdin.
96
124
  ```ruby
97
- cli.write "\n"
125
+ cli.write "echo 'hello'\n"
98
126
  # => "echo 'hello'\n"
99
127
  cli.read_till
100
128
  # => "echo 'hello'\nhello\nuser@host:"
101
129
  ```
102
130
 
103
- This method is used by #cmd
131
+ This method is used by #cmd, see ``lib/net/ssh/cli.rb#cmd``
132
+
133
+ ### #read_for
134
+
135
+ ```ruby
136
+ cli.write_n "sleep 180"
137
+ # => ""
138
+ cli.read_for(seconds: 181)
139
+ # => "..."
140
+ ```
104
141
 
105
142
  ## Configuration
106
143
 
107
- Have a deep look at ``Net::SSH::CLI::OPTIONS`` at ``lib/net/ssh/cli.rb``
144
+ Have a deep look at the various Options configured by ``Net::SSH::CLI::OPTIONS`` in ``lib/net/ssh/cli.rb``
145
+ Nearly everything can be configured.
146
+
108
147
 
109
148
  ### Callbacks
110
149
 
@@ -120,6 +159,36 @@ cli.before_open_channel do
120
159
  end
121
160
  ```
122
161
 
162
+ ```ruby
163
+ cli.after_open_channel do
164
+ cmd "logger 'Net::SSH::CLI works'"
165
+ cmd "sudo -i"
166
+ end
167
+ ```
168
+
169
+ ### #hostname #host #to_s
170
+
171
+ ```ruby
172
+ cli.to_s
173
+ # => "localhost"
174
+ cli.hostname
175
+ # => "localhost"
176
+ cli.host
177
+ # => "localhost"
178
+ ```
179
+
180
+ ### #detect_prompt
181
+
182
+ NET::SSH::CLI can try to guess the prompt by waiting for it and using the last line.
183
+ This works usually, but is not guaranteed to work well.
184
+
185
+ ```ruby
186
+ cli.open_channel
187
+ # => ...
188
+ cli.detect_prompt(seconds: 3)
189
+ # => "[my prompt]"
190
+ ```
191
+
123
192
  ## Development
124
193
 
125
194
  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
@@ -32,10 +32,11 @@ module Net
32
32
  options.merge!(opts)
33
33
  self.net_ssh = options.delete(:net_ssh)
34
34
  self.logger = options.delete(:logger) || Logger.new(STDOUT, level: Logger::WARN)
35
+ self.process_count = 0
35
36
  @new_data = String.new
36
37
  end
37
38
 
38
- attr_accessor :channel, :stdout, :net_ssh, :logger, :new_data
39
+ attr_accessor :channel, :stdout, :net_ssh, :logger, :new_data, :process_count
39
40
 
40
41
  OPTIONS = ActiveSupport::HashWithIndifferentAccess.new(
41
42
  default_prompt: /\n?^(\S+@.*)\z/, # the default prompt to search for
@@ -106,7 +107,9 @@ module Net
106
107
  before_on_stdout_procs.each { |_name, a_proc| instance_eval(&a_proc) }
107
108
  stdout << new_data
108
109
  after_on_stdout_procs.each { |_name, a_proc| instance_eval(&a_proc) }
109
- process # if we receive data, we probably receive more - improves performance
110
+ self.process_count += 1
111
+ process unless process_count > 100 # if we receive data, we probably receive more - improves performance - but on a lot of data, this leads to a stack level too deep
112
+ self.process_count -= 1
110
113
  stdout
111
114
  end
112
115
 
@@ -3,7 +3,7 @@
3
3
  module Net
4
4
  module SSH
5
5
  module CLI
6
- VERSION = '1.2.0'
6
+ VERSION = '1.2.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.2.0
4
+ version: 1.2.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-05-10 00:00:00.000000000 Z
11
+ date: 2019-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler