minfra-cli 1.7.1 → 1.8.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a48cc8f6178ef5a337fbaa5c7d26b17ae22e699c91c35e4b6835da9ea489183
4
- data.tar.gz: fbcc714995a34fd2bf63aa48c09166d0f85c6a5f40495472f1cc7b96f7cf95a2
3
+ metadata.gz: 852b56a96bf9ed6edf769a5ab0f3543a41d0759d81c1bf99b4ecd488ed0467a4
4
+ data.tar.gz: badd1560a02911fa7a1b15de36eb6ae59abb584f29824247948899ae33ec11a2
5
5
  SHA512:
6
- metadata.gz: e37680916acd863645042a241853cbdefef19aeaff358a5196f0068fb3be81604bab7c59a11fff19fa13e5e0b8ed5d153f20c88aebdabbad4e6aea2ddcd1c331
7
- data.tar.gz: d395137f217d52837983604bd590c1a2ef813446ff27c7ada4e26575690f42b448d4623fe248825482a8ca569130e87d6ae2c4ee10665a1c9c9fb58a24684398
6
+ metadata.gz: d57dfbd9ac19d4a982ab32f418100ab9f8cdde0419ba20a59a34f0d519a1d9b7ca6f6dfcbb5a4203d659fc3e3ced737454f115668aac796dc44041a9f4062dc3
7
+ data.tar.gz: 2190a697f7044c2ee18ee722b2ab1a6497d5f90506d084145644e927404328203e8dd80481419a308e597ecc65d041e844d969aff41403baf4a1836b4d187f56
data/CHANGELOG.md CHANGED
@@ -1,3 +1,8 @@
1
+ # 1.8.0
2
+ * more output which "require" failed when loading dependencies
3
+ * catching closed stream errors in Minfra::Cli::Runner
4
+ * stderr of runner goes to info
5
+ * stdout of runner goes to debug
1
6
  # 1.7.1
2
7
  * fix plugin install edge cases
3
8
  # 1.7.0
@@ -49,7 +49,7 @@ module Minfra
49
49
  begin
50
50
  require minfra_path # this should register the command
51
51
  rescue LoadError
52
- logger.warn("Minfra plugin detected but dependencies not installed: #{minfra_path} (try: minfra plugin install)")
52
+ logger.warn("Minfra plugin detected but dependencies not installed: #{minfra_path} (#{$!}). TRY: minfra plugin install")
53
53
  end
54
54
  end
55
55
  else
@@ -1,3 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'English'
1
4
  require 'open3'
2
5
 
3
6
  module Minfra
@@ -5,16 +8,16 @@ module Minfra
5
8
  class Runner
6
9
  class Result
7
10
  include Logging
8
-
11
+
9
12
  attr_writer :status
10
-
13
+
11
14
  def initialize
12
- @stderr_lines=[]
13
- @stdout_lines=[]
14
- @status=nil
15
+ @stderr_lines = []
16
+ @stdout_lines = []
17
+ @status = nil
15
18
  end
16
-
17
- def add(line, stream=:stdout)
19
+
20
+ def add(line, stream = :stdout)
18
21
  line.chomp!
19
22
  if stream == :stdout
20
23
  @stdout_lines << line
@@ -24,7 +27,11 @@ module Minfra
24
27
  error line
25
28
  end
26
29
  end
27
-
30
+
31
+ def exitstatus
32
+ @status.exitstatus
33
+ end
34
+
28
35
  def success?
29
36
  @status.success?
30
37
  end
@@ -36,11 +43,11 @@ module Minfra
36
43
  def stdout
37
44
  @stdout_lines.join("\n")
38
45
  end
39
-
46
+
40
47
  def stderr
41
48
  @stderr_lines.join("\n")
42
- end
43
-
49
+ end
50
+
44
51
  def to_s
45
52
  stdout
46
53
  end
@@ -52,39 +59,46 @@ module Minfra
52
59
  end
53
60
 
54
61
  attr_reader :exit_on_error
62
+
55
63
  def initialize(cmd, exit_on_error: true)
56
- @cmd=cmd
64
+ @cmd = cmd
57
65
  @exit_on_error = exit_on_error
58
66
  end
59
67
 
60
68
  def run
61
69
  debug("running: #{@cmd}")
62
- res=nil
70
+ res = nil
63
71
  begin
64
- res=Result.new
72
+ res = Result.new
65
73
  # see: http://stackoverflow.com/a/1162850/83386
66
- Open3.popen3(@cmd) do |stdin, stdout, stderr, thread|
74
+ # the whole implementation is problematic as we migth miss some output lines
75
+ # Open4 might be a solution. Using Select might be a solution. Using Process.fork might be a solution....
76
+ Open3.popen3(@cmd) do |_stdin, stdout, stderr, thread|
67
77
  # read each stream from a new thread
68
- { :stdout => stdout, :stderr => stderr }.each do |key, stream|
78
+ { stdout: stdout, stderr: stderr }.each do |key, stream|
69
79
  Thread.new do
70
- until (raw_line = stream.gets).nil? do
80
+ until (raw_line = stream.gets).nil?
81
+ # stream.each do |raw_line|
71
82
  res.add(raw_line, key)
72
83
  end
84
+ rescue IOError # happens when you read from a close stream
85
+ raise unless ['stream closed in another thread', 'closed stream'].include?($ERROR_INFO.message)
86
+ # warn("Caught: #{$ERROR_INFO.message} for #{@cmd}")
73
87
  end
74
88
  end
75
89
  thread.join # don't exit until the external process is done
76
90
  res.status = thread.value
77
91
  end
78
- rescue
92
+ rescue StandardError
79
93
  end
80
-
94
+
81
95
  if res.error?
82
96
  error "command failed: #{@cmd}"
83
- info res.stdout
84
- error res.stderr
97
+ debug res.stdout
98
+ info res.stderr
85
99
  end
86
100
  if exit_on_error && res.error?
87
- info "exiting on error"
101
+ info "command exiting on error (#{res.exitstatus})"
88
102
  exit 1
89
103
  end
90
104
  res
@@ -1,5 +1,5 @@
1
1
  module Minfra
2
2
  module Cli
3
- VERSION = '1.7.1'.freeze
3
+ VERSION = '1.8.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minfra-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.1
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-02-08 00:00:00.000000000 Z
11
+ date: 2023-02-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor