tsalzer-syscmd 0.0.1 → 0.0.3

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.
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 0
3
3
  :minor: 0
4
- :patch: 1
4
+ :patch: 3
data/lib/syscmd.rb CHANGED
@@ -51,6 +51,26 @@ module Syscmd
51
51
  self
52
52
  end
53
53
 
54
+ # get the stdout as lines.
55
+ def stdout_lines
56
+ if @stdout_lines.nil?
57
+ stdout = self.stdout
58
+ return nil unless stdout
59
+ @stdout_lines = stdout.split(/\n/)
60
+ end
61
+ @stdout_lines
62
+ end
63
+
64
+ # get the stdout as lines.
65
+ def stderr_lines
66
+ if @stderr_lines.nil?
67
+ stderr = self.stderr
68
+ return nil unless stderr
69
+ @stderr_lines = stderr.split(/\n/)
70
+ end
71
+ @stderr_lines
72
+ end
73
+
54
74
  # the exitcode of the executed command.
55
75
  # returns nil
56
76
  def exitcode
@@ -1,18 +1,42 @@
1
1
  require File.join(File.dirname(__FILE__), 'spec_helper')
2
2
 
3
3
  describe Syscmd::Command, ".exec! for -s 'Hello World'" do
4
- subject { Syscmd::Command.new(TESTER, '-s', 'Hello World') }
4
+ subject { Syscmd::Command.new(TESTER, '-s', 'Hello World').exec! }
5
5
 
6
- it "should have stdout 'Hello World'" do
7
- subject.exec!.stdout.should == 'Hello World'
6
+ it "should have stdout 'Hello World\\n'" do
7
+ subject.stdout.should == "Hello World\n"
8
8
  end
9
+ it "should have stdout_lines ['Hello World']" do
10
+ subject.stdout_lines.should == ["Hello World"]
11
+ end
12
+
9
13
 
10
14
  it "should have stderr \"\"" do
11
- subject.exec!.stderr.should == ""
15
+ subject.stderr.should == ""
12
16
  end
13
17
 
14
18
  it "should have exitcode 0" do
15
- subject.exec!.exitcode.should == 0
19
+ subject.exitcode.should == 0
20
+ end
21
+ end
22
+
23
+ describe Syscmd::Command, ".exec! for multiline output" do
24
+ subject { Syscmd::Command.new(TESTER,
25
+ '-s', 'Hello World', '-S', 2,
26
+ '-e', 'Bye Bye World', '-E', 2).exec! }
27
+
28
+ it "should have stdout 'Hello World\\nHello World\\n'" do
29
+ subject.stdout.should == "Hello World\nHello World\n"
30
+ end
31
+ it "should have two strings in stdout_lines" do
32
+ subject.stdout_lines.should == ["Hello World", "Hello World"]
33
+ end
34
+
35
+ it "should have stderr 'Bye Bye World\\nBye Bye World\\n'" do
36
+ subject.stderr.should == "Bye Bye World\nBye Bye World\n"
37
+ end
38
+ it "should have two strings in stdout_lines" do
39
+ subject.stderr_lines.should == ["Bye Bye World", "Bye Bye World"]
16
40
  end
17
41
  end
18
42
 
data/spec/tester.rb CHANGED
@@ -7,45 +7,51 @@
7
7
  #
8
8
  # tester [OPTION]
9
9
  #
10
- # COMMANDS:
11
- # list:
12
- # list all available project. No option required.
13
- # show:
14
- # show a project. You must provide a PROJECTNAME and a SCOPE. Valid SCOPEs
15
- # are: [env]ironment, [ver]sion
16
- # deploy:
17
- # deploys a given build to an environment. You must provide PROJECTNAME,
18
- # BUILD and ENVRIONMENT.
19
- #
20
10
  # OPTIONS:
21
- # --help, -h
22
- # --stdout, -s
23
- # --stderr, -e
24
- # --exitcode, -x
11
+ # --help, -h display this page
12
+ # --stdout, -s MSG echo MSG to stdout
13
+ # --stdoutrepeat, -S COUNT print the stdout message COUNT times
14
+ # (DEFAULT: 1)
15
+ # --stderr, -e MSG echo MSG to stderr
16
+ # --stderrrepeat, -E COUNT print the stderr message COUNT times
17
+ # (DEFAULT: 1)
18
+ # --exitcode, -x CODE return exit code CODE
25
19
  # --debug
26
20
 
27
21
  require "getoptlong"
28
22
  require "rdoc/usage"
29
23
 
30
24
  opts = GetoptLong.new(
31
- [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
32
- [ '--stdout', '-s', GetoptLong::REQUIRED_ARGUMENT ],
33
- [ '--stderr', '-e', GetoptLong::REQUIRED_ARGUMENT ],
34
- [ '--exitcode', '-x', GetoptLong::REQUIRED_ARGUMENT ],
35
- [ '--debug', GetoptLong::OPTIONAL_ARGUMENT ]
25
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
26
+ [ '--stdout', '-s', GetoptLong::REQUIRED_ARGUMENT ],
27
+ [ '--stdoutcount', '-S', GetoptLong::REQUIRED_ARGUMENT ],
28
+ [ '--stderr', '-e', GetoptLong::REQUIRED_ARGUMENT ],
29
+ [ '--stderrcount', '-E', GetoptLong::REQUIRED_ARGUMENT ],
30
+ [ '--exitcode', '-x', GetoptLong::REQUIRED_ARGUMENT ],
31
+ [ '--debug', GetoptLong::OPTIONAL_ARGUMENT ]
36
32
  )
37
33
 
38
34
  options = {}
39
35
  exitcode = 0
40
36
 
37
+ msg_stdout = nil
38
+ count_stdout = 1
39
+
40
+ msg_stderr = nil
41
+ count_stderr = 1
42
+
41
43
  opts.each do |opt, arg|
42
44
  case opt
43
45
  when '--help'
44
46
  RDoc::usage
45
47
  when '--stdout'
46
- $stdout.print arg
48
+ msg_stdout = arg
49
+ when '--stdoutcount'
50
+ count_stdout = arg.to_i
47
51
  when '--stderr'
48
- $stderr.print arg
52
+ msg_stderr = arg
53
+ when '--stderrcount'
54
+ count_stderr = arg.to_i
49
55
  when '--exitcode'
50
56
  exitcode = arg.to_i
51
57
  when '--debug'
@@ -53,4 +59,16 @@ opts.each do |opt, arg|
53
59
  end
54
60
  end
55
61
 
62
+ if msg_stdout
63
+ count_stdout.times do
64
+ $stdout.print "#{msg_stdout}\n"
65
+ end
66
+ end
67
+
68
+ if msg_stderr
69
+ count_stderr.times do
70
+ $stderr.print "#{msg_stderr}\n"
71
+ end
72
+ end
73
+
56
74
  exit exitcode
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tsalzer-syscmd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Till Salzer
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-13 00:00:00 -07:00
12
+ date: 2009-04-18 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15