bio-commandeer 0.1.3 → 0.2.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: 65c0c939bb20515c6669195c285d113ac6da4638
4
- data.tar.gz: f23a66f1c076dd46147451c948a68458345540af
3
+ metadata.gz: 386271eaa4c39b91d6a3a76891dd64b3ad8d1744
4
+ data.tar.gz: 56b7ee0ac4061f603d4c41491b5b81d968cd9332
5
5
  SHA512:
6
- metadata.gz: 3c391e332150e3d05bb2451422c404bd04eb7310656f15910cb72a226ec29e82e510e88c6e537653f23a250df006b292dc8d96a96ab648a066664cef8a51074e
7
- data.tar.gz: 818c977dd5192d42d0d69fae2e67f9dc8385b873487c98eda9649cc436544a62101075e3cbee7520480aa015146cf78fa67a8f3d6f62f4b007d8bb232bd70f13
6
+ metadata.gz: 17cfb131f6887eabf59776676610a6f1c9c39d2c8ba7c63e3179c2e53e4b25d85de44e371d2c1c30ff27c513469ce4a5938e9da8441e901010ce1e4a25faeea7
7
+ data.tar.gz: fdba58dd87e0e144a108d8e454d0d194c9ebee19bb1e1d80700421291070bffebc151ddbd78ff9c4beaff472c04c96a719598d303f613fa8156ed18955da6597
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gem 'systemu', '~>2.6'
9
9
  # Include everything needed to run rake, tests, features, etc.
10
10
  group :development do
11
11
  gem "rspec", "~> 3.2"
12
- gem "rdoc", "~>4.2"
12
+ gem "rdoc", "~> 5.0"
13
13
  gem "jeweler", "~> 2.0"
14
14
  gem "bundler", "~> 1.3"
15
15
  end
data/README.md CHANGED
@@ -50,6 +50,13 @@ Or a logging can be given directly, so long as it has an `info` method:
50
50
  Bio::Commandeer.run 'echo 5', :log=>my_logger
51
51
  ```
52
52
 
53
+ A command can also be run to completion without raising an errors using `run_to_finish`:
54
+ ```ruby
55
+ require 'bio-commandeer'
56
+ result = Bio::Commandeer.run_to_finish 'echo 5' #=> Bio::CommandResult
57
+ result.stdout #=> "5\n"
58
+ ```
59
+
53
60
 
54
61
  ## Installation
55
62
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
@@ -3,7 +3,6 @@ require 'systemu'
3
3
  module Bio
4
4
  # See #run
5
5
  class Commandeer
6
-
7
6
  # Run a command line program, and be opinionated about how to handle failure
8
7
  #
9
8
  # command is a string of the command to be run
@@ -11,6 +10,17 @@ module Bio
11
10
  # :stdin: a string that is the stdin
12
11
  # :log: if true, turn on logging. If given an object use it as the logger
13
12
  def self.run(command, options={})
13
+ obj = run_to_finish(command, options)
14
+
15
+ if obj.status.exitstatus != 0
16
+ raise Bio::CommandFailedException, "Command returned non-zero exit status (#{obj.status.exitstatus}), likely indicating failure. Command run was #{command} and the STDERR was:\n#{obj.stderr}\nSTDOUT was: #{obj.stdout}"
17
+ end
18
+
19
+ return obj.stdout
20
+ end
21
+
22
+ # Options are as per #run, but return a CommandResult object
23
+ def self.run_to_finish(command, options={})
14
24
  if options[:log]
15
25
  if options[:log] == true
16
26
  log_name = 'bio-commandeer'
@@ -25,19 +35,20 @@ module Bio
25
35
 
26
36
  @log.info "Running command: #{command}"
27
37
  end
28
- status, stdout, stderr = systemu command, :stdin => options[:stdin]
38
+ res = CommandResult.new
39
+ res.command = command
40
+ res.status, res.stdout, res.stderr = systemu command, :stdin => options[:stdin]
29
41
 
30
42
  if @log
31
- @log.info "Command finished with exitstatus #{status.exitstatus}"
43
+ @log.info "Command finished with exitstatus #{res.status.exitstatus}"
32
44
  end
33
-
34
- if status.exitstatus != 0
35
- raise Bio::CommandFailedException, "Command returned non-zero exit status (#{status.exitstatus}), likely indicating failure. Command run was #{command} and the STDERR was:\n#{stderr}\nSTDOUT was: #{stdout}"
36
- end
37
-
38
- return stdout
45
+ return res
39
46
  end
40
47
  end
41
48
 
49
+ class CommandResult
50
+ attr_accessor :stdout, :stderr, :command, :status
51
+ end
52
+
42
53
  class CommandFailedException < Exception; end
43
54
  end
@@ -51,4 +51,12 @@ describe "BioCommandeer" do
51
51
  expect(stdout).to eq "50\n"
52
52
  end
53
53
  end
54
+
55
+ it 'should run to finish' do
56
+ obj = Bio::Commandeer.run_to_finish("cat /definitelyNotAFile")
57
+ expect(obj.stdout).to eq ""
58
+ expect(obj.status.exitstatus).to eq 1
59
+ expect(obj.stderr).to eq "cat: /definitelyNotAFile: No such file or directory\n"
60
+ expect(obj.command).to eq "cat /definitelyNotAFile"
61
+ end
54
62
  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.1.3
4
+ version: 0.2.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: 2016-04-18 00:00:00.000000000 Z
11
+ date: 2017-08-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bio-logger
@@ -58,14 +58,14 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '4.2'
61
+ version: '5.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '4.2'
68
+ version: '5.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: jeweler
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -135,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
135
  version: '0'
136
136
  requirements: []
137
137
  rubyforge_project:
138
- rubygems_version: 2.5.1
138
+ rubygems_version: 2.6.8
139
139
  signing_key:
140
140
  specification_version: 4
141
141
  summary: dead simple method of running shell commands from within Ruby