run-command 0.1 → 0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -0
- data/Gemfile.lock +27 -0
- data/Rakefile +8 -2
- data/lib/run-command.rb +11 -24
- data/run-command.gemspec +6 -6
- data/test/test.rb +38 -0
- metadata +43 -12
- data/lib/run-command/version.rb +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a97d559632d69814b3d64b79c0dab60d63bab697dcd39c74c53e546d7c0a2570
|
4
|
+
data.tar.gz: a62840eddfbc10e49930576852813d72724b45371738e1f56ea07b785d634bff
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44649150f3cd9f2f7ba7a3e1d6ec4d6ac198ab3601ebca29c070107c209a171949464ea52f50107ae93e22cbc70954e6c67d2b274cb63244d9e29f05a104083e
|
7
|
+
data.tar.gz: 8b2f7156eff5e19ba84ce7a85edce15edc82735c4bcee71e2f2eb1f7b1f3704adeaf8d61af1ffae9b1fe941e959ed35cf16f932feaf3deeda30a035d7fed4d4d
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
run-command (0.4)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.14.4)
|
10
|
+
minitest-power_assert (0.3.1)
|
11
|
+
minitest
|
12
|
+
power_assert (>= 1.1)
|
13
|
+
power_assert (2.0.0)
|
14
|
+
rake (13.0.3)
|
15
|
+
|
16
|
+
PLATFORMS
|
17
|
+
arm64-darwin-20
|
18
|
+
|
19
|
+
DEPENDENCIES
|
20
|
+
bundler (~> 2.2)
|
21
|
+
minitest (~> 5.14)
|
22
|
+
minitest-power_assert (~> 0.3)
|
23
|
+
rake (~> 13.0)
|
24
|
+
run-command!
|
25
|
+
|
26
|
+
BUNDLED WITH
|
27
|
+
2.2.20
|
data/Rakefile
CHANGED
data/lib/run-command.rb
CHANGED
@@ -1,22 +1,17 @@
|
|
1
1
|
require 'shellwords'
|
2
2
|
|
3
|
-
|
3
|
+
module Kernel
|
4
4
|
|
5
|
-
class
|
5
|
+
class RunCommandFailed < Exception; end
|
6
6
|
|
7
|
-
def
|
8
|
-
|
9
|
-
end
|
10
|
-
|
11
|
-
def run_command(command, *args)
|
12
|
-
command = command.to_s
|
13
|
-
options = args.last.kind_of?(Hash) ? args.pop.dup : {}
|
14
|
-
options[:exception] = true
|
7
|
+
def run_command(*args, **options)
|
8
|
+
command = args.shift
|
15
9
|
args = args.flatten.compact.map(&:to_s)
|
16
10
|
env = options.delete(:env) || {}
|
17
11
|
verbose = options.delete(:verbose) || false
|
18
12
|
pretend = options.delete(:pretend) || false
|
19
13
|
argv0 = options.delete(:argv0)
|
14
|
+
input = options.delete(:input)
|
20
15
|
if verbose
|
21
16
|
warn "$ %s%s" % [
|
22
17
|
env.empty? ? nil : env.map { |kv| kv.join('=') }.join(' ') + ' ',
|
@@ -24,22 +19,14 @@ class RunCommand
|
|
24
19
|
]
|
25
20
|
end
|
26
21
|
unless pretend
|
27
|
-
|
28
|
-
|
29
|
-
|
22
|
+
output = IO.popen(env, [argv0 ? [command, argv0] : command, *args], 'r+', options) do |io|
|
23
|
+
io.write(input.to_s) if input
|
24
|
+
io.close_write
|
25
|
+
io.read
|
30
26
|
end
|
31
|
-
|
27
|
+
raise RunCommandFailed, "Command #{command.to_s.inspect} failed: #{$?}" if $? != 0
|
28
|
+
output
|
32
29
|
end
|
33
30
|
end
|
34
31
|
|
35
|
-
end
|
36
|
-
|
37
|
-
if $0 == __FILE__
|
38
|
-
|
39
|
-
RunCommand.run_command('echo', %w{a b}, verbose: true)
|
40
|
-
RunCommand.run_command('echo', %w{a b}, verbose: true, env: { 'FOO' => 'bar' })
|
41
|
-
RunCommand.run_command('echo', %w{a b}, verbose: true, env: { 'FOO' => 'bar' }, argv0: 'DATE')
|
42
|
-
RunCommand.run_command('echo', %w{a b}, verbose: true, pretend: true)
|
43
|
-
RunCommand.run_command('echo', ['a', 'b', [1, :foo]], verbose: true)
|
44
|
-
|
45
32
|
end
|
data/run-command.gemspec
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require_relative 'lib/run-command/version'
|
2
|
-
|
3
1
|
Gem::Specification.new do |s|
|
4
2
|
s.name = 'run-command'
|
5
|
-
s.version =
|
3
|
+
s.version = '0.4'
|
6
4
|
s.summary = 'A friendlier system().'
|
7
5
|
s.author = 'John Labovitz'
|
8
6
|
s.email = 'johnl@johnlabovitz.com'
|
9
7
|
s.description = %q{
|
10
|
-
|
8
|
+
A friendlier system().
|
11
9
|
}
|
12
10
|
s.license = 'MIT'
|
13
11
|
s.homepage = 'http://github.com/jslabovitz/run-command'
|
@@ -16,6 +14,8 @@ Gem::Specification.new do |s|
|
|
16
14
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
15
|
s.require_path = 'lib'
|
18
16
|
|
19
|
-
s.add_development_dependency '
|
20
|
-
s.add_development_dependency '
|
17
|
+
s.add_development_dependency 'bundler', '~> 2.2'
|
18
|
+
s.add_development_dependency 'minitest', '~> 5.14'
|
19
|
+
s.add_development_dependency 'minitest-power_assert', '~> 0.3'
|
20
|
+
s.add_development_dependency 'rake', '~> 13.0'
|
21
21
|
end
|
data/test/test.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'minitest/power_assert'
|
3
|
+
|
4
|
+
require 'run-command'
|
5
|
+
|
6
|
+
class Test < MiniTest::Test
|
7
|
+
|
8
|
+
def test_simple
|
9
|
+
assert_output {
|
10
|
+
run_command('echo', %w{a b}, verbose: true)
|
11
|
+
}
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_env
|
15
|
+
assert_output {
|
16
|
+
run_command('echo', %w{a b}, verbose: true, env: { 'FOO' => 'bar' })
|
17
|
+
}
|
18
|
+
end
|
19
|
+
|
20
|
+
def test_env_argv0
|
21
|
+
assert_output {
|
22
|
+
run_command('echo', %w{a b}, verbose: true, env: { 'FOO' => 'bar' }, argv0: 'DATE')
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_pretend
|
27
|
+
assert_output {
|
28
|
+
run_command('echo', %w{a b}, verbose: true, pretend: true)
|
29
|
+
}
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_varied_args
|
33
|
+
assert_output {
|
34
|
+
run_command('echo', ['a', 'b', [1, :foo]], verbose: true)
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,85 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: run-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.4'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Labovitz
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
16
30
|
requirements:
|
17
31
|
- - "~>"
|
18
32
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
33
|
+
version: '5.14'
|
20
34
|
type: :development
|
21
35
|
prerelease: false
|
22
36
|
version_requirements: !ruby/object:Gem::Requirement
|
23
37
|
requirements:
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
40
|
+
version: '5.14'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
42
|
+
name: minitest-power_assert
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
29
57
|
requirement: !ruby/object:Gem::Requirement
|
30
58
|
requirements:
|
31
59
|
- - "~>"
|
32
60
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0
|
61
|
+
version: '13.0'
|
34
62
|
type: :development
|
35
63
|
prerelease: false
|
36
64
|
version_requirements: !ruby/object:Gem::Requirement
|
37
65
|
requirements:
|
38
66
|
- - "~>"
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0
|
41
|
-
description: "\n
|
68
|
+
version: '13.0'
|
69
|
+
description: "\n A friendlier system().\n "
|
42
70
|
email: johnl@johnlabovitz.com
|
43
71
|
executables: []
|
44
72
|
extensions: []
|
45
73
|
extra_rdoc_files: []
|
46
74
|
files:
|
47
75
|
- ".gitignore"
|
76
|
+
- Gemfile
|
77
|
+
- Gemfile.lock
|
48
78
|
- README.md
|
49
79
|
- Rakefile
|
50
80
|
- lib/run-command.rb
|
51
|
-
- lib/run-command/version.rb
|
52
81
|
- run-command.gemspec
|
82
|
+
- test/test.rb
|
53
83
|
homepage: http://github.com/jslabovitz/run-command
|
54
84
|
licenses:
|
55
85
|
- MIT
|
@@ -69,8 +99,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
69
99
|
- !ruby/object:Gem::Version
|
70
100
|
version: '0'
|
71
101
|
requirements: []
|
72
|
-
rubygems_version: 3.2.
|
102
|
+
rubygems_version: 3.2.20
|
73
103
|
signing_key:
|
74
104
|
specification_version: 4
|
75
105
|
summary: A friendlier system().
|
76
|
-
test_files:
|
106
|
+
test_files:
|
107
|
+
- test/test.rb
|