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 +4 -4
- data/lib/clamp/completion/bash_generator.rb +2 -0
- data/lib/clamp/completion/fish_generator.rb +39 -9
- data/lib/clamp/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: ceef639e7f7761b30abc7be04ab5384ee2dc238ba472a12c808e2cdffc14e540
|
|
4
|
+
data.tar.gz: 7f97fc3d84a9fad89123fad6ed35dffeb37efc9e82815a44a6ca76ad134905ec
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 886c0eb9476e36c0c46e07812a412108f8575799f2a1b5588d0e6ed6feac5d7d8fe25ea27a1b8c4e244e691a62a9c502f0ecdb848eb56022cf48004f353d11ed
|
|
7
|
+
data.tar.gz: 18cc7167ae022ea13afd50b2367e47f5a9832e67d3754c683077125d4eaa99e75efba69b736fd327173ce9b2662f16be43bdbf53eea33f17b409703579f11b03
|
|
@@ -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
|
-
|
|
22
|
-
|
|
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
|
-
|
|
29
|
-
|
|
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