pindo 5.4.0 → 5.4.1

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: 56fcfdba92a710c2c7ab85226d30f305cbb1fca5d3fccb57d5c62e6593c8afbb
4
- data.tar.gz: a2d7a5c80ca642869ce4f79ef9dca35383b7426c5cf15077937137db899b4eab
3
+ metadata.gz: 11f6f7b05adc236bf8e379152b9e2d6dbd1bb62da99067637915d3f17768fe77
4
+ data.tar.gz: 7dd2e73b4bb8edb542d3f274eecf64d3c76b8877ac76aa31ca0e574e7606e3bd
5
5
  SHA512:
6
- metadata.gz: 54cef915058ddb2d765e136181c13b1e1e6e1376316e8b443a19e54bf03da4afb7763564348c7fe04099cb87476e3547664016dd479936423243360036a9fbe4
7
- data.tar.gz: 86a5729f1929db20b938254ae541c1310fce8dba85d7d0088966f197aad668723c11270775bbdcd8651ca86609d357e69fac7dfd8e6d1459133d58fe9357bccd
6
+ metadata.gz: 4396cfc57f38554634ca62437021ef29c193a347ffbe460a09cf1bfb9f8ac8e0d1e6e584628c044be1935d41be4e5b131c6d9036f3527d9031ab821e79e713e4
7
+ data.tar.gz: 135931aae0cdc3c823e59764611f6e64d30d7e58775c1975776073a551b7e849b937859ba9283f45ca3e40dc37035f23594732fd51fb4b943cb1a2c9bd928783
@@ -16,14 +16,20 @@ module Pindo
16
16
  @file_cache_loaded = false # 标记文件缓存是否已加载
17
17
  @cache_enabled = false # 默认禁用缓存
18
18
  @command_group = nil # 命令组名称
19
+ @verbose = false # 是否输出详细日志
19
20
  ensure_cache_dir
20
21
  end
21
22
 
23
+ # 判断是否处于 verbose 模式
24
+ def verbose?
25
+ @verbose || ENV['PINDO_VERBOSE'] == '1' || ENV['PINDO_DEBUG'] == '1'
26
+ end
27
+
22
28
  # 设置当前上下文
23
29
  def set_context(command, directory = nil, options = {})
24
30
  # 如果已有命令在执行,这是嵌套调用,不需要做任何事
25
31
  unless @current_command.nil?
26
- puts "[PindoContext] 嵌套调用 #{command},使用已有上下文 (根命令: #{@current_command},命令组: #{@command_group})"
32
+ puts "[PindoContext] 嵌套调用 #{command},使用已有上下文 (根命令: #{@current_command},命令组: #{@command_group})" if verbose?
27
33
  return
28
34
  end
29
35
 
@@ -33,29 +39,34 @@ module Pindo
33
39
 
34
40
  # 从选项中获取缓存配置
35
41
  @cache_enabled = options[:cache_enabled] || false
42
+ @verbose = options[:verbose] || false
36
43
  # 使用 get_command_group 来确定缓存组
37
44
  @command_group = get_command_group(command)
38
45
 
39
- puts "\n[PindoContext] ========== 设置顶层命令上下文 =========="
40
- puts "[PindoContext] 命令: #{command}"
41
- puts "[PindoContext] 目录: #{@current_directory}"
42
- puts "[PindoContext] 缓存启用: #{@cache_enabled}"
43
- puts "[PindoContext] 命令组: #{@command_group}"
44
- puts "[PindoContext] options: #{options.inspect}"
46
+ if verbose?
47
+ puts "\n[PindoContext] ========== 设置顶层命令上下文 =========="
48
+ puts "[PindoContext] 命令: #{command}"
49
+ puts "[PindoContext] 目录: #{@current_directory}"
50
+ puts "[PindoContext] 缓存启用: #{@cache_enabled}"
51
+ puts "[PindoContext] 命令组: #{@command_group}"
52
+ puts "[PindoContext] options: #{options.inspect}"
53
+ end
45
54
 
46
55
  # 仅在启用缓存时加载文件缓存
47
56
  if @cache_enabled && !@file_cache_loaded
48
- puts "[PindoContext] 准备加载文件缓存..."
57
+ puts "[PindoContext] 准备加载文件缓存..." if verbose?
49
58
  load_file_cache_with_confirmation
50
59
  @file_cache_loaded = true
51
60
  else
52
- if !@cache_enabled
53
- puts "[PindoContext] 缓存未启用,跳过文件缓存加载"
54
- elsif @file_cache_loaded
55
- puts "[PindoContext] 文件缓存已加载,跳过重复加载"
61
+ if verbose?
62
+ if !@cache_enabled
63
+ puts "[PindoContext] 缓存未启用,跳过文件缓存加载"
64
+ elsif @file_cache_loaded
65
+ puts "[PindoContext] 文件缓存已加载,跳过重复加载"
66
+ end
56
67
  end
57
68
  end
58
- puts "[PindoContext] ======================================\n"
69
+ puts "[PindoContext] ======================================\n" if verbose?
59
70
  end
60
71
 
61
72
  # 重置上下文(顶层命令结束时调用)
@@ -91,14 +102,14 @@ module Pindo
91
102
  # 更新该命令组的最后修改时间
92
103
  @memory_selections[project_path][root_command]['__last_modified__'] = Time.now.to_i
93
104
 
94
- puts "[PindoContext] 保存到内存: [#{project_path}][#{root_command}][#{key}] = #{value.inspect}"
105
+ puts "[PindoContext] 保存到内存: [#{project_path}][#{root_command}][#{key}] = #{value.inspect}" if verbose?
95
106
 
96
107
  # 仅在启用缓存时保存到文件
97
108
  if @cache_enabled
98
109
  save_file_cache
99
- puts "[PindoContext] 已保存到文件缓存"
110
+ puts "[PindoContext] 已保存到文件缓存" if verbose?
100
111
  else
101
- puts "[PindoContext] 缓存未启用,仅保存到内存"
112
+ puts "[PindoContext] 缓存未启用,仅保存到内存" if verbose?
102
113
  end
103
114
  end
104
115
 
@@ -114,9 +125,9 @@ module Pindo
114
125
  value = @memory_selections.dig(project_path, root_command, key)
115
126
 
116
127
  if value
117
- puts "[PindoContext] 从内存获取: [#{project_path}][#{root_command}][#{key}] = #{value.inspect}"
128
+ puts "[PindoContext] 从内存获取: [#{project_path}][#{root_command}][#{key}] = #{value.inspect}" if verbose?
118
129
  else
119
- puts "[PindoContext] 内存中未找到: [#{project_path}][#{root_command}][#{key}]" if ENV['PINDO_DEBUG']
130
+ puts "[PindoContext] 内存中未找到: [#{project_path}][#{root_command}][#{key}]" if verbose?
120
131
  end
121
132
 
122
133
  value
@@ -192,7 +203,7 @@ module Pindo
192
203
  @memory_selections[proj_path].delete(cmd)
193
204
  @memory_selections.delete(proj_path) if @memory_selections[proj_path].empty?
194
205
  save_file_cache
195
- puts "[PindoContext] 清除缓存: [#{proj_path}][#{cmd}]" if ENV['PINDO_DEBUG']
206
+ puts "[PindoContext] 清除缓存: [#{proj_path}][#{cmd}]" if verbose?
196
207
  end
197
208
  end
198
209
 
@@ -222,10 +233,10 @@ module Pindo
222
233
  def load_file_cache_with_confirmation
223
234
  file_path = cache_file_path
224
235
 
225
- puts "[PindoContext] 检查文件缓存: #{file_path}"
236
+ puts "[PindoContext] 检查文件缓存: #{file_path}" if verbose?
226
237
 
227
238
  unless File.exist?(file_path)
228
- puts "[PindoContext] 文件缓存不存在,跳过加载"
239
+ puts "[PindoContext] 文件缓存不存在,跳过加载" if verbose?
229
240
  return
230
241
  end
231
242
 
@@ -240,7 +251,7 @@ module Pindo
240
251
  project_path = get_project_path
241
252
  root_command = @command_group || @current_command
242
253
 
243
- puts "[PindoContext] 查找缓存: [#{project_path}][#{root_command}]"
254
+ puts "[PindoContext] 查找缓存: [#{project_path}][#{root_command}]" if verbose?
244
255
 
245
256
  # 检查三级结构中是否有当前上下文的缓存
246
257
  cached_selections = file_cache.dig(project_path, root_command)
@@ -327,9 +338,9 @@ module Pindo
327
338
  end
328
339
  end
329
340
 
330
- puts "[PindoContext] 处理文件缓存: #{file_path}" if ENV['PINDO_DEBUG']
341
+ puts "[PindoContext] 处理文件缓存: #{file_path}" if verbose?
331
342
  rescue => e
332
- puts "[PindoContext] 加载缓存失败: #{e.message}" if ENV['PINDO_DEBUG']
343
+ puts "[PindoContext] 加载缓存失败: #{e.message}" if verbose?
333
344
  end
334
345
  end
335
346
 
@@ -355,9 +366,9 @@ module Pindo
355
366
  # 写入文件
356
367
  File.write(file_path, JSON.pretty_generate(file_cache))
357
368
 
358
- puts "[PindoContext] 保存文件缓存: #{file_path}" if ENV['PINDO_DEBUG']
369
+ puts "[PindoContext] 保存文件缓存: #{file_path}" if verbose?
359
370
  rescue => e
360
- puts "[PindoContext] 保存缓存失败: #{e.message}" if ENV['PINDO_DEBUG']
371
+ puts "[PindoContext] 保存缓存失败: #{e.message}" if verbose?
361
372
  end
362
373
  end
363
374
 
@@ -403,7 +414,7 @@ module Pindo
403
414
  # 如果没有时间戳,视为过期
404
415
  if last_modified.nil?
405
416
  expired_commands << "[#{project_path}][#{command}] (无时间戳)"
406
- puts "[PindoContext] 清理无时间戳缓存: [#{project_path}][#{command}]" if ENV['PINDO_DEBUG']
417
+ puts "[PindoContext] 清理无时间戳缓存: [#{project_path}][#{command}]" if verbose?
407
418
  next
408
419
  end
409
420
 
@@ -411,7 +422,7 @@ module Pindo
411
422
  if (current_time - last_modified.to_i) > seven_days_in_seconds
412
423
  days_old = (current_time - last_modified.to_i) / (24 * 60 * 60)
413
424
  expired_commands << "[#{project_path}][#{command}] (#{days_old}天前)"
414
- puts "[PindoContext] 清理过期缓存 (#{days_old}天前): [#{project_path}][#{command}]" if ENV['PINDO_DEBUG']
425
+ puts "[PindoContext] 清理过期缓存 (#{days_old}天前): [#{project_path}][#{command}]" if verbose?
415
426
  next
416
427
  end
417
428
 
@@ -425,7 +436,7 @@ module Pindo
425
436
  else
426
437
  # 整个项目路径下的所有命令都过期了,删除整个项目路径
427
438
  expired_projects << project_path
428
- puts "[PindoContext] 删除空项目路径: #{project_path}" if ENV['PINDO_DEBUG']
439
+ puts "[PindoContext] 删除空项目路径: #{project_path}" if verbose?
429
440
  end
430
441
  end
431
442
 
@@ -434,11 +445,11 @@ module Pindo
434
445
  puts "[PindoContext] 缓存清理完成:"
435
446
  if expired_commands.any?
436
447
  puts " - 清理了 #{expired_commands.size} 个过期命令缓存"
437
- expired_commands.each { |cmd| puts " • #{cmd}" } if ENV['PINDO_DEBUG']
448
+ expired_commands.each { |cmd| puts " • #{cmd}" } if verbose?
438
449
  end
439
450
  if expired_projects.any?
440
451
  puts " - 删除了 #{expired_projects.size} 个空项目路径"
441
- expired_projects.each { |proj| puts " • #{proj}" } if ENV['PINDO_DEBUG']
452
+ expired_projects.each { |proj| puts " • #{proj}" } if verbose?
442
453
  end
443
454
 
444
455
  # 立即保存清理后的缓存到文件
data/lib/pindo/command.rb CHANGED
@@ -74,6 +74,7 @@ module Pindo
74
74
 
75
75
  DEFAULT_OPTIONS = [
76
76
  ['--help', '查看命令行用法'],
77
+ ['--verbose', '显示详细的调试信息'],
77
78
  ]
78
79
 
79
80
 
@@ -105,6 +106,10 @@ module Pindo
105
106
  def initialize(argv)
106
107
  super
107
108
  @args_help_flag = argv.flag?('help', false)
109
+ @args_verbose_flag = argv.flag?('verbose', false)
110
+
111
+ # 设置全局 verbose 标志
112
+ ENV['PINDO_VERBOSE'] = '1' if @args_verbose_flag
108
113
 
109
114
  # 在非抽象命令初始化时设置上下文
110
115
  if !self.class.abstract_command? && !@args_help_flag
@@ -126,7 +131,8 @@ module Pindo
126
131
  # 配置选项
127
132
  cache_enabled_value = self.class.respond_to?(:use_cache?) ? self.class.use_cache? : false
128
133
  options = {
129
- cache_enabled: cache_enabled_value
134
+ cache_enabled: cache_enabled_value,
135
+ verbose: @args_verbose_flag
130
136
  }
131
137
 
132
138
  # 获取项目根目录(Git仓库根目录或当前目录)
data/lib/pindo/version.rb CHANGED
@@ -6,7 +6,7 @@ require 'time'
6
6
 
7
7
  module Pindo
8
8
 
9
- VERSION = "5.4.0"
9
+ VERSION = "5.4.1"
10
10
 
11
11
  class VersionCheck
12
12
  RUBYGEMS_API = 'https://rubygems.org/api/v1/gems/pindo.json'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pindo
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.4.0
4
+ version: 5.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - wade