libexec 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: faa9c299dd68921cd9fc29dcb8773394a9c2e12d86882e419d38e5fa2390243a
4
- data.tar.gz: 6bb3a7a8531c97c64289fd5a8cce7a4787e0ea43011bbc1e495072742c04699f
3
+ metadata.gz: a3d8b26a3b51d11a80ee0b158da31636268490b6b7141f9c0953934df47341f8
4
+ data.tar.gz: 31ee9aeae742be7e66c6f8c020957214a22af6edccf9d6131200b2c5b9a34182
5
5
  SHA512:
6
- metadata.gz: 3f4a070e82ef3f3751852ae3e27533f9be28e2f83b26204124e091d563b509525cde6338c576e0966486f0aebbcadc5f71bdaa4cc74538b67f713a4d8c7e17d9
7
- data.tar.gz: 8a92d8e88a3c17ba0ea4f25853224ba5a07cba49d6a26e7cb38d0c2ad34a3842a85ba3953e7c57102789a76bfd8b2e4e6991fd9f533c39f41bc6dee84888a65f
6
+ metadata.gz: e15fe7d30af4bbc40b400b7aef5b51208d2478127bc4e23d1488ed80483be8a907711164b94a40655361286a6310d0f821614e469c1a3e2f536c56c9ca8cc290
7
+ data.tar.gz: 85858c2cf6fc6be5e607245c332f79aea2e26444f807a9937fba72fbb40b52c94df0ae410d3d0da9222b5c6e855ebfbb15721af0ee1f121c0d1cd8d5a83a649d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- libexec (0.1.0)
4
+ libexec (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/libexec/exec.rb CHANGED
@@ -2,17 +2,40 @@
2
2
 
3
3
  module Libexec
4
4
  module Exec
5
- def run(cmd)
5
+ def run(cmd, *argv, env: {}, mode: "r", **opts)
6
+ unless argv.empty?
7
+ cmd = [cmd]
8
+ argv.each do |arg|
9
+ # https://docs.ruby-lang.org/en/master/Kernel.html#method-i-class
10
+ if arg.instance_of?(Array)
11
+ cmd.concat(arg)
12
+ elsif arg.instance_of?(String)
13
+ cmd.push(arg)
14
+ end
15
+ end
16
+ end
17
+
6
18
  # https://docs.ruby-lang.org/en/master/IO.html#method-c-popen
7
- IO.popen(cmd) do |pipe|
19
+ IO.popen(env, cmd, mode, opts) do |pipe|
8
20
  print pipe.gets until pipe.eof?
9
21
  end
10
22
  nil
11
23
  end
12
24
 
13
- def each_line(cmd, &block)
25
+ def each_line(cmd, *argv, env: {}, mode: "r", **opts, &block)
26
+ unless argv.empty?
27
+ cmd = [cmd]
28
+ argv.each do |arg|
29
+ if arg.instance_of?(Array)
30
+ cmd.concat(arg)
31
+ elsif arg.instance_of?(String)
32
+ cmd.push(arg)
33
+ end
34
+ end
35
+ end
36
+
14
37
  # https://docs.ruby-lang.org/en/master/IO.html#method-i-each_line
15
- IO.popen(cmd) do |pipe|
38
+ IO.popen(env, cmd, mode, opts) do |pipe|
16
39
  pipe.each_line(&block)
17
40
  end
18
41
  end
@@ -30,16 +53,38 @@ module Libexec
30
53
  end
31
54
 
32
55
  def code(cmd, *opt, **args)
33
- catch_error = opt.nil? || args[:catch_error] || false
34
- code = opt[0] || args[:code]
56
+ catch_error = !opt.empty? || args[:catch_error] || false
57
+ code = opt[0] || args[:code] || 1
58
+
59
+ # https://docs.ruby-lang.org/en/master/Process.html#method-c-last_status
60
+ Process.spawn(cmd)
61
+ Process.wait
35
62
 
36
- # https://docs.ruby-lang.org/en/master/Kernel.html#method-i-system
37
- result = system cmd
38
- exit code if catch_error && !result
39
- result
63
+ result = $?.exitstatus.zero?
64
+
65
+ if catch_error && !result
66
+ exit code
67
+ else
68
+ $?.exitstatus
69
+ end
70
+ rescue Errno::ENOENT => _e
71
+ 127
40
72
  end
41
73
 
42
- def output(cmd)
74
+ def output(cmd, *argv)
75
+ unless argv.empty?
76
+ arr = [cmd]
77
+ argv.each do |arg|
78
+ if arg.instance_of?(Array)
79
+ arr.push("'#{arg.join(" ")}'")
80
+ elsif arg.instance_of?(String)
81
+ arr.push(arg)
82
+ end
83
+ end
84
+
85
+ cmd = arr.join(" ")
86
+ end
87
+
43
88
  # https://docs.ruby-lang.org/en/master/Kernel.html#method-i-60
44
89
  output = `#{cmd}`
45
90
  output.chomp
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Libexec
4
- VERSION = "0.1.1"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libexec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - initdc
@@ -52,7 +52,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  requirements: []
55
- rubygems_version: 3.3.26
55
+ rubygems_version: 3.2.3
56
56
  signing_key:
57
57
  specification_version: 4
58
58
  summary: Wrapper for ruby exec