thor-completion 0.0.2 → 0.0.4

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: c9a09943a60c0fa1ee8dc204e7f1ce67f86683d31651ce15f284c087313c1ce2
4
- data.tar.gz: 8b82e6ded0bd726a29d701fa71ccaccadda97d76308385b5333766a83a06a66f
3
+ metadata.gz: 04d13f1834c0add34287b632d18e8e854457c28f42394e0bd44f5f70f6c132d8
4
+ data.tar.gz: a6095ce17d6b6f41c834d88ee078c7c5adadea8027cdeae51d34c51dc2aa3c25
5
5
  SHA512:
6
- metadata.gz: 3feea415e81693e107ef457275d38207e1f495de6ea439e43a889b23ec7a59ae8f94f2e8329dc77b683e2b0de5adc239ce5384e87a4a849eebabe6358eea5b1f
7
- data.tar.gz: e339618aa4c8e0a6054178a4d729fa9bcdfe3b898e104671fb3247bf96eac273d6dee2e73b00de156f95e749b810e7a9b9f8858b49d0e793e1990ad9d7725134
6
+ metadata.gz: e0d00a39ec7b612794d7d0271f102729073efc28c5b280c5556dc25188b1d6624197e429635a4dcd79c22434ad2ffd799c482e7acf37b658e423da3ee3ba6b70
7
+ data.tar.gz: 04d07083431b0c28fb4a4f000d6d8601c14a81789851d48768ad83b98358a03b066db0f38dbd3e940e822884a42a822bd5f9a3361637fbe94ab06a6b2450016e
data/CHANGELOG.md CHANGED
@@ -11,6 +11,16 @@ Prefix your message with one of the following:
11
11
  - [Security] in case of vulnerabilities.
12
12
  -->
13
13
 
14
+ ## v0.0.4
15
+
16
+ - [Fixed] Escape newlines in option descriptions for zsh completions.
17
+ - [Fixed] Properly escape single quotes in zsh completion strings.
18
+ - [Fixed] Properly normalize command names.
19
+
20
+ ## v0.0.3
21
+
22
+ - [Fixed] Map Thor's `numeric` type to schema's `float` type.
23
+
14
24
  ## v0.0.2
15
25
 
16
26
  - [Fixed] Fix completion property format to match schema (object instead of
@@ -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
 
@@ -56,6 +75,15 @@ class Thor
56
75
  end
57
76
  end
58
77
 
78
+ def self.normalize_type(thor_type)
79
+ case thor_type.to_s
80
+ when "numeric"
81
+ "float"
82
+ else
83
+ thor_type.to_s
84
+ end
85
+ end
86
+
59
87
  def self.resolve_completion(value)
60
88
  value = value.to_s
61
89
 
@@ -69,8 +97,8 @@ class Thor
69
97
  def self.build_subcommands(cli, parent)
70
98
  cli.all_commands.each_value do |command|
71
99
  subcmd_schema = {
72
- name: command.name,
73
- description: command.description || "",
100
+ name: normalize_name(command.name),
101
+ description: normalize_description(command.description),
74
102
  options: command.options.each_value.flat_map { build_option(_1) }
75
103
  }
76
104
 
@@ -102,7 +130,7 @@ class Thor
102
130
 
103
131
  values.map do |type, name|
104
132
  arg_hash = {
105
- name: name.to_s,
133
+ name: normalize_name(name),
106
134
  description: name.to_s.tr("_", " ").capitalize,
107
135
  required: type == :req,
108
136
  variadic: type == :rest
@@ -117,15 +145,14 @@ class Thor
117
145
  end
118
146
 
119
147
  def self.build_option(option)
120
- dasherize = proc { _1.to_s.tr("_", "-") }
121
- name = dasherize.call(option.name)
148
+ name = dasherize(option.name)
122
149
 
123
150
  [].tap do |list|
124
- short_opts = option.aliases.map { dasherize.call(_1.gsub(/^-+/, "")) }
151
+ short_opts = option.aliases.map { dasherize(_1.gsub(/^-+/, "")) }
125
152
  opt_hash = {
126
- name:,
127
- type: option.type.to_s,
128
- description: option.description || "",
153
+ name: normalize_name(name),
154
+ type: normalize_type(option.type),
155
+ description: normalize_description(option.description),
129
156
  required: option.required,
130
157
  repeatable: option.repeatable || false,
131
158
  default: option.default,
@@ -148,7 +175,7 @@ class Thor
148
175
  if option.type == :boolean
149
176
  list << {
150
177
  name: "no-#{name}",
151
- type: option.type.to_s,
178
+ type: normalize_type(option.type),
152
179
  description: "",
153
180
  required: false,
154
181
  repeatable: option.repeatable || false,
@@ -157,7 +184,7 @@ class Thor
157
184
 
158
185
  list << {
159
186
  name: "skip-#{name}",
160
- type: option.type.to_s,
187
+ type: normalize_type(option.type),
161
188
  description: "",
162
189
  required: false,
163
190
  repeatable: option.repeatable || false,
@@ -2,6 +2,6 @@
2
2
 
3
3
  class Thor
4
4
  module Completion
5
- VERSION = "0.0.2"
5
+ VERSION = "0.0.4"
6
6
  end
7
7
  end
@@ -293,7 +293,7 @@ class Thor
293
293
 
294
294
  private def add_completion_spec(spec, completion)
295
295
  comp_spec = format_completion(completion)
296
- spec.sub(/\]$/, "]:value:#{comp_spec}'")
296
+ spec + "]:value:#{comp_spec}'"
297
297
  end
298
298
 
299
299
  private def format_completion(completion)
@@ -324,11 +324,11 @@ class Thor
324
324
  end
325
325
 
326
326
  private def escape_description(desc)
327
- desc.to_s.gsub(/[\[\]']/, '\\\\\&')
327
+ desc.to_s.gsub("\n", " ").gsub("'", "'\\\\''" ).gsub(/[\[\]]/, '\\\\\&')
328
328
  end
329
329
 
330
330
  private def escape_value(value)
331
- value.to_s.gsub(/[\s']/, '\\\\\&')
331
+ value.to_s.gsub("'", "'\\\\''" ).gsub(/[\s]/, '\\\\\&')
332
332
  end
333
333
 
334
334
  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.2
4
+ version: 0.0.4
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.2
169
- changelog_uri: https://github.com/fnando/thor-completion/tree/v0.0.2/CHANGELOG.md
170
- documentation_uri: https://github.com/fnando/thor-completion/tree/v0.0.2/README.md
171
- license_uri: https://github.com/fnando/thor-completion/tree/v0.0.2/LICENSE.md
168
+ source_code_uri: https://github.com/fnando/thor-completion/tree/v0.0.4
169
+ changelog_uri: https://github.com/fnando/thor-completion/tree/v0.0.4/CHANGELOG.md
170
+ documentation_uri: https://github.com/fnando/thor-completion/tree/v0.0.4/README.md
171
+ license_uri: https://github.com/fnando/thor-completion/tree/v0.0.4/LICENSE.md
172
172
  rdoc_options: []
173
173
  require_paths:
174
174
  - lib