bio-commandeer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.rspec +1 -0
- data/.travis.yml +13 -0
- data/Gemfile +15 -0
- data/LICENSE.txt +20 -0
- data/README.md +44 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/lib/bio-commandeer.rb +14 -0
- data/lib/bio-commandeer/commandeer.rb +40 -0
- data/spec/bio-commandeer_spec.rb +11 -0
- data/spec/spec_helper.rb +12 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b9c771b0c81dc1e3b7d403e6e1a8710786992287
|
4
|
+
data.tar.gz: cb1e3b28ff63aa29bcc50fc8a5180ea3f968ac12
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2487a87d69c8546f09992a44055fe486b157c88a0a785fbf809301eb41a4e90714360b344747feb83ebc5eb790881fc8f532dde5c95fac668c3cb83c3095b23e
|
7
|
+
data.tar.gz: 5fd71b17b3e0f474fd5c1ce86507ff90fa706a4fc571d50fe912e52f72de7d582837d0a1ce9ec005256d8b81479e2f6ec204a5c9136c18c82e85493bb4ca8cd7
|
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 1.9.2
|
4
|
+
- 1.9.3
|
5
|
+
- jruby-19mode # JRuby in 1.9 mode
|
6
|
+
|
7
|
+
# - rbx-19mode
|
8
|
+
# - 1.8.7
|
9
|
+
# - jruby-18mode # JRuby in 1.8 mode
|
10
|
+
# - rbx-18mode
|
11
|
+
|
12
|
+
# uncomment this line if your project needs to run something other than `rake`:
|
13
|
+
# script: bundle exec rspec spec
|
data/Gemfile
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
gem 'bio-logger', '~>1.0'
|
6
|
+
gem 'systemu', '~>2.6'
|
7
|
+
|
8
|
+
# Add dependencies to develop your gem here.
|
9
|
+
# Include everything needed to run rake, tests, features, etc.
|
10
|
+
group :development do
|
11
|
+
gem "rspec", "~> 2.8"
|
12
|
+
gem "rdoc", "~> 3.12"
|
13
|
+
gem "jeweler", "~> 2.0"
|
14
|
+
gem "bundler", "~> 1.3"
|
15
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Ben J. Woodcroft
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# bio-commandeer
|
2
|
+
|
3
|
+
[![Build Status](https://secure.travis-ci.org/wwood/bioruby-commandeer.png)](http://travis-ci.org/wwood/bioruby-commandeer)
|
4
|
+
|
5
|
+
`Bio::Commandeer` provides a dead simple method of running shell commands from within Ruby:
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
require 'bio-commandeer'
|
9
|
+
Bio::Commandeer.run 'echo 5' #=> "5\n"
|
10
|
+
```
|
11
|
+
The real advantage of bio-commandeer is that when something goes wrong, it tells you; you don't have go looking for the error. Take for instance this simple script:
|
12
|
+
```ruby
|
13
|
+
#!/usr/bin/env ruby
|
14
|
+
require 'bio-commandeer'
|
15
|
+
print Bio::Commandeer.run('echo 5')
|
16
|
+
print Bio::Commandeer.run('cat /not_a_file')
|
17
|
+
```
|
18
|
+
The output is:
|
19
|
+
```sh
|
20
|
+
5
|
21
|
+
<snip>/lib/bio-commandeer/commandeer.rb:32:in `run': Command returned non-zero exit status (1), likely indicating failure. Command run was cat /not_a_file and the STDERR was: (Bio::CommandFailedException)
|
22
|
+
cat: /not_a_file: No such file or directory
|
23
|
+
from spec/eg.rb:4:in `<main>'
|
24
|
+
```
|
25
|
+
When a command fails (as detected through a non-zero exit status), then a `Bio::CommandFailedException` exception is thrown. While you can catch these exceptions with begin/rescue, often the best to do is fail, especially if you are writing quick one-off scripts.
|
26
|
+
|
27
|
+
Of course, when running commands such as this, take care not to trust the input directly from the command line, and especially not from a website. When in doubt, use `inspect` around the arguments to make sure that you don't run into [little bobby tables](http://xkcd.com/327).
|
28
|
+
|
29
|
+
Note: this software is under active development! Currently it is perhaps overly opinionated and as such not overly flexible.
|
30
|
+
|
31
|
+
## Installation
|
32
|
+
|
33
|
+
```sh
|
34
|
+
gem install bio-commandeer
|
35
|
+
```
|
36
|
+
|
37
|
+
## Biogems.info
|
38
|
+
|
39
|
+
This Biogem is published at (http://biogems.info/index.html#bio-commandeer)
|
40
|
+
|
41
|
+
## Copyright
|
42
|
+
|
43
|
+
Copyright (c) 2014 Ben J. Woodcroft. See LICENSE.txt for further details.
|
44
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "bio-commandeer"
|
18
|
+
gem.homepage = "http://github.com/wwood/bioruby-commandeer"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{dead simple method of running shell commands from within Ruby}
|
21
|
+
gem.description = %Q{A dead simple method of running shell commands from within Ruby, by applying opinion}
|
22
|
+
gem.email = "donttrustben near gmail.com"
|
23
|
+
gem.authors = ["Ben J. Woodcroft"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "bio-commandeer #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.1
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'systemu'
|
2
|
+
|
3
|
+
module Bio
|
4
|
+
# See #run
|
5
|
+
class Commandeer
|
6
|
+
include Bio::CommandeerLogging
|
7
|
+
|
8
|
+
# Run a command line program, and be opinionated about how to handle failure
|
9
|
+
#
|
10
|
+
# command is a string of the command to be run
|
11
|
+
# * options is a hash, with keys:
|
12
|
+
# :stdin: a string that is the stdin
|
13
|
+
# :log: turn on logging
|
14
|
+
def self.run(command, options={})
|
15
|
+
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)
|
21
|
+
end
|
22
|
+
|
23
|
+
@log.info "Running command: #{command}"
|
24
|
+
end
|
25
|
+
status, stdout, stderr = systemu command, :stdin => options[:stdin]
|
26
|
+
|
27
|
+
if @log
|
28
|
+
@log.info "Command finished with exitstatus #{status.exitstatus}"
|
29
|
+
end
|
30
|
+
|
31
|
+
if status.exitstatus != 0
|
32
|
+
raise Bio::CommandFailedException, "Command returned non-zero exit status (#{status.exitstatus}), likely indicating failure. Command run was #{command} and the STDERR was:\n#{stderr}"
|
33
|
+
end
|
34
|
+
|
35
|
+
return stdout
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class CommandFailedException < Exception; end
|
40
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "BioCommandeer" do
|
4
|
+
it "should return stdout" do
|
5
|
+
Bio::Commandeer.run("echo 1 3").should == "1 3\n"
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'should raise when exit status the command fails' do
|
9
|
+
expect {Bio::Commandeer.run("cat /definitelyNotAFile")}.to raise_error
|
10
|
+
end
|
11
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'bio-commandeer'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bio-commandeer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ben J. Woodcroft
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bio-logger
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: systemu
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.6'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.6'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.8'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.8'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rdoc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.12'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: jeweler
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '2.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '2.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: bundler
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '1.3'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '1.3'
|
97
|
+
description: A dead simple method of running shell commands from within Ruby, by applying
|
98
|
+
opinion
|
99
|
+
email: donttrustben near gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files:
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
files:
|
106
|
+
- ".document"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- Gemfile
|
110
|
+
- LICENSE.txt
|
111
|
+
- README.md
|
112
|
+
- Rakefile
|
113
|
+
- VERSION
|
114
|
+
- lib/bio-commandeer.rb
|
115
|
+
- lib/bio-commandeer/commandeer.rb
|
116
|
+
- spec/bio-commandeer_spec.rb
|
117
|
+
- spec/spec_helper.rb
|
118
|
+
homepage: http://github.com/wwood/bioruby-commandeer
|
119
|
+
licenses:
|
120
|
+
- MIT
|
121
|
+
metadata: {}
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.2.0.rc.1
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: dead simple method of running shell commands from within Ruby
|
142
|
+
test_files: []
|