shellfold 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 +8 -8
- data/lib/shellfold.rb +38 -26
- data/lib/shellfold/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
ZjFjZWYzM2RhZmY4ZmZjNGNhMjk2MjU4ZWFlODAzOThkZWE3NTVlYw==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OWY1YmZjN2JhMzdkMzVkMDJhNmVjYWU2MzlkNzhlNjc3YTY0NGVkZA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NmVkOTk2YTBiMmUyYTA4NGRkNGFkODkzYjk2YmIxYmQ1ODIyYWQwNzRkNTA5
|
10
|
+
NzQ1YjI5MzYwYzk3YmE4Zjc0MzllNzllOGQzMjRhZTk5YWUzMmM1OGM0OGRm
|
11
|
+
NGZmYjMzODBmOWYwZmJkYzE2Zjk3MTJkMGJlODMwZTFlNDdmYWE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGU1NWIzMTUyMWQ1OWNkNzI0ZjQ2MzE0NGFiY2RiM2JmMGY3N2I5OWFjM2U1
|
14
|
+
M2NiOTI3ZTA2NzA0MmYxMGRkYWU5NWQzNmZmNGNmMmVjODU3OGE2MTBhMzFl
|
15
|
+
Mzk2NDQ5YjhhOWRjZTAxNjNlYTk1NGVlZTczNTM4MWI1OGM1MjY=
|
data/lib/shellfold.rb
CHANGED
@@ -7,52 +7,64 @@ module Shellfold
|
|
7
7
|
class Command
|
8
8
|
include MonitorMixin
|
9
9
|
|
10
|
+
attr_reader :command
|
10
11
|
attr_reader :desc
|
11
12
|
attr_reader :out
|
12
|
-
attr_reader :
|
13
|
-
attr_reader :
|
13
|
+
attr_reader :live_log
|
14
|
+
attr_reader :log_failure
|
15
|
+
attr_reader :last_output_max
|
14
16
|
|
15
17
|
def initialize(*args, desc: nil,
|
16
18
|
out: $stdout,
|
19
|
+
live_log: false,
|
20
|
+
log_failure: false,
|
17
21
|
last_output_max: 200, **kwargs)
|
18
22
|
super()
|
19
23
|
|
20
|
-
|
21
|
-
|
24
|
+
kwargs.merge!(live_stderr: out, live_stdout: out) if live_log
|
25
|
+
|
22
26
|
@command = Mixlib::ShellOut.new(*args, **kwargs)
|
23
27
|
@desc = desc || command.command
|
28
|
+
@out = out
|
29
|
+
@live_log = live_log
|
30
|
+
@log_failure = log_failure
|
31
|
+
@last_output_max = last_output_max
|
24
32
|
@running = false
|
25
33
|
end
|
26
34
|
|
27
|
-
def run
|
28
|
-
run(ignore_failure: false)
|
29
|
-
end
|
30
|
-
|
31
|
-
def run(ignore_failure: true)
|
35
|
+
def run
|
32
36
|
running!
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
37
|
+
|
38
|
+
progress_bar_thr = nil
|
39
|
+
|
40
|
+
unless live_log
|
41
|
+
write_out{desc}
|
42
|
+
progress_bar_thr = Thread.new do
|
43
|
+
loop do
|
44
|
+
sleep 10
|
45
|
+
break unless running?
|
46
|
+
write_out do
|
47
|
+
[@been_here.tap{@been_here = true} ? nil : ' ', '.'].compact.join
|
48
|
+
end
|
49
|
+
end
|
41
50
|
end
|
51
|
+
else
|
52
|
+
write_out{desc + "\n"}
|
42
53
|
end
|
43
54
|
|
44
55
|
on_command_finish = proc do
|
56
|
+
next if live_log
|
45
57
|
if not command.status.success?
|
46
58
|
write_out{" [FAILED: #{command.status.inspect}]"}
|
47
|
-
if
|
48
|
-
write_out{"\n"}
|
49
|
-
else
|
59
|
+
if log_failure
|
50
60
|
msg = ["# COMMAND: #{command.command}\n",
|
51
61
|
"# LAST OUTPUT BEGIN:\n",
|
52
62
|
*[*command.stdout.lines,
|
53
|
-
*command.stderr.lines].
|
63
|
+
*command.stderr.lines].last(last_output_max),
|
54
64
|
"# LAST OUTPUT END\n"].join
|
55
65
|
write_out{"\n#{msg}"}
|
66
|
+
else
|
67
|
+
write_out{"\n"}
|
56
68
|
end
|
57
69
|
else
|
58
70
|
write_out{" [DONE]\n"}
|
@@ -66,7 +78,7 @@ module Shellfold
|
|
66
78
|
rescue Mixlib::ShellOut::CommandTimeout
|
67
79
|
on_command_finish.call
|
68
80
|
ensure
|
69
|
-
|
81
|
+
progress_bar_thr.kill if progress_bar_thr
|
70
82
|
end
|
71
83
|
|
72
84
|
command
|
@@ -92,12 +104,12 @@ module Shellfold
|
|
92
104
|
end # Command
|
93
105
|
|
94
106
|
class << self
|
95
|
-
def run(*args)
|
96
|
-
Command.new(*args).run
|
107
|
+
def run(*args, **kwargs)
|
108
|
+
Command.new(*args, **kwargs).run
|
97
109
|
end
|
98
110
|
|
99
|
-
def run!(*args)
|
100
|
-
Command.new(*args).run
|
111
|
+
def run!(*args, **kwargs)
|
112
|
+
Command.new(*args, log_failure: true, **kwargs).run
|
101
113
|
end
|
102
114
|
end # << self
|
103
115
|
end # Shellfold
|
data/lib/shellfold/version.rb
CHANGED