helm-cli 0.2.0 → 0.3.0

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
  SHA256:
3
- metadata.gz: 2178e1cf5c785d76d7adfdf613b8ba498f16ce460467e12bc5950e2b39c57410
4
- data.tar.gz: 13467f86a20c2c1c57294cbb30b72d1778d4cee9ca388dd0c15450cd2b7f4e4b
3
+ metadata.gz: df943c745733500ec8e3fe4f4625d93f0177e0a4d990b179b0a9dd97dcceea4d
4
+ data.tar.gz: cfc72f57fbc9bfc4024b56b7dd7f68a3d2f81afe8b37a355b3025e1d9984b3d7
5
5
  SHA512:
6
- metadata.gz: 4211173e0d471ad4ad65ca225a6f2f3037dcd7bd806c3caf8bfbf5a89ca6c1b0b3bb6020e393064b8588b572135a5e15a3af8d58a4a8b971216979aebd094121
7
- data.tar.gz: 973c27dd6c8cb77e99de3d80b5628d45ce58c80021f70cf4b4f2c18fde82399c7cd2ca74b7ebbcdea3741b39726f797ce43c8b724178e1ce1474bc544a120a4d
6
+ metadata.gz: 612a1959c9b722180fb4014910f081652154ed2ba267d1e121f9a423716ff6237495e67e6434d1fd3f71e5f564fa719337013ca7495178198977e02ee0d09a18
7
+ data.tar.gz: 37b29e9f4f293278a0e17ae149104aad929d4ddffa658c9ac95c87876ec66286af0873d64c107ac22ff95b5162b30f1a995e653cbb4fec05d923dacce3f3e5a8
@@ -1,3 +1,6 @@
1
+ ## 0.3.0
2
+ * Add ability to redirect Helm's stdout and stderr streams.
3
+
1
4
  ## 0.2.0
2
5
  * Fix bug causing crash when an error occurs while upgrading a chart.
3
6
 
@@ -1,4 +1,5 @@
1
1
  require 'helm-rb'
2
+ require 'open3'
2
3
 
3
4
  class HelmCLI
4
5
  class HelmError < StandardError; end
@@ -79,6 +80,33 @@ class HelmCLI
79
80
  end
80
81
  end
81
82
 
83
+ def with_pipes(out = STDOUT, err = STDERR)
84
+ previous_stdout = self.stdout
85
+ previous_stderr = self.stderr
86
+ self.stdout = out
87
+ self.stderr = err
88
+ yield
89
+ ensure
90
+ self.stdout = previous_stdout
91
+ self.stderr = previous_stderr
92
+ end
93
+
94
+ def stdout
95
+ Thread.current[stdout_key] || STDOUT
96
+ end
97
+
98
+ def stdout=(new_stdout)
99
+ Thread.current[stdout_key] = new_stdout
100
+ end
101
+
102
+ def stderr
103
+ Thread.current[stderr_key] || STDERR
104
+ end
105
+
106
+ def stderr=(new_stderr)
107
+ Thread.current[stderr_key] = new_stderr
108
+ end
109
+
82
110
  private
83
111
 
84
112
  def base_cmd
@@ -87,15 +115,52 @@ class HelmCLI
87
115
 
88
116
  def backticks(cmd)
89
117
  cmd_s = cmd.join(' ')
90
- `#{cmd_s}`.tap do
91
- self.last_status = $?
118
+ result = StringIO.new
119
+
120
+ Open3.popen3(cmd_s) do |p_stdin, p_stdout, p_stderr, wait_thread|
121
+ Thread.new do
122
+ begin
123
+ p_stdout.each { |line| result.puts(line) }
124
+ rescue IOError
125
+ end
126
+ end
127
+
128
+ Thread.new(stderr) do |t_stderr|
129
+ begin
130
+ p_stderr.each { |line| t_stderr.puts(line) }
131
+ rescue IOError
132
+ end
133
+ end
134
+
135
+ p_stdin.close
136
+ self.last_status = wait_thread.value
137
+ wait_thread.join
92
138
  end
139
+
140
+ result.string
93
141
  end
94
142
 
95
143
  def systemm(cmd)
96
144
  cmd_s = cmd.join(' ')
97
- system(cmd_s).tap do
98
- self.last_status = $?
145
+
146
+ Open3.popen3(cmd_s) do |p_stdin, p_stdout, p_stderr, wait_thread|
147
+ Thread.new(stdout) do |t_stdout|
148
+ begin
149
+ p_stdout.each { |line| t_stdout.puts(line) }
150
+ rescue IOError
151
+ end
152
+ end
153
+
154
+ Thread.new(stderr) do |t_stderr|
155
+ begin
156
+ p_stderr.each { |line| t_stderr.puts(line) }\
157
+ rescue IOError
158
+ end
159
+ end
160
+
161
+ p_stdin.close
162
+ self.last_status = wait_thread.value
163
+ wait_thread.join
99
164
  end
100
165
  end
101
166
 
@@ -104,6 +169,14 @@ class HelmCLI
104
169
  end
105
170
 
106
171
  def status_key
107
- :helm_rb_cli_last_status
172
+ :helm_cli_last_status
173
+ end
174
+
175
+ def stdout_key
176
+ :helm_cli_stdout
177
+ end
178
+
179
+ def stderr_key
180
+ :helm_cli_stderr
108
181
  end
109
182
  end
@@ -1,3 +1,3 @@
1
1
  class HelmCLI
2
- VERSION = '0.2.0'
2
+ VERSION = '0.3.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helm-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cameron Dutro
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-18 00:00:00.000000000 Z
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: helm-rb