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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5827bce78cb19042fdd07b2d243fc155e8cf60c7
4
- data.tar.gz: 92ea3e418b5aa08ca64a75cd1c29291d5990e38c
3
+ metadata.gz: c9172a254dca436cd1ae2b8c87126a7640371e49
4
+ data.tar.gz: b3b4d0264b2de92e4f5a3076de7bcd62192e37a6
5
5
  SHA512:
6
- metadata.gz: 0e00c251347f44bb2e61f77d9d0607fd9ec52bc4e56d1ece80201eafb8e9adf0d702100844d164c91e01b58abd972e1e06be16a4c78771f550db06358e2c8501
7
- data.tar.gz: 17da8d58f365de3f3340fa5ab764991facfb23a7c639d3a3f888b76f8eb024142d3941db284034a1d7a30a3a8a4959c2cc01d465e61fb2311438a68ac26a2e27
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
- gem install dev_commands
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
@@ -10,9 +10,11 @@ class Array
10
10
 
11
11
  def to_html
12
12
  html=Array.new
13
+ html << '<div>'
13
14
  self.each{|e|
14
15
  html << e.to_html if e.respond_to?(:to_html)
15
16
  }
17
+ html << '</div>'
16
18
  html.join
17
19
  end
18
20
  end
@@ -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
- self[:output] = `#{self[:input]}`
53
- self[:elapsed] = timer.elapsed_str
54
- self[:end_time] = Time.now
55
- self[:exit_code]=$?.to_i
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
- '<h2>',
96
+ '<div><table><tr><td width="20"></td><td><pre>',
78
97
  self[:input],
79
- '</h2>',
80
- '<ul>',
81
- map { |k, v| ["<li><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></li>"] },
82
- '</ul>'
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
@@ -1 +1,3 @@
1
+ require 'json'
2
+ require 'systemu'
1
3
  require_relative('command.rb')
@@ -1,14 +1,19 @@
1
1
  class Hash
2
2
  def execute
3
3
  self.each{|k,v|
4
- v.execute if v.respond_to?(:execute)
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
- '<ul>',
10
- map { |k, v| ["<li><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></li>"] },
11
- '</ul>'
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
@@ -79,7 +79,6 @@ describe Command do
79
79
  cmd.execute
80
80
  FileUtils.rm_r("#{File.dirname(__FILE__)}/tmp")
81
81
  expect(cmd[:output].include?('rake_test')).to eq(true)
82
-
83
82
  end
84
83
 
85
84
  it "should be able to execute an array of commands" do
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.5
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