bio-commandeer 0.0.1 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b9c771b0c81dc1e3b7d403e6e1a8710786992287
4
- data.tar.gz: cb1e3b28ff63aa29bcc50fc8a5180ea3f968ac12
3
+ metadata.gz: 4dafee4b620f94ea378960ad13088211729ca259
4
+ data.tar.gz: a8452c98ec7a4714dbe27fa67e05fdd1786257c9
5
5
  SHA512:
6
- metadata.gz: 2487a87d69c8546f09992a44055fe486b157c88a0a785fbf809301eb41a4e90714360b344747feb83ebc5eb790881fc8f532dde5c95fac668c3cb83c3095b23e
7
- data.tar.gz: 5fd71b17b3e0f474fd5c1ce86507ff90fa706a4fc571d50fe912e52f72de7d582837d0a1ce9ec005256d8b81479e2f6ec204a5c9136c18c82e85493bb4ca8cd7
6
+ metadata.gz: c980f3c8c40054a6a0fcaff69365cbd2490c9e8dd22feabc82d7c816d7301d6d406d2a9fa3606dcd65f6f8f69886f57a40482164b5b52b53a043c594d21af848
7
+ data.tar.gz: 5d98992130120ff74358594b4bb608766af3af808a06c309de5c4db3332571ed55d645e04b195e150eaa494cc6d471d9b1d2a32086f7537670803a87e4eda627
data/README.md CHANGED
@@ -28,6 +28,24 @@ Of course, when running commands such as this, take care not to trust the input
28
28
 
29
29
  Note: this software is under active development! Currently it is perhaps overly opinionated and as such not overly flexible.
30
30
 
31
+ ## Logging
32
+ Commands run are logged with level info, if requested:
33
+ ```ruby
34
+ require 'bio-commandeer'
35
+ Bio::Log::CLI.logger("stderr"); Bio::Log::CLI.trace("info");
36
+ puts Bio::Commandeer.run 'echo 5', :log=>true
37
+ ```
38
+ On stderr this gives
39
+ ```
40
+ INFO bio-commandeer: Running command: echo 5\n"+
41
+ INFO bio-commandeer: Command finished with exitstatus 0"
42
+ ```
43
+ Or a logging can be given directly, so long as it has an `info` method:
44
+ ```ruby
45
+ Bio::Commandeer.run 'echo 5', :log=>my_logger
46
+ ```
47
+
48
+
31
49
  ## Installation
32
50
 
33
51
  ```sh
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.1
1
+ 0.1.0
@@ -1,14 +1,4 @@
1
1
 
2
-
3
2
  require 'bio-logger'
4
- Bio::Log::LoggerPlus.new('bio-commandeer')
5
- module Bio
6
- module CommandeerLogging
7
- def log
8
- Bio::Log::LoggerPlus['bio-commandeer']
9
- end
10
- end
11
- end
12
-
13
3
 
14
4
  require 'bio-commandeer/commandeer.rb'
@@ -3,21 +3,24 @@ require 'systemu'
3
3
  module Bio
4
4
  # See #run
5
5
  class Commandeer
6
- include Bio::CommandeerLogging
7
6
 
8
7
  # Run a command line program, and be opinionated about how to handle failure
9
8
  #
10
9
  # command is a string of the command to be run
11
10
  # * options is a hash, with keys:
12
11
  # :stdin: a string that is the stdin
13
- # :log: turn on logging
12
+ # :log: if true, turn on logging. If given an object use it as the logger
14
13
  def self.run(command, options={})
15
14
  if options[:log]
16
- log_name = 'bio-commandeer'
17
- @log = Bio::Log::LoggerPlus[log_name]
18
- if @log.nil? or @log.outputters.empty?
19
- @log = Bio::Log::LoggerPlus.new(log_name)
20
- Bio::Log::CLI.configure(log_name)
15
+ if options[:log] == true
16
+ log_name = 'bio-commandeer'
17
+ @log = Bio::Log::LoggerPlus[log_name]
18
+ if @log.nil? or @log.outputters.empty?
19
+ @log = Bio::Log::LoggerPlus.new(log_name)
20
+ Bio::Log::CLI.configure(log_name)
21
+ end
22
+ else
23
+ @log = options[:log]
21
24
  end
22
25
 
23
26
  @log.info "Running command: #{command}"
@@ -1,4 +1,5 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+ require 'tempfile'
2
3
 
3
4
  describe "BioCommandeer" do
4
5
  it "should return stdout" do
@@ -8,4 +9,46 @@ describe "BioCommandeer" do
8
9
  it 'should raise when exit status the command fails' do
9
10
  expect {Bio::Commandeer.run("cat /definitelyNotAFile")}.to raise_error
10
11
  end
12
+
13
+ it 'should accept stdin' do
14
+ Bio::Commandeer.run('cat', :stdin => 'dog').should == "dog"
15
+ end
16
+
17
+ it 'should do logging with bio-logger' do
18
+ Tempfile.open('script') do |f|
19
+ f.puts [
20
+ "require 'bio-commandeer'",
21
+ 'Bio::Log::CLI.logger("stderr"); Bio::Log::CLI.trace("info")',
22
+ "puts Bio::Commandeer.run 'echo 5', :log=>true"
23
+ ].join("\n")
24
+ f.close
25
+ lib = File.join(File.dirname(__FILE__), '..', 'lib')
26
+
27
+ status, stdout, stderr = systemu "RUBYLIB=$RUBYLIB:#{lib} ruby #{f.path}"
28
+
29
+ stderr.should == " INFO bio-commandeer: Running command: echo 5\n"+
30
+ " INFO bio-commandeer: Command finished with exitstatus 0\n"
31
+ stdout.should == "5\n"
32
+ end
33
+ end
34
+
35
+ it 'should do logging given a log object' do
36
+ Tempfile.open('script') do |f|
37
+ f.puts [
38
+ "require 'bio-commandeer'",
39
+ 'Bio::Log::CLI.logger("stderr"); Bio::Log::CLI.trace("info")',
40
+ 'log = Bio::Log::LoggerPlus.new("anotherlog"); Bio::Log::CLI.configure("anotherlog")',
41
+ "puts Bio::Commandeer.run 'echo 50', :log=>log"
42
+ ].join("\n")
43
+ f.close
44
+ lib = File.join(File.dirname(__FILE__), '..', 'lib')
45
+
46
+ status, stdout, stderr = systemu "RUBYLIB=$RUBYLIB:#{lib} ruby #{f.path}"
47
+
48
+ # Note the source of the log
49
+ stderr.should == " INFO anotherlog: Running command: echo 50\n"+
50
+ " INFO anotherlog: Command finished with exitstatus 0\n"
51
+ stdout.should == "50\n"
52
+ end
53
+ end
11
54
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bio-commandeer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben J. Woodcroft
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-12 00:00:00.000000000 Z
11
+ date: 2014-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bio-logger