scmd 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -51,7 +51,28 @@ cmd.stderr #=> ''
51
51
  cmd.run.stdout #=> 'hi'
52
52
  ```
53
53
 
54
- Some helpers:
54
+ ### Run with input on stdin
55
+
56
+ A single input line
57
+
58
+ ```ruby
59
+ input = "echo hi"
60
+ cmd = Scmd.new("sh").run(input)
61
+ cmd.stdout #=> 'hi'
62
+ ```
63
+
64
+ Multiple input lines:
65
+
66
+ ```ruby
67
+ input = ["echo hi", "echo err 1>&2"]
68
+ cmd = Scmd.new("sh").run(input)
69
+ cmd.stdout #=> 'hi'
70
+ cmd.stderr #=> 'err'
71
+ ```
72
+
73
+ ### Some helpers
74
+
75
+ Ask if cmd was successful:
55
76
 
56
77
  ```ruby
57
78
  puts cmd.stderr if !cmd.success?
data/lib/scmd/command.rb CHANGED
@@ -32,14 +32,18 @@ module Scmd
32
32
  "#<#{self.class}:0x#{self.object_id.to_s(16)} @cmd_str=#{self.cmd_str.inspect} @exitcode=#{@exitcode.inspect}>"
33
33
  end
34
34
 
35
- def run
36
- run! rescue Failure
35
+ def run(input=nil)
36
+ run!(input) rescue Failure
37
37
  self
38
38
  end
39
39
 
40
- def run!
40
+ def run!(input=nil)
41
41
  begin
42
42
  status = Open4::popen4(@cmd_str) do |pid, stdin, stdout, stderr|
43
+ if !input.nil?
44
+ [*input].each{|line| stdin.puts line.to_s}
45
+ stdin.close
46
+ end
43
47
  @pid = pid.to_i
44
48
  @stdout += stdout.read.strip
45
49
  @stderr += stderr.read.strip
data/lib/scmd/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Scmd
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
data/scmd.gemspec CHANGED
@@ -7,9 +7,9 @@ Gem::Specification.new do |gem|
7
7
  gem.description = %q{Wrapper to `open4` for running system commands.}
8
8
  gem.summary = %q{Wrapper to `open4` for running system commands.}
9
9
 
10
- gem.authors = ["Kelly Redding and Team Insight"]
11
- gem.email = ["appdev@reelfx.com"]
12
- gem.homepage = "http://github.com/teaminsight/scmd"
10
+ gem.authors = ["Kelly Redding"]
11
+ gem.email = ["kelly@kellyredding.com"]
12
+ gem.homepage = "http://github.com/redding/scmd"
13
13
 
14
14
  gem.files = `git ls-files`.split("\n")
15
15
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
@@ -1,57 +1,85 @@
1
1
  require "assert"
2
2
  require 'scmd/command'
3
3
 
4
- class CommandTests < Assert::Context
5
- desc "a command"
6
- setup do
7
- @success_cmd = Scmd::Command.new("echo hi")
8
- @failure_cmd = Scmd::Command.new("cd /path/that/does/not/exist")
9
- end
10
- subject { @success_cmd }
4
+ module Scmd
11
5
 
12
- should have_readers :cmd_str, :pid, :exitcode, :stdout, :stderr
13
- should have_instance_methods :run, :run!
6
+ class CommandTests < Assert::Context
7
+ desc "a command"
8
+ setup do
9
+ @success_cmd = Command.new("echo hi")
10
+ @failure_cmd = Command.new("cd /path/that/does/not/exist")
11
+ end
12
+ subject { @success_cmd }
14
13
 
15
- should "know and return its cmd string" do
16
- assert_equal "echo hi", subject.cmd_str
17
- assert_equal "echo hi", subject.to_s
18
- end
14
+ should have_readers :cmd_str, :pid, :exitcode, :stdout, :stderr
15
+ should have_instance_methods :run, :run!
19
16
 
20
- should "default its result values" do
21
- assert_nil subject.pid
22
- assert_nil subject.exitcode
23
- assert_equal '', subject.stdout
24
- assert_equal '', subject.stderr
25
- end
17
+ should "know and return its cmd string" do
18
+ assert_equal "echo hi", subject.cmd_str
19
+ assert_equal "echo hi", subject.to_s
20
+ end
26
21
 
27
- should "run the command and set appropriate result data" do
28
- @success_cmd.run
22
+ should "default its result values" do
23
+ assert_nil subject.pid
24
+ assert_nil subject.exitcode
25
+ assert_equal '', subject.stdout
26
+ assert_equal '', subject.stderr
27
+ end
29
28
 
30
- assert_not_nil @success_cmd.pid
31
- assert_equal 0, @success_cmd.exitcode
32
- assert @success_cmd.success?
33
- assert_equal 'hi', @success_cmd.stdout
34
- assert_equal '', @success_cmd.stderr
29
+ should "run the command and set appropriate result data" do
30
+ @success_cmd.run
35
31
 
36
- @failure_cmd.run
32
+ assert_not_nil @success_cmd.pid
33
+ assert_equal 0, @success_cmd.exitcode
34
+ assert @success_cmd.success?
35
+ assert_equal 'hi', @success_cmd.stdout
36
+ assert_equal '', @success_cmd.stderr
37
37
 
38
- assert_not_nil @failure_cmd.pid
39
- assert_not_equal 0, @failure_cmd.exitcode
40
- assert_not @failure_cmd.success?
41
- assert_equal '', @failure_cmd.stdout
42
- assert_not_equal '', @failure_cmd.stderr
43
- end
38
+ @failure_cmd.run
39
+
40
+ assert_not_nil @failure_cmd.pid
41
+ assert_not_equal 0, @failure_cmd.exitcode
42
+ assert_not @failure_cmd.success?
43
+ assert_equal '', @failure_cmd.stdout
44
+ assert_not_equal '', @failure_cmd.stderr
45
+ end
46
+
47
+ should "raise an exception on `run!` and a non-zero exitcode" do
48
+ assert_raises Scmd::Command::Failure do
49
+ @failure_cmd.run!
50
+ end
51
+ end
44
52
 
45
- should "raise an exception on `run!` and a non-zero exitcode" do
46
- assert_raises Scmd::Command::Failure do
47
- @failure_cmd.run!
53
+ should "return itself on `run`, `run!`" do
54
+ assert_equal @success_cmd, @success_cmd.run
55
+ assert_equal @success_cmd, @success_cmd.run!
56
+ assert_equal @failure_cmd, @failure_cmd.run
48
57
  end
58
+
49
59
  end
50
60
 
51
- should "return itself on `run`, `run!`" do
52
- assert_equal @success_cmd, @success_cmd.run
53
- assert_equal @success_cmd, @success_cmd.run!
54
- assert_equal @failure_cmd, @failure_cmd.run
61
+ class InputTests < CommandTests
62
+ desc "that takes input on stdin"
63
+ setup do
64
+ @cmd = Command.new("sh")
65
+ end
66
+ subject { @cmd }
67
+
68
+ should "run the command given a single line of input" do
69
+ subject.run "echo hi"
70
+
71
+ assert @cmd.success?
72
+ assert_equal 'hi', @cmd.stdout
73
+ end
74
+
75
+ should "run the command given multiple lines of input" do
76
+ subject.run ["echo hi", "echo err 1>&2"]
77
+
78
+ assert @cmd.success?
79
+ assert_equal 'hi', @cmd.stdout
80
+ assert_equal 'err', @cmd.stderr
81
+ end
82
+
55
83
  end
56
84
 
57
85
  end
metadata CHANGED
@@ -1,25 +1,25 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scmd
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
- - Kelly Redding and Team Insight
13
+ - Kelly Redding
14
14
  autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-08-21 00:00:00 Z
18
+ date: 2012-10-16 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
- type: :development
22
- requirement: &id001 !ruby/object:Gem::Requirement
21
+ name: assert
22
+ version_requirements: &id001 !ruby/object:Gem::Requirement
23
23
  none: false
24
24
  requirements:
25
25
  - - ">="
@@ -28,12 +28,12 @@ dependencies:
28
28
  segments:
29
29
  - 0
30
30
  version: "0"
31
- name: assert
32
- version_requirements: *id001
31
+ type: :development
32
+ requirement: *id001
33
33
  prerelease: false
34
34
  - !ruby/object:Gem::Dependency
35
- type: :runtime
36
- requirement: &id002 !ruby/object:Gem::Requirement
35
+ name: open4
36
+ version_requirements: &id002 !ruby/object:Gem::Requirement
37
37
  none: false
38
38
  requirements:
39
39
  - - ">="
@@ -42,12 +42,12 @@ dependencies:
42
42
  segments:
43
43
  - 0
44
44
  version: "0"
45
- name: open4
46
- version_requirements: *id002
45
+ type: :runtime
46
+ requirement: *id002
47
47
  prerelease: false
48
48
  description: Wrapper to `open4` for running system commands.
49
49
  email:
50
- - appdev@reelfx.com
50
+ - kelly@kellyredding.com
51
51
  executables: []
52
52
 
53
53
  extensions: []
@@ -68,7 +68,7 @@ files:
68
68
  - test/helper.rb
69
69
  - test/irb.rb
70
70
  - test/scmd_tests.rb
71
- homepage: http://github.com/teaminsight/scmd
71
+ homepage: http://github.com/redding/scmd
72
72
  licenses: []
73
73
 
74
74
  post_install_message:
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  requirements: []
98
98
 
99
99
  rubyforge_project:
100
- rubygems_version: 1.8.11
100
+ rubygems_version: 1.8.24
101
101
  signing_key:
102
102
  specification_version: 3
103
103
  summary: Wrapper to `open4` for running system commands.