shellfold 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- YzljZDMxNGIyZmRiMjZhOTkyMjlmNWRjNzYzODY2NTA1N2UyZTY1OQ==
4
+ ZjFjZWYzM2RhZmY4ZmZjNGNhMjk2MjU4ZWFlODAzOThkZWE3NTVlYw==
5
5
  data.tar.gz: !binary |-
6
- MmNiYmQ1YWRjOGVmYTExMDEyNjEyMmI3MmZiM2IzMWJlN2E3Y2MyNg==
6
+ OWY1YmZjN2JhMzdkMzVkMDJhNmVjYWU2MzlkNzhlNjc3YTY0NGVkZA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- ZWQ2MGU5NTdhM2RjMGU2OTA2YTllZTg0Y2Y4OGFmY2FjMTUyYzdkN2JlYmVk
10
- Nzc4OGFkNmFhNzZmNzg0ZmViYjhiODViYjg5ZmRmNTJjMDc4OTU5ZTgzYmY2
11
- ZWIyN2RkNWRkNTVjMjgyNTczOTM4YTc5ZTExNWE1ZjA0MDA0N2Y=
9
+ NmVkOTk2YTBiMmUyYTA4NGRkNGFkODkzYjk2YmIxYmQ1ODIyYWQwNzRkNTA5
10
+ NzQ1YjI5MzYwYzk3YmE4Zjc0MzllNzllOGQzMjRhZTk5YWUzMmM1OGM0OGRm
11
+ NGZmYjMzODBmOWYwZmJkYzE2Zjk3MTJkMGJlODMwZTFlNDdmYWE=
12
12
  data.tar.gz: !binary |-
13
- MjBjYmJjNDZjY2YyYWY0ZmFhOTEwYWE2ZjI0MGJjMjRkNjkxZGM3MzBhNTBk
14
- N2IzY2MzYjA2ZDdmODcwNjMyNDU4MmJmMTk1OTE5Yjk5YjlmZDc0NWM2MzEz
15
- Mzk0MDIyZDU2ZWZlMmFjYTY3Mjc1MmE2M2FlY2FkZDVkODE1MzQ=
13
+ MGU1NWIzMTUyMWQ1OWNkNzI0ZjQ2MzE0NGFiY2RiM2JmMGY3N2I5OWFjM2U1
14
+ M2NiOTI3ZTA2NzA0MmYxMGRkYWU5NWQzNmZmNGNmMmVjODU3OGE2MTBhMzFl
15
+ Mzk2NDQ5YjhhOWRjZTAxNjNlYTk1NGVlZTczNTM4MWI1OGM1MjY=
@@ -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 :out_bar
13
- attr_reader :command
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
- @out = out
21
- @last_output_max = last_output_max
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
- write_out{"#{desc}"}
34
-
35
- thr = Thread.new do
36
- loop do
37
- sleep 10
38
- break unless running?
39
- write_out{' '} if not @been_here.tap{@been_here = true}
40
- write_out{'.'}
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 ignore_failure
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].reverse[0...@last_output_max].reverse,
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
- thr.kill
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
@@ -1,3 +1,3 @@
1
1
  module Shellfold
2
- VERSION = '0.0.1'
2
+ VERSION = '0.0.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shellfold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - flant