thor-completion 0.0.3 → 0.0.5

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: 691cb833f0cc214e326a1b186f6c884cab5abe6102dc4357f1eee7cd6f82ed1e
4
- data.tar.gz: fb8a29b2ceb7ae67e907d3e63e02717acfa6e44ab68a229ed85bc6c1f91db3a5
3
+ metadata.gz: c49505c007d48270ffb369298b6f8b11917200030e3d00e96cb6582555fc76a5
4
+ data.tar.gz: f85beb78adb7934319054ef69f10092df9c9a610bf7a406b977d6d0be873253d
5
5
  SHA512:
6
- metadata.gz: bd116f5e939b154e1dce77cd86bb02ccf07f832c5591d6ba782aa3b8b0aa9d0fdf459fd9e6eddb0ecf500ccaf0fb911579a40b7f435996a9b417d42bfb63f4f5
7
- data.tar.gz: 19120d0dba101995ae46132e91e45eea1c674ef47b27d4ca86c022c5bff6a6569b2c3dd7028db693840dcb74d8a6f5dbdc1f4260baff13cb88be33ebe42b026d
6
+ metadata.gz: 6545bcb815d53e9bc37cf24def563862462ab497bb0132eb251a46ae7e351872e1b6e2c296aedc0be93396d79f2d2f6215a6c3e7e5a263dcf56da9efd15badd6
7
+ data.tar.gz: ebc1fa9a160ef976a92ce3e58380c1d7da84f8d163a53451394e4bb59807e379ba14b15f68f726291aaf6b24ba4e403e7521add28e05051a4ce2442120473011
data/CHANGELOG.md CHANGED
@@ -11,6 +11,18 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## v0.0.5
15
+
16
+ - [Fixed] Remove position number from variadic arguments in zsh completions.
17
+ - [Fixed] Prioritize subcommand state handling over arguments for commands with
18
+ subcommands.
19
+
20
+ ## v0.0.4
21
+
22
+ - [Fixed] Escape newlines in option descriptions for zsh completions.
23
+ - [Fixed] Properly escape single quotes in zsh completion strings.
24
+ - [Fixed] Properly normalize command names.
25
+
14
26
  ## v0.0.3
15
27
 
16
28
  - [Fixed] Map Thor's `numeric` type to schema's `float` type.
@@ -7,8 +7,8 @@ class Thor
7
7
 
8
8
  def self.call(name:, description:, version:, cli:)
9
9
  schema = {
10
- name:,
11
- description:,
10
+ name: normalize_name(name),
11
+ description: normalize_description(description),
12
12
  version:,
13
13
  commands: [],
14
14
  subcommands: [],
@@ -24,6 +24,25 @@ class Thor
24
24
  schema
25
25
  end
26
26
 
27
+ def self.dasherize(text) = text.to_s.tr("_", "-")
28
+
29
+ def self.normalize_description(description)
30
+ description.to_s.gsub(/(\r?\n)+/, " ")
31
+ end
32
+
33
+ def self.normalize_name(name)
34
+ case name
35
+ when "_run"
36
+ # Thor reserves the name `run` for its internal use.
37
+ # I've done ARGV manipulation to replace `run` with `_run` so that
38
+ # users can still use `run` as a command name. Let's assume this
39
+ # is the case and rename it back to `run`.
40
+ "run"
41
+ else
42
+ dasherize(name)
43
+ end
44
+ end
45
+
27
46
  def self.build_command(cli, parent)
28
47
  cli.options.each_value do |option|
29
48
  parent[:options] += build_option(option)
@@ -31,8 +50,8 @@ class Thor
31
50
 
32
51
  cli.all_commands.each_value do |command|
33
52
  cmd_schema = {
34
- name: command.name,
35
- description: command.description || "",
53
+ name: normalize_name(command.name),
54
+ description: normalize_description(command.description),
36
55
  options: command.options.each_value.flat_map { build_option(_1) }
37
56
  }
38
57
 
@@ -78,8 +97,8 @@ class Thor
78
97
  def self.build_subcommands(cli, parent)
79
98
  cli.all_commands.each_value do |command|
80
99
  subcmd_schema = {
81
- name: command.name,
82
- description: command.description || "",
100
+ name: normalize_name(command.name),
101
+ description: normalize_description(command.description),
83
102
  options: command.options.each_value.flat_map { build_option(_1) }
84
103
  }
85
104
 
@@ -111,7 +130,7 @@ class Thor
111
130
 
112
131
  values.map do |type, name|
113
132
  arg_hash = {
114
- name: name.to_s,
133
+ name: normalize_name(name),
115
134
  description: name.to_s.tr("_", " ").capitalize,
116
135
  required: type == :req,
117
136
  variadic: type == :rest
@@ -126,15 +145,14 @@ class Thor
126
145
  end
127
146
 
128
147
  def self.build_option(option)
129
- dasherize = proc { _1.to_s.tr("_", "-") }
130
- name = dasherize.call(option.name)
148
+ name = dasherize(option.name)
131
149
 
132
150
  [].tap do |list|
133
- short_opts = option.aliases.map { dasherize.call(_1.gsub(/^-+/, "")) }
151
+ short_opts = option.aliases.map { dasherize(_1.gsub(/^-+/, "")) }
134
152
  opt_hash = {
135
- name:,
153
+ name: normalize_name(name),
136
154
  type: normalize_type(option.type),
137
- description: option.description || "",
155
+ description: normalize_description(option.description),
138
156
  required: option.required,
139
157
  repeatable: option.repeatable || false,
140
158
  default: option.default,
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Thor
4
4
  module Completion
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.5"
6
6
  end
7
7
  end
@@ -152,7 +152,7 @@ class Thor
152
152
  end
153
153
 
154
154
  # Add positional arguments
155
- if cmd[:arguments]&.any?
155
+ if cmd[:arguments]&.any? && !cmd[:subcommands]&.any?
156
156
  cmd[:arguments].each_with_index do |arg, idx|
157
157
  args << format_argument(arg, idx + 1)
158
158
  end
@@ -280,20 +280,21 @@ class Thor
280
280
  arg_name = arg[:name]
281
281
  arg_desc = arg[:description] || arg_name
282
282
  variadic = arg[:variadic] ? "*" : ""
283
+ pos = variadic.empty? ? position.to_s : ""
283
284
 
284
285
  if arg[:completion]
285
286
  completion = format_completion(arg[:completion])
286
- "'#{variadic}#{position}:#{arg_desc}:#{completion}'"
287
+ "'#{variadic}#{pos}:#{arg_desc}:#{completion}'"
287
288
  elsif arg[:required] == false
288
- "'#{variadic}#{position}::#{arg_desc}:_files'"
289
+ "'#{variadic}#{pos}::#{arg_desc}:_files'"
289
290
  else
290
- "'#{variadic}#{position}:#{arg_desc}:_files'"
291
+ "'#{variadic}#{pos}:#{arg_desc}:_files'"
291
292
  end
292
293
  end
293
294
 
294
295
  private def add_completion_spec(spec, completion)
295
296
  comp_spec = format_completion(completion)
296
- spec.sub(/\]$/, "]:value:#{comp_spec}'")
297
+ spec + "]:value:#{comp_spec}'"
297
298
  end
298
299
 
299
300
  private def format_completion(completion)
@@ -324,11 +325,11 @@ class Thor
324
325
  end
325
326
 
326
327
  private def escape_description(desc)
327
- desc.to_s.gsub(/[\[\]']/, '\\\\\&')
328
+ desc.to_s.gsub("\n", " ").gsub("'", "'\\\\''" ).gsub(/[\[\]]/, '\\\\\&')
328
329
  end
329
330
 
330
331
  private def escape_value(value)
331
- value.to_s.gsub(/[\s']/, '\\\\\&')
332
+ value.to_s.gsub("'", "'\\\\''" ).gsub(/[\s]/, '\\\\\&')
332
333
  end
333
334
 
334
335
  private def quote(str)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: thor-completion
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
@@ -165,10 +165,10 @@ metadata:
165
165
  rubygems_mfa_required: 'true'
166
166
  homepage_uri: https://github.com/fnando/thor-completion
167
167
  bug_tracker_uri: https://github.com/fnando/thor-completion/issues
168
- source_code_uri: https://github.com/fnando/thor-completion/tree/v0.0.3
169
- changelog_uri: https://github.com/fnando/thor-completion/tree/v0.0.3/CHANGELOG.md
170
- documentation_uri: https://github.com/fnando/thor-completion/tree/v0.0.3/README.md
171
- license_uri: https://github.com/fnando/thor-completion/tree/v0.0.3/LICENSE.md
168
+ source_code_uri: https://github.com/fnando/thor-completion/tree/v0.0.5
169
+ changelog_uri: https://github.com/fnando/thor-completion/tree/v0.0.5/CHANGELOG.md
170
+ documentation_uri: https://github.com/fnando/thor-completion/tree/v0.0.5/README.md
171
+ license_uri: https://github.com/fnando/thor-completion/tree/v0.0.5/LICENSE.md
172
172
  rdoc_options: []
173
173
  require_paths:
174
174
  - lib