dev_commands 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +11 -1
- data/lib/array.rb +2 -0
- data/lib/command.rb +30 -10
- data/lib/dev_commands.rb +2 -0
- data/lib/hash.rb +9 -4
- data/spec/command_spec.rb +0 -1
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c9172a254dca436cd1ae2b8c87126a7640371e49
|
4
|
+
data.tar.gz: b3b4d0264b2de92e4f5a3076de7bcd62192e37a6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 15c8d7c143dca42534965ed376af389ffde7e184e60809ddcfe8ab6bd614efaf942a0dfecf241d6e23b6ebab41952589aaab546fe1236c600a428f0bbde90283
|
7
|
+
data.tar.gz: dfee1127ace3bb8305f0ef27ccfa6c2a98290ca2b7a5c49b2264a12639193f50950766a733e621ac8969df3cef61192bf404ee7afe5843236e91cf1e1e5c680a
|
data/README.md
CHANGED
@@ -5,15 +5,25 @@ A ruby gem to aid in the definition and execution of system commands
|
|
5
5
|
### Installation
|
6
6
|
|
7
7
|
The gem can be installed by the single command
|
8
|
+
|
8
9
|
```
|
9
|
-
|
10
|
+
gem install dev_commands
|
10
11
|
```
|
11
12
|
|
12
13
|
### Usage
|
13
14
|
|
14
15
|
This is an example of a simple usage
|
16
|
+
|
15
17
|
```
|
16
18
|
require 'dev_commands'
|
19
|
+
|
20
|
+
cmd=Command.new 'ruby --version'
|
21
|
+
cmd.execute
|
22
|
+
puts "exit_code: #{cmd[:exit_code]}"
|
23
|
+
puts "output: #{cmd[:output]}"
|
24
|
+
|
25
|
+
# exit_code: 0
|
26
|
+
# output": ruby 2.0.0p481 (2014-05-08 revision 45883) [universal.x86_64-darwin14]
|
17
27
|
```
|
18
28
|
|
19
29
|
### License
|
data/lib/array.rb
CHANGED
data/lib/command.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'open3'
|
1
2
|
require_relative('./array.rb')
|
2
3
|
require_relative('./hash.rb')
|
3
4
|
require_relative('./timer.rb')
|
@@ -26,6 +27,7 @@ class Command < Hash
|
|
26
27
|
end
|
27
28
|
|
28
29
|
def execute
|
30
|
+
puts "#{self[:input]}"
|
29
31
|
pwd=Dir.pwd
|
30
32
|
Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
|
31
33
|
self[:directory] = pwd if(self[:directory].length==0)
|
@@ -41,7 +43,7 @@ class Command < Hash
|
|
41
43
|
begin
|
42
44
|
puts "eval(#{ruby})"
|
43
45
|
self[:output]=eval(ruby)
|
44
|
-
rescue
|
46
|
+
rescue
|
45
47
|
puts "unable to eval(#{ruby})"
|
46
48
|
raise "unable to eval(#{ruby})"
|
47
49
|
end
|
@@ -49,10 +51,20 @@ class Command < Hash
|
|
49
51
|
self[:elapsed] = timer.elapsed_str
|
50
52
|
self[:end_time] = Time.now
|
51
53
|
else
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
54
|
+
begin
|
55
|
+
self[:output],self[:error],self[:exit_code]= Open3.capture3(self[:input])
|
56
|
+
|
57
|
+
|
58
|
+
#self[:output] = `#{self[:input]}`
|
59
|
+
self[:elapsed] = timer.elapsed_str
|
60
|
+
self[:end_time] = Time.now
|
61
|
+
#self[:exit_code]=$?.to_i
|
62
|
+
rescue Exception => e
|
63
|
+
self[:elapsed] = timer.elapsed_str
|
64
|
+
self[:end_time] = Time.now
|
65
|
+
self[:error] = "Exception: " + e.to_s
|
66
|
+
self[:exit_code]=1
|
67
|
+
end
|
56
68
|
end
|
57
69
|
|
58
70
|
Dir.chdir(pwd) if pwd != Dir.pwd
|
@@ -73,13 +85,21 @@ class Command < Hash
|
|
73
85
|
end
|
74
86
|
|
75
87
|
def to_html
|
88
|
+
if self[:exit_code] == 0
|
89
|
+
[
|
90
|
+
'<div><table><tr><td width="20"></td><td><pre>',
|
91
|
+
self[:input],
|
92
|
+
'</pre></td></tr></table></div>'
|
93
|
+
].join
|
94
|
+
else
|
76
95
|
[
|
77
|
-
'<
|
96
|
+
'<div><table><tr><td width="20"></td><td><pre>',
|
78
97
|
self[:input],
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
'</
|
98
|
+
'</pre><table><tr><td width="20"></td><td><table>',
|
99
|
+
map { |k, v| ["<tr><td><strong>#{k}</strong></td>", v.respond_to?(:to_html) ? v.to_html : "<td><span><pre>#{v}</pre></span></td></tr>"] },
|
100
|
+
'</table>',
|
101
|
+
'</td></tr></table></td></tr></table></div>'
|
83
102
|
].join
|
103
|
+
end
|
84
104
|
end
|
85
105
|
end
|
data/lib/dev_commands.rb
CHANGED
data/lib/hash.rb
CHANGED
@@ -1,14 +1,19 @@
|
|
1
1
|
class Hash
|
2
2
|
def execute
|
3
3
|
self.each{|k,v|
|
4
|
-
|
4
|
+
if(v.is_a?(Array) && v.length==0)
|
5
|
+
self.delete k
|
6
|
+
else
|
7
|
+
#puts "executing #{k}"
|
8
|
+
v.execute if v.respond_to?(:execute)
|
9
|
+
end
|
5
10
|
}
|
6
11
|
end
|
7
12
|
def to_html
|
8
13
|
[
|
9
|
-
|
10
|
-
map { |k, v| ["<
|
11
|
-
'</
|
14
|
+
'<div>',
|
15
|
+
map { |k, v| ["<br/><div><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></div><br/>"] },
|
16
|
+
'</div>'
|
12
17
|
].join
|
13
18
|
end
|
14
19
|
end
|
data/spec/command_spec.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dev_commands
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lou Parslow
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: json
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rspec
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|