libexec 0.1.4 → 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: 5b3371c07934d16c67be9241d732a44ad6ea40608994d895f300feeda75fdc34
4
- data.tar.gz: 4c93a42bfc53932c9df557d92cfb54bd75a0fd94b29116e8b1fcaa15192001f0
3
+ metadata.gz: a3d8b26a3b51d11a80ee0b158da31636268490b6b7141f9c0953934df47341f8
4
+ data.tar.gz: 31ee9aeae742be7e66c6f8c020957214a22af6edccf9d6131200b2c5b9a34182
5
5
  SHA512:
6
- metadata.gz: e560c83b63e6adf337d6736477ba34f78cd3af54e510e07fa20b6129e626eb68d51f1d5a9ac1adc053474878cd72fbe1d5163359ea7ab6a18060487ff09e99c4
7
- data.tar.gz: 60c7ea41c22f0e58d113fb791cd10026e0f4e043e6ad9973797efbabad17c3f8eff3b50d21ab14588c57d8927fa03d5069758efd46a60aa47612622b4fcc0f52
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.4)
4
+ libexec (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -55,4 +55,4 @@ DEPENDENCIES
55
55
  rubocop (~> 1.21)
56
56
 
57
57
  BUNDLED WITH
58
- 2.4.1
58
+ 2.3.26
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
@@ -29,9 +52,9 @@ module Libexec
29
52
  each_line("ls -1 #{dir}", &block)
30
53
  end
31
54
 
32
- def code(cmd, code = nil, **opts)
33
- catch_error = code.instance_of?(Integer) || opts[:catch_error] || false
34
- code ||= opts[:code] || 1
55
+ def code(cmd, *opt, **args)
56
+ catch_error = !opt.empty? || args[:catch_error] || false
57
+ code = opt[0] || args[:code] || 1
35
58
 
36
59
  # https://docs.ruby-lang.org/en/master/Process.html#method-c-last_status
37
60
  Process.spawn(cmd)
@@ -48,7 +71,20 @@ module Libexec
48
71
  127
49
72
  end
50
73
 
51
- 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
+
52
88
  # https://docs.ruby-lang.org/en/master/Kernel.html#method-i-60
53
89
  output = `#{cmd}`
54
90
  output.chomp
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Libexec
4
- VERSION = "0.1.4"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libexec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - initdc
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-27 00:00:00.000000000 Z
11
+ date: 2022-12-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Wrapper for ruby exec shell command.
14
14
  email: