vx-lib-shell 0.1.2 → 0.1.3

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
  SHA1:
3
- metadata.gz: ac1de258197e6487b76d4b881ef6bb96050b8a02
4
- data.tar.gz: bc0e35943023134797f32e80676d95e4f3bb76a9
3
+ metadata.gz: e2b7d6fc28b5070948dd75094444b620d57f1163
4
+ data.tar.gz: 5987143de05073b0b25008041dc9896994cdf87a
5
5
  SHA512:
6
- metadata.gz: 7eeaa52a2799bacb5f906d6581b5adbb2842de78c768e1cb1a0bcb928681af1c24036185bd508bbe7ca21e97d14821f554b07570f8c3e53f993637a5d5dd4133
7
- data.tar.gz: 57edc0a4c994578ca8dc3cc14702087ad0253848c14a5f331dd6828428d4293119f2500a752c811e46250744205df40ac0983c40bdd54c958092d2f4f32dcf6c
6
+ metadata.gz: fd2eca44bf45eb1a9814f8e55861b1fec627c8c28fc71fae42e6792a63d39109a5b73723c8fecc79a18989d70ca384d15fd77495e955057e299849b4919316ef
7
+ data.tar.gz: d249cb474a35de4a6a80ed9e5fe329c1f83dcc88bee6006da656ebc32385351b907cda5545d4672326e0a645f148a187ea3b48f16173225d1b510e9434fdd22d
@@ -18,11 +18,7 @@ module Vx
18
18
  read_timeout = Shell::ReadTimeout.new options.delete(:read_timeout)
19
19
 
20
20
  prefix = "/usr/bin/env - TERM=ansi USER=$USER HOME=#{home} SHELL=/bin/bash /bin/bash -l"
21
- if command
22
- command = "#{prefix} -c #{Shellwords.escape command}"
23
- else
24
- command = prefix
25
- end
21
+ command = "#{prefix} -c #{Shellwords.escape command}"
26
22
 
27
23
  status = spawn_command_internal(command, options) do |r|
28
24
  read_loop r, timeout, read_timeout, select_timeout, &block
@@ -35,25 +31,20 @@ module Vx
35
31
 
36
32
  def request_pipes(options)
37
33
  m,s = PTY.open
38
- r1,w1 = IO.pipe
39
34
 
40
35
  s.raw! # disable newline conversion.
41
36
  m.sync = true
42
37
  s.sync = true
43
38
 
44
- [m, s, r1, w1]
39
+ [m, s]
45
40
  end
46
41
 
47
42
  def spawn_command_internal(command, options)
48
- r1, w1, r2, w2 = request_pipes(options)
43
+ r1, w1 = request_pipes(options)
49
44
 
50
- pid = ::Process.spawn(command, in: r2, out: w1, err: w1)
45
+ pid = ::Process.spawn(command, out: w1, err: w1)
51
46
 
52
47
  begin
53
- if i = options[:stdin]
54
- IO.copy_stream i, w2
55
- end
56
- w2.close
57
48
  w1.close
58
49
 
59
50
  yield r1
@@ -64,7 +55,6 @@ module Vx
64
55
  _, status = ::Process.wait2(pid)
65
56
 
66
57
  r1.close
67
- r2.close
68
58
 
69
59
  status
70
60
  end
@@ -23,11 +23,7 @@ module Vx
23
23
  read_timeout = Shell::ReadTimeout.new options.delete(:read_timeout)
24
24
 
25
25
  prefix = "/usr/bin/env - TERM=ansi USER=$USER HOME=#{home} SHELL=/bin/bash /bin/bash -l"
26
- if command
27
- command = "#{prefix} -c #{Shellwords.escape command}"
28
- else
29
- command = prefix
30
- end
26
+ command = "#{prefix} -c #{Shellwords.escape command}"
31
27
 
32
28
  channel = spawn_channel command, read_timeout, options, &block
33
29
 
@@ -47,7 +43,7 @@ module Vx
47
43
  private
48
44
 
49
45
  def request_pty(channel, options)
50
- channel.request_pty term: "ansi" do |_, pty_status|
46
+ channel.request_pty do |_, pty_status|
51
47
  raise StandardError, "could not obtain pty (ssh.channel.request_pty)" unless pty_status
52
48
  yield if block_given?
53
49
  end
@@ -87,11 +83,6 @@ module Vx
87
83
  raise StandardError, "FAILED: couldn't execute command (ssh.channel.exec)"
88
84
  end
89
85
 
90
- if i = options[:stdin]
91
- channel.send_data i.read
92
- channel.eof!
93
- end
94
-
95
86
  channel.on_data do |_, data|
96
87
  yield data if block_given?
97
88
  read_timeout.reset
@@ -1,7 +1,7 @@
1
1
  module Vx
2
2
  module Lib
3
3
  module Shell
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.3"
5
5
  end
6
6
  end
7
7
  end
@@ -23,13 +23,13 @@ describe Vx::Lib::Shell::Process do
23
23
  context "timeout" do
24
24
  it 'run command with timeout' do
25
25
  expect {
26
- run("echo $USER && sleep 0.5", timeout: 0.2, pty: pty)
26
+ run("echo $USER && sleep 0.5", timeout: 0.2)
27
27
  }.to raise_error(::Vx::Lib::Shell::TimeoutError)
28
28
  expect(subject.strip).to eq "#{user}"
29
29
  end
30
30
 
31
31
  it 'run command with timeout successfuly' do
32
- code = run("echo BAR && sleep 0.1", timeout: 0.5, pty: pty)
32
+ code = run("echo BAR && sleep 0.1", timeout: 0.5)
33
33
  expect(subject.strip).to eq "BAR"
34
34
  expect(code).to eq 0
35
35
  end
@@ -45,43 +45,36 @@ describe Vx::Lib::Shell::Process do
45
45
 
46
46
  it 'run command with read timeout in loop' do
47
47
  expect{
48
- run('sleep 0.1 ; echo $USER ; sleep 0.5', read_timeout: 0.3, pty: pty)
48
+ run('sleep 0.1 ; echo $USER ; sleep 0.5', read_timeout: 0.3)
49
49
  }.to raise_error(Vx::Lib::Shell::ReadTimeoutError)
50
50
  expect(collected.strip).to eq "#{user}"
51
51
  end
52
52
 
53
53
  it 'run command with read timeout successfuly' do
54
- code = run('echo $USER; sleep 0.1', read_timeout: 0.5, pty: pty)
54
+ code = run('echo $USER; sleep 0.1', read_timeout: 0.5)
55
55
  expect(collected.strip).to eq "#{user}"
56
56
  expect(code).to eq 0
57
57
  end
58
58
 
59
59
  it 'run command with read timeout in loop successfuly' do
60
- code = run('sleep 0.3 ; echo $USER; sleep 0.3 ; echo $USER', read_timeout: 0.5, pty: pty)
60
+ code = run('sleep 0.3 ; echo $USER; sleep 0.3 ; echo $USER', read_timeout: 0.5)
61
61
  expect(collected).to eq "#{user}\n#{user}\n"
62
62
  expect(code).to eq 0
63
63
  end
64
64
  end
65
65
 
66
66
  it 'run and kill process' do
67
- code = run( "echo $USER; kill -KILL $$", pty: pty)
67
+ code = run( "echo $USER; kill -KILL $$")
68
68
  expect(subject).to eq "#{user}\n"
69
69
  expect(code).to eq(-9)
70
70
  end
71
71
 
72
72
  it 'run and interupt process' do
73
- code = run( "echo $USER; kill -INT $$", pty: pty)
73
+ code = run( "echo $USER; kill -INT $$")
74
74
  expect(subject).to eq "#{user}\n"
75
75
  expect(code).to eq(-2)
76
76
  end
77
77
 
78
- it "should copy stdin" do
79
- io = StringIO.new("echo foo ; exit")
80
- code = run(stdin: io)
81
- expect(subject).to eq "foo\n"
82
- expect(code).to eq 0
83
- end
84
-
85
78
  def run(*args, &block)
86
79
  @proxy ||= ShellTest.new
87
80
  timeout do
data/spec/lib/ssh_spec.rb CHANGED
@@ -87,13 +87,6 @@ describe Vx::Lib::Shell::SSH, ssh: true do
87
87
  expect(code).to eq(-4)
88
88
  end
89
89
 
90
- it "should copy stdin" do
91
- io = StringIO.new("echo foo ; exit\n")
92
- code = run_ssh(stdin: io)
93
- expect(collected).to match "foo\r\n"
94
- expect(code).to eq 0
95
- end
96
-
97
90
  def open_ssh(&block)
98
91
  described_class.open(host, user, password: pass, paranoid: false, verbose: 2, port: port, &block)
99
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vx-lib-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Galinsky