clamp 1.5.1 → 1.5.2

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: d0987845ae98be0a62e6501a780e42f4e73826df831d5d3809e17c8f8d335db2
4
- data.tar.gz: 07665f169706158283c5e3d5fa9e231d668fa7105b8f4726e46f801679173071
3
+ metadata.gz: ceef639e7f7761b30abc7be04ab5384ee2dc238ba472a12c808e2cdffc14e540
4
+ data.tar.gz: 7f97fc3d84a9fad89123fad6ed35dffeb37efc9e82815a44a6ca76ad134905ec
5
5
  SHA512:
6
- metadata.gz: 1a2b310ce3f8a1e2cd0bb100abf9a1fec7b8dc36ad639f4b2007824136dd77409d460a2305d36fba0c11999c5e8620406fef5326ab749e31505809631671ee0e
7
- data.tar.gz: 3fbc558438ae5dd809e60562a9b799c034a3bbbf620eeb77a7cec2ca0c8eb4dd35a86330214a94bde6c22a449974527dc480c9d4278774af0dacb0212a6556fe
6
+ metadata.gz: 886c0eb9476e36c0c46e07812a412108f8575799f2a1b5588d0e6ed6feac5d7d8fe25ea27a1b8c4e244e691a62a9c502f0ecdb848eb56022cf48004f353d11ed
7
+ data.tar.gz: 18cc7167ae022ea13afd50b2367e47f5a9832e67d3754c683077125d4eaa99e75efba69b736fd327173ce9b2662f16be43bdbf53eea33f17b409703579f11b03
@@ -54,7 +54,9 @@ module Clamp
54
54
  " return",
55
55
  " fi",
56
56
  "",
57
+ ' if [[ "$cur" == -* ]]; then',
57
58
  options_case("$subcmd"),
59
+ " fi",
58
60
  "",
59
61
  ' if [ "$params_remaining" -eq 0 ]; then',
60
62
  subcommands_case("$subcmd"),
@@ -17,16 +17,22 @@ module Clamp
17
17
  lines << "# Generated by Clamp"
18
18
  lines << ""
19
19
  helpers = [subcmd_args_function]
20
+
21
+ # Track visible option switches at each depth, so we can identify
22
+ # which options are new at each level. Depth-first walk order means
23
+ # the entry at depth N-1 is always the current node's parent.
24
+ switches_at_depth = []
25
+
20
26
  Completion.walk_command_tree(@command_class) do |cmd, path, has_children|
21
- child_names = has_children ? cmd.recognised_subcommands.flat_map(&:names) : []
22
- condition = condition_for(path, child_names)
23
- Completion.visible_options(cmd).each do |option|
24
- lines << option_completion(option, condition)
25
- end
27
+ generate_option_completions(lines, cmd, path, switches_at_depth)
28
+
26
29
  next unless has_children
27
30
 
28
- subcmd_condition = subcommand_condition(cmd, path, condition, helpers)
29
- generate_subcommand_completions(lines, cmd, subcmd_condition)
31
+ # Subcommand names need an exclusive condition (only at this level).
32
+ child_names = cmd.recognised_subcommands.flat_map(&:names)
33
+ exclusive_cond = condition_for(path, child_names)
34
+ subcmd_cond = subcommand_condition(cmd, path, exclusive_cond, helpers)
35
+ generate_subcommand_completions(lines, cmd, subcmd_cond)
30
36
  lines << ""
31
37
  end
32
38
  "#{helpers.join("\n\n")}\n\n#{lines.join("\n")}\n"
@@ -52,6 +58,30 @@ module Clamp
52
58
  end
53
59
  end
54
60
 
61
+ # Emit only options new at this level (not inherited from parent).
62
+ # Use an inclusive condition so they also apply to child subcommands.
63
+ def generate_option_completions(lines, cmd, path, switches_at_depth)
64
+ depth = path.length
65
+ visible = Completion.visible_options(cmd)
66
+ parent_switches = depth.positive? ? switches_at_depth[depth - 1] : nil
67
+ new_options = if parent_switches
68
+ visible.reject { |o| parent_switches.include?(o.switches) }
69
+ else
70
+ visible
71
+ end
72
+ option_cond = depth.positive? ? inclusive_condition_for(path) : nil
73
+ new_options.each do |option|
74
+ lines << option_completion(option, option_cond)
75
+ end
76
+ switches_at_depth[depth] = Set.new(visible.map(&:switches))
77
+ end
78
+
79
+ # Condition that matches this level AND all child subcommands.
80
+ def inclusive_condition_for(path)
81
+ path.map { |sub| "#{completion_function}_seen_subcommand_from #{sub.names.join(' ')}" }.join("; and ")
82
+ end
83
+
84
+ # Condition that matches this level only (excludes child subcommands).
55
85
  def condition_for(path, child_names)
56
86
  if path.empty?
57
87
  "not #{completion_function}_subcmd_args >/dev/null"
@@ -96,9 +126,9 @@ module Clamp
96
126
  end
97
127
  end
98
128
 
99
- def option_completion(option, condition)
129
+ def option_completion(option, condition = nil)
100
130
  parts = ["complete -c #{@executable_name} -f"]
101
- parts << "-n '#{condition}'"
131
+ parts << "-n '#{condition}'" if condition
102
132
 
103
133
  Completion.expanded_switches(option).each do |switch|
104
134
  parts << if switch.start_with?("--")
data/lib/clamp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Clamp
4
- VERSION = "1.5.1"
4
+ VERSION = "1.5.2"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.1
4
+ version: 1.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams