kdeploy 1.0.5 → 1.0.7

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: 83c00c00789f233f007546ca34305f421da37baf99cdbae2f025335f1be06c19
4
- data.tar.gz: 6bf1d8e927c30f0e11d11aa14e1290ff8e7d224adb53a884fe621daf5776d7b1
3
+ metadata.gz: 15b3fbf88bffba0ba35c0b75e18cf57e5665d6bb512c354835574b07359de60a
4
+ data.tar.gz: 5e94c13abd994f4e2e445527aacd42dfd7a7e825f4a78c114b9c5aae78f928b0
5
5
  SHA512:
6
- metadata.gz: 6827b3c353a608b1c554cb5ddd4c32909a938dd5125b9ab0175312b7a8b41b68830c578e11f6616ecb9fb884516a59eede85ecd8df321319334f49952d688761
7
- data.tar.gz: fe23ae3d9b659ae1124dad9b8c5804c07884bdd463315f96aac4a988a29f9c86035c6f73fc74ae40846fbb3e747d597f89af9d79751dbbf5b4e7446835ed24fd
6
+ metadata.gz: 30e9abe01d5f729092df74cf6065279042421c42bde354c8214a497af56e6d0084f4618ef16ab9ec05d9f9adf9c8b8ab627d7fb22b59b407fdc904cf06917c79
7
+ data.tar.gz: 36827e5d4dd7178def48f0602d57ec5c1ee829a163082088915e1aad48f9a98feb00a7f04b6be80b6be802ec9d2ab3fed5b22bb1f3067db022e880f642bf50e9
data/exe/kdeploy CHANGED
@@ -1,6 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
+ # 自动修复常见 gem 扩展
5
+ %w[debug rbs].zip(%w[1.7.1 2.8.2]).each do |gem_name, version|
6
+ require gem_name
7
+ rescue LoadError
8
+ warn "[Kdeploy] 自动修复 #{gem_name}-#{version} ..."
9
+ system("gem pristine #{gem_name} --version #{version}")
10
+ begin
11
+ require gem_name
12
+ rescue LoadError
13
+ warn "[Kdeploy] 依然无法加载 #{gem_name}-#{version},请手动修复。"
14
+ end
15
+ end
16
+
4
17
  require 'kdeploy'
5
18
 
6
19
  Kdeploy::CLI.start(ARGV)
data/lib/kdeploy/cli.rb CHANGED
@@ -79,6 +79,13 @@ module Kdeploy
79
79
  method_option :parallel, type: :numeric, default: 5, desc: 'Number of parallel executions'
80
80
  method_option :dry_run, type: :boolean, desc: 'Show what would be done'
81
81
  def execute(task_file, task_name = nil)
82
+ # 只在最前面输出一次 banner
83
+ @banner_printed ||= false
84
+ unless @banner_printed
85
+ puts Kdeploy::Banner.show
86
+ @banner_printed = true
87
+ end
88
+
82
89
  load_task_file(task_file)
83
90
 
84
91
  tasks_to_run = if task_name
@@ -118,7 +125,8 @@ module Kdeploy
118
125
  exit 1
119
126
  end
120
127
 
121
- self.class.class_eval(File.read(file), file)
128
+ # 用 instance_eval 并传递顶层 binding,兼容 heredoc
129
+ self.class.module_eval(File.read(file), file)
122
130
  end
123
131
 
124
132
  def filter_hosts(limit, task_hosts)
@@ -168,31 +176,26 @@ module Kdeploy
168
176
  end
169
177
 
170
178
  def print_results(results, task_name)
171
- puts Kdeploy::Banner.show
172
179
  pastel = Pastel.new
173
-
174
- puts "#{pastel.bright_cyan('Task:')} #{pastel.bright_white(task_name)}"
175
- puts
180
+ puts pastel.bright_cyan("\n=== Task: #{task_name} ===\n")
176
181
 
177
182
  results.each do |host, result|
178
183
  status = result[:status] == :success ? pastel.green('✓ Success') : pastel.red('✗ Failed')
179
- puts "#{pastel.bright_white(host)} - #{status}"
184
+ puts pastel.bright_white("[#{host}] #{status}")
180
185
 
181
186
  if result[:status] == :success
182
187
  result[:output].each do |cmd|
183
188
  # 显示命令
184
189
  if cmd[:command].include?('<<') || cmd[:command].include?("\n")
185
- # 多行命令显示
186
190
  first_line = cmd[:command].lines.first.strip
187
- puts " #{pastel.bright_yellow('$')} #{first_line}"
191
+ puts pastel.bright_yellow(" $ #{first_line}")
188
192
  cmd[:command].lines[1..].each do |line|
189
193
  next if line.strip.empty?
190
194
 
191
- puts " #{pastel.bright_yellow('>')} #{line.strip}"
195
+ puts pastel.bright_yellow(" > #{line.strip}")
192
196
  end
193
197
  else
194
- # 单行命令显示
195
- puts " #{pastel.bright_yellow('$')} #{cmd[:command].strip}"
198
+ puts pastel.bright_yellow(" $ #{cmd[:command].strip}")
196
199
  end
197
200
 
198
201
  # 显示输出
@@ -200,20 +203,20 @@ module Kdeploy
200
203
  output.each_line do |line|
201
204
  next if line.strip.empty?
202
205
 
203
- puts " #{line.rstrip}"
206
+ puts pastel.white(" #{line.rstrip}")
204
207
  end
205
208
 
206
209
  # 显示错误输出
207
210
  if cmd[:output].is_a?(Hash) && !cmd[:output][:stderr].empty?
208
211
  cmd[:output][:stderr].each_line do |line|
209
- puts " #{pastel.red(line.rstrip)}" unless line.strip.empty?
212
+ puts pastel.red(" #{line.rstrip}") unless line.strip.empty?
210
213
  end
211
214
  end
212
215
 
213
216
  puts
214
217
  end
215
218
  else
216
- puts " #{pastel.red(result[:error])}"
219
+ puts pastel.red(" #{result[:error]}")
217
220
  puts
218
221
  end
219
222
  end
@@ -24,12 +24,16 @@ module Kdeploy
24
24
  task[:block].call.each do |command|
25
25
  case command[:type]
26
26
  when :run
27
+ puts "[#{name}] $ #{command[:command].lines.first.strip}" # 实时输出主机和命令
28
+ command[:command].lines[1..].each { |line| puts "[#{name}] > #{line.strip}" unless line.strip.empty? }
27
29
  output = executor.execute(command[:command])
28
30
  result[:output] << { command: command[:command], output: output }
29
31
  when :upload
32
+ puts "[#{name}] upload: #{command[:source]} -> #{command[:destination]}"
30
33
  executor.upload(command[:source], command[:destination])
31
34
  result[:output] << { command: "upload: #{command[:source]} -> #{command[:destination]}" }
32
35
  when :upload_template
36
+ puts "[#{name}] upload_template: #{command[:source]} -> #{command[:destination]}"
33
37
  executor.upload_template(command[:source], command[:destination], command[:variables])
34
38
  result[:output] << { command: "upload_template: #{command[:source]} -> #{command[:destination]}" }
35
39
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Kdeploy
4
- VERSION = '1.0.5'
4
+ VERSION = '1.0.7'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kdeploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kk