run-command 0.1 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a98764c775cf0417c45f4d2b652263d792aefc30624759f7cccef5d114d43490
4
- data.tar.gz: 07ea9656757fb971759ce719df8229820956ca691030353e1bd8ff031cb9347d
3
+ metadata.gz: 6dad44af580195093d4a940c048dbb93cbbe784af6b1c40a595f75b4ba17df0d
4
+ data.tar.gz: 566b5c0e81b051d4aafcdff6c9fd5aacdcd3f84a99030933b7e3c52b060d1a6a
5
5
  SHA512:
6
- metadata.gz: 959caa28c1446bae0a6b909f93a3dedeb481c11de97c43329f9f9eb2dd93740fa3ac3f8faf5e7e9a9ff91aa13dcc0dd493ee475d3f007690a261ad864d8d0f5c
7
- data.tar.gz: 47633e6c3484daf8ebdb0318bc1367c9dce62ee1a0f694603c2e9d0366c424a6176469d36cfb16900f2e63153c1871e932aad9267e88e80760cf34a091511d88
6
+ metadata.gz: bf54aae85631a713aaeb98eb20d6497c75cd152d8193445018b2574bbd8be9b50a81c255c5eef702d0f1638aae06f108c0c1923303b0e216ff3fdb9ac9bdae2e
7
+ data.tar.gz: bd6ac5a02af2a1d71541f1d37ee49f549cd94bcfe0bc78263c83e5ec663ddc55b3dd60f713d163ed4fb941f665557f0b9f862a50ef0ec9491c0f41bf6f210a60
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  .DS_Store
2
- *.gem
2
+ *.gem
3
+ Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Rakefile CHANGED
@@ -1,3 +1,9 @@
1
- require 'rubygems/tasks'
1
+ require 'bundler/gem_tasks'
2
+ Bundler.require
3
+ require 'rake/testtask'
2
4
 
3
- Gem::Tasks.new
5
+ Rake::TestTask.new do |t|
6
+ t.test_files = FileList['test/test.rb']
7
+ end
8
+
9
+ task :default => :test
data/lib/run-command.rb CHANGED
@@ -1,22 +1,18 @@
1
1
  require 'shellwords'
2
2
 
3
- class RunCommand
3
+ module Kernel
4
4
 
5
- class Error < Exception; end
5
+ class RunCommandFailed < Exception; end
6
6
 
7
- def self.run_command(command, *args)
8
- new.run_command(command, *args)
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)
15
8
  args = args.flatten.compact.map(&:to_s)
9
+ command = args.shift
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)
15
+ interactive = options.delete(:interactive)
20
16
  if verbose
21
17
  warn "$ %s%s" % [
22
18
  env.empty? ? nil : env.map { |kv| kv.join('=') }.join(' ') + ' ',
@@ -24,22 +20,19 @@ class RunCommand
24
20
  ]
25
21
  end
26
22
  unless pretend
27
- data = ''
28
- IO.popen(env, [argv0 ? [command, argv0] : command, *args], 'r', options) do |io|
29
- data += io.read
23
+ if interactive
24
+ system(env, *command)
25
+ output = nil
26
+ else
27
+ output = IO.popen(env, [argv0 ? [command, argv0] : command, *args], 'r+', options) do |io|
28
+ io.write(input.to_s) if input
29
+ io.close_write
30
+ io.read
31
+ end
30
32
  end
31
- data
33
+ raise RunCommandFailed, "Command #{command.to_s.inspect} failed: #{$?}" if $? != 0
34
+ output
32
35
  end
33
36
  end
34
37
 
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
38
  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 = RunCommand::VERSION
3
+ s.version = '0.6'
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
- RunCommand provides a friendlier system().
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 'rake', '~> 12.3'
20
- s.add_development_dependency 'rubygems-tasks', '~> 0.2'
17
+ s.add_development_dependency 'bundler', '~> 2.3'
18
+ s.add_development_dependency 'minitest', '~> 5.16'
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,84 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run-command
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.6'
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Labovitz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-31 00:00:00.000000000 Z
11
+ date: 2022-09-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rake
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.3'
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: '12.3'
33
+ version: '5.16'
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: '12.3'
40
+ version: '5.16'
27
41
  - !ruby/object:Gem::Dependency
28
- name: rubygems-tasks
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.2'
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.2'
41
- description: "\n RunCommand provides a friendlier system().\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
48
77
  - README.md
49
78
  - Rakefile
50
79
  - lib/run-command.rb
51
- - lib/run-command/version.rb
52
80
  - run-command.gemspec
81
+ - test/test.rb
53
82
  homepage: http://github.com/jslabovitz/run-command
54
83
  licenses:
55
84
  - MIT
@@ -69,8 +98,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
98
  - !ruby/object:Gem::Version
70
99
  version: '0'
71
100
  requirements: []
72
- rubygems_version: 3.2.3
101
+ rubygems_version: 3.3.22
73
102
  signing_key:
74
103
  specification_version: 4
75
104
  summary: A friendlier system().
76
- test_files: []
105
+ test_files:
106
+ - test/test.rb
@@ -1,5 +0,0 @@
1
- class RunCommand
2
-
3
- VERSION = '0.1'
4
-
5
- end