proclib 0.2.2 → 0.2.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: d6212650eff9983728f4fb27e15da5f0d1ecd0b9
4
- data.tar.gz: da2f686f9549288c78a92f8a0c9797006398e00d
3
+ metadata.gz: ee04281f5c38f3ceddc62dbe3b808ac54bd351bc
4
+ data.tar.gz: 3ac72aa351dca2b23e726c8fc632243b04691205
5
5
  SHA512:
6
- metadata.gz: ec307361563e72615dff68ff55ebd5ad12a160331e08ff54d5a612541f943fedcf2d0ed32c9395f93bdb0474ad2a720d281038a02892f56aed901b72dea082f5
7
- data.tar.gz: 5441bea3cc830c74e9ee62eaf7201c59b7114a46f66d1440b32142264a9a81f4e54024b7e9fed8c7d937a52b1ea5497162c56ef5c1f2e11e906eea2690cd56ed
6
+ metadata.gz: cc1ab51247d14584cca686d7695d09cb6c1942fb7bf134c10e909cc242936972b63291ae0d4789c33c28fa61860acabaab68963810ba6e1484ca47e9ed808fc0
7
+ data.tar.gz: 460f4341cdcddeaf9873b075725672ca764093f65ab1566fe17813a9cc57b8ffe917ebe08075015b8564ce936f994624190e1fa389dfce37dda32ceb15d28e9d
@@ -8,6 +8,7 @@ module Proclib
8
8
  log_to_console: false,
9
9
  capture_output: true,
10
10
  env: {},
11
+ stdin: nil,
11
12
  on_output: nil,
12
13
  cwd: nil,
13
14
  ssh: nil
@@ -16,6 +17,7 @@ module Proclib
16
17
  tag: tag,
17
18
  env: env,
18
19
  cwd: cwd,
20
+ stdin: stdin,
19
21
  ssh: ssh)
20
22
 
21
23
  executor = Executor.new(inv.commands,
@@ -8,13 +8,16 @@ module Proclib
8
8
  NotYetRunning = Class.new(Error)
9
9
  NotYetTerminated = Class.new(Error)
10
10
 
11
- attr_reader :tag, :cmdline, :env, :run_dir
11
+ STDIN_BUF_SIZE = 1024 * 1024
12
12
 
13
- def initialize(tag: nil, cmdline:, env: {} , run_dir: nil)
13
+ attr_reader :tag, :cmdline, :env, :run_dir, :stdin
14
+
15
+ def initialize(tag: nil, cmdline:, env: {}, run_dir: nil, stdin: nil)
14
16
  @env = env.map {|k,v| [k.to_s, v.to_s]}.to_h
15
17
  @cmdline = cmdline
16
18
  @tag = tag || cmdline[0..20]
17
19
  @run_dir = run_dir
20
+ @stdin = stdin
18
21
  end
19
22
 
20
23
  def pipes
@@ -14,6 +14,16 @@ module Proclib
14
14
  else
15
15
  spawn.call
16
16
  end
17
+
18
+ unless stdin.nil?
19
+ until stdin.eof?
20
+ pipes.stdin.write(stdin.read(STDIN_BUF_SIZE))
21
+ end
22
+
23
+ stdin.close
24
+ end
25
+
26
+ pipes.stdin.close
17
27
  end
18
28
 
19
29
  def wait
@@ -15,9 +15,16 @@ module Proclib
15
15
  def spawn
16
16
  write_pipes
17
17
 
18
- open_channel do |ch|
19
- ch.exec(cmdline) do |_, success|
18
+ open_channel do |channel|
19
+ channel.exec(cmdline) do |_, success|
20
20
  raise SSHError, "Command Failed" unless success
21
+
22
+ if !stdin.nil?
23
+ while msg = stdin.read(STDIN_BUF_SIZE)
24
+ channel.send_data(msg)
25
+ end
26
+ channel.eof!
27
+ end
21
28
  end
22
29
  end
23
30
  end
@@ -53,6 +60,7 @@ module Proclib
53
60
  @result = data.read_long
54
61
  end
55
62
 
63
+
56
64
  yield channel
57
65
  end
58
66
  end
@@ -15,6 +15,7 @@ module Proclib
15
15
  tag: nil,
16
16
  env: {},
17
17
  cwd: nil,
18
+ stdin: nil,
18
19
  ssh: nil
19
20
  )
20
21
  @cmd = cmd
@@ -22,6 +23,7 @@ module Proclib
22
23
  @env = env
23
24
  @cwd = cwd
24
25
  @ssh = ssh
26
+ @stdin = stdin
25
27
  end
26
28
 
27
29
  def commands
@@ -45,6 +47,7 @@ module Proclib
45
47
  tag: @tag,
46
48
  env: validated_env,
47
49
  run_dir: validated_cwd,
50
+ stdin: validated_stdin,
48
51
  cmdline: validated_cmd
49
52
  }.tap do |args|
50
53
  args[:ssh_session] = validated_ssh if !validated_ssh.nil?
@@ -117,5 +120,19 @@ module Proclib
117
120
  @cmd
118
121
  end
119
122
  end
123
+
124
+ def validated_stdin
125
+ @validated_stdin ||= begin
126
+ return nil if @stdin.nil?
127
+
128
+ if %i(eof? read close).none? {|m| @stdin.respond_to?(m) }
129
+ raise Invalid, "Expected stdin to to be IO."
130
+ elsif !@cmd.kind_of?(String)
131
+ raise Invalid, "Stdin can not be given when running simultaneous commands."
132
+ end
133
+
134
+ @stdin
135
+ end
136
+ end
120
137
  end
121
138
  end
@@ -13,6 +13,7 @@ module Proclib
13
13
  env: {},
14
14
  on_output: nil,
15
15
  cwd: nil,
16
+ stdin: nil,
16
17
  ssh: nil
17
18
  )
18
19
 
@@ -20,6 +21,7 @@ module Proclib
20
21
  tag: tag,
21
22
  env: env,
22
23
  ssh: session,
24
+ stdin: stdin,
23
25
  cwd: cwd)
24
26
 
25
27
  executor = Executor.new(inv.commands,
@@ -1,3 +1,3 @@
1
1
  module Proclib
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proclib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Forrest