dev_commands 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/array.rb +18 -0
- data/lib/command.rb +32 -8
- data/lib/hash.rb +14 -0
- data/spec/command_spec.rb +22 -8
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5827bce78cb19042fdd07b2d243fc155e8cf60c7
|
4
|
+
data.tar.gz: 92ea3e418b5aa08ca64a75cd1c29291d5990e38c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e00c251347f44bb2e61f77d9d0607fd9ec52bc4e56d1ece80201eafb8e9adf0d702100844d164c91e01b58abd972e1e06be16a4c78771f550db06358e2c8501
|
7
|
+
data.tar.gz: 17da8d58f365de3f3340fa5ab764991facfb23a7c639d3a3f888b76f8eb024142d3941db284034a1d7a30a3a8a4959c2cc01d465e61fb2311438a68ac26a2e27
|
data/lib/array.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
class Array
|
2
|
+
def execute
|
3
|
+
i=0
|
4
|
+
while i < self.length
|
5
|
+
self[i]=Command.new(self[i]) if(self[i].is_a?(String))
|
6
|
+
self[i].execute if(self[i].is_a?(Command))
|
7
|
+
i=i+1
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_html
|
12
|
+
html=Array.new
|
13
|
+
self.each{|e|
|
14
|
+
html << e.to_html if e.respond_to?(:to_html)
|
15
|
+
}
|
16
|
+
html.join
|
17
|
+
end
|
18
|
+
end
|
data/lib/command.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative('./array.rb')
|
2
|
+
require_relative('./hash.rb')
|
1
3
|
require_relative('./timer.rb')
|
2
4
|
|
3
5
|
class Command < Hash
|
@@ -10,8 +12,8 @@ class Command < Hash
|
|
10
12
|
self[:exit_code] = 0
|
11
13
|
self[:output] = ''
|
12
14
|
self[:error] = ''
|
13
|
-
self[:
|
14
|
-
self[:
|
15
|
+
self[:machine] = ''
|
16
|
+
self[:user] = ''
|
15
17
|
self[:start_time] = nil
|
16
18
|
self[:end_time] = nil
|
17
19
|
end
|
@@ -24,12 +26,12 @@ class Command < Hash
|
|
24
26
|
end
|
25
27
|
|
26
28
|
def execute
|
27
|
-
|
28
|
-
#Logger.start_command self
|
29
|
-
|
30
29
|
pwd=Dir.pwd
|
31
30
|
Dir.chdir(self[:directory]) if(self.has_key?(:directory) && File.exists?(self[:directory]))
|
32
|
-
|
31
|
+
self[:directory] = pwd if(self[:directory].length==0)
|
32
|
+
|
33
|
+
self[:machine] = Command.machine
|
34
|
+
self[:user] = Command.user
|
33
35
|
|
34
36
|
self[:start_time]=Time.now
|
35
37
|
timer=Timer.new
|
@@ -44,7 +46,6 @@ class Command < Hash
|
|
44
46
|
raise "unable to eval(#{ruby})"
|
45
47
|
end
|
46
48
|
|
47
|
-
#puts " " + timer.elapsed_str
|
48
49
|
self[:elapsed] = timer.elapsed_str
|
49
50
|
self[:end_time] = Time.now
|
50
51
|
else
|
@@ -55,7 +56,30 @@ class Command < Hash
|
|
55
56
|
end
|
56
57
|
|
57
58
|
Dir.chdir(pwd) if pwd != Dir.pwd
|
58
|
-
#Logger.end_command self
|
59
59
|
end
|
60
60
|
|
61
|
+
def self.machine
|
62
|
+
if !ENV['COMPUTERNAME'].nil?
|
63
|
+
return ENV['COMPUTERNAME']
|
64
|
+
end
|
65
|
+
|
66
|
+
machine = `hostname`
|
67
|
+
machine = machine.split('.')[0] if machine.include?('.')
|
68
|
+
return machine.strip
|
69
|
+
end
|
70
|
+
|
71
|
+
def self.user
|
72
|
+
ENV['USER'].nil? ? ENV['USERNAME'] : ENV['USER']
|
73
|
+
end
|
74
|
+
|
75
|
+
def to_html
|
76
|
+
[
|
77
|
+
'<h2>',
|
78
|
+
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>'
|
83
|
+
].join
|
84
|
+
end
|
61
85
|
end
|
data/lib/hash.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
class Hash
|
2
|
+
def execute
|
3
|
+
self.each{|k,v|
|
4
|
+
v.execute if v.respond_to?(:execute)
|
5
|
+
}
|
6
|
+
end
|
7
|
+
def to_html
|
8
|
+
[
|
9
|
+
'<ul>',
|
10
|
+
map { |k, v| ["<li><strong>#{k}</strong>", v.respond_to?(:to_html) ? v.to_html : "<span>#{v}</span></li>"] },
|
11
|
+
'</ul>'
|
12
|
+
].join
|
13
|
+
end
|
14
|
+
end
|
data/spec/command_spec.rb
CHANGED
@@ -35,15 +35,15 @@ describe Command do
|
|
35
35
|
cmd[:error]='error_test'
|
36
36
|
expect(cmd[:error]).to eq('error_test')
|
37
37
|
|
38
|
-
#
|
39
|
-
expect(cmd[:
|
40
|
-
cmd[:
|
41
|
-
expect(cmd[:
|
38
|
+
# Machine
|
39
|
+
expect(cmd[:machine]).to eq('')
|
40
|
+
cmd[:machine]='machine_test'
|
41
|
+
expect(cmd[:machine]).to eq('machine_test')
|
42
42
|
|
43
|
-
#
|
44
|
-
expect(cmd[:
|
45
|
-
cmd[:
|
46
|
-
expect(cmd[:
|
43
|
+
# User
|
44
|
+
expect(cmd[:user]).to eq('')
|
45
|
+
cmd[:user]='user_test'
|
46
|
+
expect(cmd[:user]).to eq('user_test')
|
47
47
|
|
48
48
|
# StartTime
|
49
49
|
expect(cmd[:start_time]).to eq(nil)
|
@@ -81,4 +81,18 @@ describe Command do
|
|
81
81
|
expect(cmd[:output].include?('rake_test')).to eq(true)
|
82
82
|
|
83
83
|
end
|
84
|
+
|
85
|
+
it "should be able to execute an array of commands" do
|
86
|
+
help=['git --help','rake --help','ruby --help']
|
87
|
+
help.execute
|
88
|
+
File.open('help.html','w'){|f|f.write(help.to_html)}
|
89
|
+
end
|
90
|
+
|
91
|
+
it "should be able to execute a hash with arrays or commands" do
|
92
|
+
commands=Hash.new
|
93
|
+
commands[:help]=['git --help','rake --help','ruby --help']
|
94
|
+
commands[:version]=['git --version','rake --version','ruby --version']
|
95
|
+
commands.execute
|
96
|
+
File.open('commands.html','w'){|f|f.write(commands.to_html)}
|
97
|
+
end
|
84
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lou Parslow
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01-
|
11
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -58,8 +58,10 @@ executables: []
|
|
58
58
|
extensions: []
|
59
59
|
extra_rdoc_files: []
|
60
60
|
files:
|
61
|
+
- lib/array.rb
|
61
62
|
- lib/command.rb
|
62
63
|
- lib/dev_commands.rb
|
64
|
+
- lib/hash.rb
|
63
65
|
- lib/timer.rb
|
64
66
|
- spec/command_spec.rb
|
65
67
|
- LICENSE
|