rsystem 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +22 -0
- data/README.md +18 -4
- data/lib/rsystem.rb +23 -4
- data/lib/rsystem/version.rb +1 -1
- data/spec/rsystem_spec.rb +8 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ed9e665a05086dbdd52905d68f25f5d44465d74
|
4
|
+
data.tar.gz: cbc2f064e1af691ac2430cce9699167f5cf6e8e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dc00c0a07b41e33aa9c204a3e2905b661c007166ecca6189995534828b757c1be8e5504221ec24a5e9f10a845c55573b32654d3cbb8b6b7189752fc323b9add3
|
7
|
+
data.tar.gz: 703222eda2aae3c5cbca39caf8ec3e16551e2685b7f368d6b460824ff6f373ebae28d037422b24006b7e10503345ae86acd0c8a9f4a113c4e939466dabfe5dc1
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Miles Jordan
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# RSystem
|
2
2
|
|
3
|
-
RSystem simply executes a system() call but it also echoes the command that it is about to execute to stdout.
|
3
|
+
RSystem simply executes a system() call but it also echoes the command that it is about to execute to stdout, and will raise an exception if the command does not return successfully.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
@@ -20,11 +20,25 @@ Or install it yourself as:
|
|
20
20
|
|
21
21
|
## Usage
|
22
22
|
|
23
|
-
|
23
|
+
Right now this gem just contains one statuc method.
|
24
24
|
|
25
|
-
|
25
|
+
`RSystem::Runner:Run(<command>, [options={}])`
|
26
26
|
|
27
|
-
|
27
|
+
Simply using `RSystem::Runner:Run(<command>)` will execute the command and echo it, returning the return code of the command that is ran or raising an exception if it did not return successfully.
|
28
|
+
|
29
|
+
### Options
|
30
|
+
|
31
|
+
There are two options specific to the `run` method that you can use, with the defaults listed here:
|
32
|
+
|
33
|
+
options{echo:true, raise_on_error: true}
|
34
|
+
|
35
|
+
The other options that you can pass are the same as the ones listed for the [spawn](http://www.ruby-doc.org/core-2.2.0/Kernel.html#method-i-spawn) method in Ruby's Kernel module.
|
36
|
+
|
37
|
+
## Todo
|
38
|
+
|
39
|
+
- more tests
|
40
|
+
- output logging to a file
|
41
|
+
- stdout/stderr configuration
|
28
42
|
|
29
43
|
## Contributing
|
30
44
|
|
data/lib/rsystem.rb
CHANGED
@@ -2,9 +2,28 @@ require "rsystem/version"
|
|
2
2
|
|
3
3
|
module RSystem
|
4
4
|
class Runner
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
def self.run(command, options={})
|
6
|
+
|
7
|
+
# Only set the default options of the haven't already been set
|
8
|
+
options[:echo] = true unless options.has_key?(:echo)
|
9
|
+
options[:raise_on_error] = true unless options.has_key?(:raise_on_error)
|
10
|
+
|
11
|
+
puts "[#{Time.now}] Executing: #{command}" if options[:echo]
|
12
|
+
|
13
|
+
# Remove custom options so we can pass the entire options hash to system()
|
14
|
+
sys_options = options.clone
|
15
|
+
sys_options.delete(:echo)
|
16
|
+
sys_options.delete(:raise_on_error)
|
17
|
+
|
18
|
+
ret = system(command, sys_options)
|
19
|
+
if !ret and options[:raise_on_error]
|
20
|
+
raise FailedExecutionException, "[#{Time.now}] Error: The executed command returned a failure code."
|
21
|
+
else
|
22
|
+
ret
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class FailedExecutionException < Exception
|
9
28
|
end
|
10
29
|
end
|
data/lib/rsystem/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rsystem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Miles Jordan
|
@@ -75,12 +75,14 @@ extra_rdoc_files: []
|
|
75
75
|
files:
|
76
76
|
- .gitignore
|
77
77
|
- Gemfile
|
78
|
+
- LICENSE
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|
80
81
|
- Rakefile
|
81
82
|
- lib/rsystem.rb
|
82
83
|
- lib/rsystem/version.rb
|
83
84
|
- rsystem.gemspec
|
85
|
+
- spec/rsystem_spec.rb
|
84
86
|
homepage: ''
|
85
87
|
licenses:
|
86
88
|
- MIT
|
@@ -106,4 +108,5 @@ signing_key:
|
|
106
108
|
specification_version: 4
|
107
109
|
summary: RSystem simply executes a system() call but it also echoes the command that
|
108
110
|
it is about to execute to stdout.
|
109
|
-
test_files:
|
111
|
+
test_files:
|
112
|
+
- spec/rsystem_spec.rb
|