rash-command-shell 0.2.2 → 0.3.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rash.rb +2 -2
  3. data/lib/rash/capturing.rb +42 -0
  4. metadata +2 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8d2870af889b41fda5f16c62f4f181c09ae843cc61ef4391596078c723c13269
4
- data.tar.gz: 0e4e282af5b0940e63478b62985238e427969f2d95e7fccb6e25afc7f18f7c3b
3
+ metadata.gz: f1656e8fb0ce00b1053a2fb71e551e4cec9108f31b41e6bff096a48f2a39a45a
4
+ data.tar.gz: fc0fc83b298541d1b8593a484660b9ba3e1f9470f226e0db2062316650557234
5
5
  SHA512:
6
- metadata.gz: ca2658254fe315de5c6902a301d1a5d7f210e68630f9ac0677d811af697a2b334e6f185882d4ac8e725e56ee3e8dad777f8b09e7a5db9159914fb2dbecf9a589
7
- data.tar.gz: 2820b7e820e1a28fdf87e898cc284b8c8a9be53193fd72047b61cc6036ba51eb2fa92e2b0dc687e73f258a8af7854a89320230bf349b71cc8d5d3e09ee46ca62
6
+ metadata.gz: 275fa36281ff54847e61457ee9f1c4dc8cf0284766d80826b1cce90ae01e0c23384c3ed5f532121566a709318546ebd62749944b3ecf52951cd43dcbdcca0231
7
+ data.tar.gz: 2b11e91d955014d576ab6a90ff3650458631592f86f5a3d2508d5800d174470365e79959e11f721f516b693957bb72ae2c12eb4c66270464cf9eb45d2d70b546
@@ -105,6 +105,7 @@ require_relative "rash/redirection"
105
105
  require_relative "rash/aliasing"
106
106
  require_relative "rash/jobcontrol"
107
107
  require_relative "rash/pipeline"
108
+ require_relative "rash/capturing"
108
109
 
109
110
  $env = Environment.new
110
111
 
@@ -128,7 +129,6 @@ def run(file, *args)
128
129
  raise SystemCallError.new("No such executable file - #{exe}", Errno::ENOENT::Errno)
129
130
  end
130
131
  $env.dispatch(exe, *args, literal: true)
131
- # system(exe, *args.flatten.map{|a| a.to_s}, {out: $stdout, err: $stderr, in: $stdin, umask: $env.umask})
132
132
  end
133
133
 
134
134
  alias cmd __send__
@@ -151,7 +151,7 @@ end
151
151
 
152
152
 
153
153
  def which(command)
154
- cmd = File.expand_path(command)
154
+ cmd = File.expand_path(command.to_s)
155
155
  return cmd if File.executable?(cmd) && !File.directory?(cmd)
156
156
 
157
157
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
@@ -0,0 +1,42 @@
1
+ class Environment
2
+ def capture_block(&block)
3
+ raise ArgumentError.new("no block provided") unless block_given?
4
+ result = nil
5
+ begin
6
+ reader, writer = IO.pipe
7
+ self.stdout = writer
8
+ block.call
9
+ ensure
10
+ reset_stdout
11
+ writer.close
12
+ result = reader.read
13
+ reader.close
14
+ end
15
+ result
16
+ end
17
+
18
+ def capture_command(m, *args)
19
+ raise NameError.new("no such command", m) unless which(m) || ($env.alias?(m) && !$env.aliasing_disabled)
20
+ result = nil
21
+ begin
22
+ reader, writer = IO.pipe
23
+ system_command(m, *args, out: writer)
24
+ ensure
25
+ writer.close
26
+ result = reader.read
27
+ reader.close
28
+ end
29
+ result
30
+ end
31
+ end
32
+
33
+ # This explicitly doesn't support pipelining, as the output is ripped out of sequence.
34
+ def capture(*cmd, &block)
35
+ if block_given?
36
+ $env.capture_block(&block)
37
+ elsif cmd.size > 0 && (which(cmd[0]) || ($env.alias?(m) && !$env.aliasing_disabled))
38
+ $env.capture_command(cmd[0].to_s, *cmd[1..])
39
+ else
40
+ raise ArgumentError.new("nothing to capture from")
41
+ end
42
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rash-command-shell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kellen Watt
@@ -34,6 +34,7 @@ files:
34
34
  - bin/rash
35
35
  - lib/rash.rb
36
36
  - lib/rash/aliasing.rb
37
+ - lib/rash/capturing.rb
37
38
  - lib/rash/ext/filesystem.rb
38
39
  - lib/rash/jobcontrol.rb
39
40
  - lib/rash/pipeline.rb