proclib 0.1.1 → 0.1.2

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: 0f14da2636c7920354164801ec23b79a257e0bf1
4
- data.tar.gz: 804b5af1d78d5f3295688362451ca40ca719213e
3
+ metadata.gz: ba4b02e8d72fd8a8d8d9b0516aa7ab9dfa501099
4
+ data.tar.gz: 6f7f96bbf764a5bdb87cc3984f4dec1679e616eb
5
5
  SHA512:
6
- metadata.gz: 7df0c94025f7aac0fc1cd90631799b49978c6aad6ab0e03be49c944e2a3eeeac28ece0c7ded5ed95218da6922fc37ce711102fa511bfab4cfe33676c0adadaf7
7
- data.tar.gz: 8f8b399172a311691292f17dd0e9a3f9bf2ffc74bdf162bbd54bbe46b5cb9b37703c0d49b0844bf1e42637eea3a865b087b5c36767665bd581a34d8d3944f666
6
+ metadata.gz: b082cc0aaff885ec30f9e86fbedfe5f292a46894df601d8e620400ab604bee003c4207217a7e2d16cc86e0c5740cf716945ab946e3fec0050bad8fc8a776345b
7
+ data.tar.gz: 48530c111e4ce5d5df119c8704bda9b92ce680b5a06f39a86256cccbeeac4e7dfa8ba1b90d5bf6abb1d68221b0fcaa59408698f8389b90d20c822839955e2f7d
@@ -11,6 +11,10 @@ require_relative '../lib/proclib'
11
11
 
12
12
  Proclib.run("echo herorooo >&2", tag: :test, log_to_console: true)
13
13
 
14
+ # Pass env vars to subprocess
15
+
16
+ Proclib.run("echo $FOO", env: {FOO: 'hi'}, log_to_console: true)
17
+
14
18
  _, stdout, _ = Proclib.run("ls /tmp/", capture_output: true)
15
19
 
16
20
  puts "Files in /tmp"
@@ -14,12 +14,15 @@ module Proclib
14
14
  tag: nil,
15
15
  log_to_console: false,
16
16
  capture_output: true,
17
+ env: {},
17
18
  on_output: nil)
18
19
 
20
+ raise(ArgumentError, "env must be a Hash") unless env.kind_of?(Hash)
21
+
19
22
  runnable = if cmd.kind_of? String
20
- Process.new(cmd, tag: tag || cmd[0..20])
23
+ Process.new(cmd, tag: tag || cmd[0..20], env: env)
21
24
  elsif cmd.kind_of?(Hash)
22
- processes = cmd.map {|(k,v)| Process.new(v, tag: k || v[0..20]) }
25
+ processes = cmd.map {|(k,v)| Process.new(v, tag: k || v[0..20], env: env) }
23
26
  ProcessGroup.new(processes)
24
27
  else
25
28
  raise ArgumentError, "Unexpected type for `cmd`: #{cmd.class}. \n"\
@@ -35,7 +38,6 @@ module Proclib
35
38
  on_output: on_output,
36
39
  cache_output: capture_output)
37
40
 
38
-
39
41
  executor.run_sync
40
42
  end
41
43
  end
@@ -8,13 +8,14 @@ module Proclib
8
8
  class Process
9
9
  include EventEmitter::Producer
10
10
 
11
- attr_reader :cmdline, :tag
11
+ attr_reader :cmdline, :tag, :env
12
12
 
13
13
  Error = Class.new(StandardError)
14
14
 
15
- def initialize(cmdline, tag:)
15
+ def initialize(cmdline, tag:, env: {})
16
16
  @cmdline = cmdline
17
17
  @tag = tag
18
+ @env = env.map {|k,v| [k.to_s, v.to_s]}.to_h
18
19
  @state = :ready
19
20
  @io_handlers = OpenStruct.new
20
21
  @pipes = OpenStruct.new
@@ -23,7 +24,7 @@ module Proclib
23
24
  def spawn
24
25
  raise(Error, "Already started process") unless @wait_thread.nil?
25
26
 
26
- pipes.stdin, pipes.stdout, pipes.stderr, @wait_thread = Open3.popen3(cmdline)
27
+ pipes.stdin, pipes.stdout, pipes.stderr, @wait_thread = Open3.popen3(env, cmdline)
27
28
  @state = :running?
28
29
  start_output_emitters
29
30
  start_watch_thread
@@ -1,3 +1,3 @@
1
1
  module Proclib
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
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.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jack Forrest