dry-cli 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -0
- data/lib/dry/cli/command_registry.rb +13 -1
- data/lib/dry/cli/registry.rb +7 -7
- data/lib/dry/cli/spell_checker.rb +38 -0
- data/lib/dry/cli/usage.rb +3 -1
- data/lib/dry/cli/version.rb +1 -1
- data/lib/dry/cli.rb +7 -4
- metadata +6 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 816b3ffdbf5a84ad4ce91ff6be0bba9424141a7b28b880accb087ba65b63e36d
|
4
|
+
data.tar.gz: 6ca3a54ff35dcb634acf68ff6472ddc8737cc15f99d6f7f860ac89e491759cd4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e1b289e4571b3b658ff402f1c8dd2fa8c7746fc3a17293f2a3316961622adc1570c76b82dfbcf4c74c6510f1994952928d64eb56e99284acfae797f6adeb8037
|
7
|
+
data.tar.gz: 4739d57ca298e1c85afcd5d0c499a56ca04db8e802d4c84be905a674e884599d4b2dbedca66927d9ed9a0467a5b1468c063bd57b25109c6a7e1c69068b113b59
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.2.0 2024-10-15
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- Added `:hidden` option to register commands that should not be shown in the help output. (@benoittgt in #137)
|
9
|
+
- Provide suggestions when there is a typo in a command name. (@benoittgt in #138)
|
10
|
+
|
11
|
+
|
12
|
+
[Compare v1.1.0...v1.2.0](https://github.com/dry-rb/dry-cli/compare/v1.1.0...v1.2.0)
|
13
|
+
|
3
14
|
## 1.1.0 2024-07-14
|
4
15
|
|
5
16
|
|
@@ -18,7 +18,7 @@ module Dry
|
|
18
18
|
|
19
19
|
# @since 0.1.0
|
20
20
|
# @api private
|
21
|
-
def set(name, command, aliases)
|
21
|
+
def set(name, command, aliases, hidden)
|
22
22
|
@_mutex.synchronize do
|
23
23
|
node = @root
|
24
24
|
name.split(/[[:space:]]/).each do |token|
|
@@ -26,6 +26,7 @@ module Dry
|
|
26
26
|
end
|
27
27
|
|
28
28
|
node.aliases!(aliases)
|
29
|
+
node.hidden!(hidden)
|
29
30
|
if command
|
30
31
|
node.leaf!(command)
|
31
32
|
node.subcommands!(command)
|
@@ -91,6 +92,10 @@ module Dry
|
|
91
92
|
# @api private
|
92
93
|
attr_reader :aliases
|
93
94
|
|
95
|
+
# @since 1.1.1
|
96
|
+
# @api private
|
97
|
+
attr_reader :hidden
|
98
|
+
|
94
99
|
# @since 0.1.0
|
95
100
|
# @api private
|
96
101
|
attr_reader :command
|
@@ -109,6 +114,7 @@ module Dry
|
|
109
114
|
@parent = parent
|
110
115
|
@children = {}
|
111
116
|
@aliases = {}
|
117
|
+
@hidden = hidden
|
112
118
|
@command = nil
|
113
119
|
|
114
120
|
@before_callbacks = Chain.new
|
@@ -154,6 +160,12 @@ module Dry
|
|
154
160
|
end
|
155
161
|
end
|
156
162
|
|
163
|
+
# @since 1.1.1
|
164
|
+
# @api private
|
165
|
+
def hidden!(hidden)
|
166
|
+
@hidden = hidden
|
167
|
+
end
|
168
|
+
|
157
169
|
# @since 0.1.0
|
158
170
|
# @api private
|
159
171
|
def leaf?
|
data/lib/dry/cli/registry.rb
CHANGED
@@ -75,11 +75,11 @@ module Dry
|
|
75
75
|
# end
|
76
76
|
# end
|
77
77
|
# end
|
78
|
-
def register(name, command = nil, aliases: [], &block)
|
79
|
-
@commands.set(name, command, aliases)
|
78
|
+
def register(name, command = nil, aliases: [], hidden: false, &block)
|
79
|
+
@commands.set(name, command, aliases, hidden)
|
80
80
|
|
81
81
|
if block_given?
|
82
|
-
prefix = Prefix.new(@commands, name, aliases)
|
82
|
+
prefix = Prefix.new(@commands, name, aliases, hidden)
|
83
83
|
if block.arity.zero?
|
84
84
|
prefix.instance_eval(&block)
|
85
85
|
else
|
@@ -308,19 +308,19 @@ module Dry
|
|
308
308
|
class Prefix
|
309
309
|
# @since 0.1.0
|
310
310
|
# @api private
|
311
|
-
def initialize(registry, prefix, aliases)
|
311
|
+
def initialize(registry, prefix, aliases, hidden)
|
312
312
|
@registry = registry
|
313
313
|
@prefix = prefix
|
314
314
|
|
315
|
-
registry.set(prefix, nil, aliases)
|
315
|
+
registry.set(prefix, nil, aliases, hidden)
|
316
316
|
end
|
317
317
|
|
318
318
|
# @since 0.1.0
|
319
319
|
#
|
320
320
|
# @see Dry::CLI::Registry#register
|
321
|
-
def register(name, command, aliases: [])
|
321
|
+
def register(name, command, aliases: [], hidden: false)
|
322
322
|
command_name = "#{prefix} #{name}"
|
323
|
-
registry.set(command_name, command, aliases)
|
323
|
+
registry.set(command_name, command, aliases, hidden)
|
324
324
|
end
|
325
325
|
|
326
326
|
private
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/cli/program_name"
|
4
|
+
require "did_you_mean"
|
5
|
+
|
6
|
+
module Dry
|
7
|
+
class CLI
|
8
|
+
# Command(s) usage
|
9
|
+
#
|
10
|
+
# @since 1.1.1
|
11
|
+
# @api private
|
12
|
+
module SpellChecker
|
13
|
+
# @since 1.1.1
|
14
|
+
# @api private
|
15
|
+
def self.call(result, arguments)
|
16
|
+
commands = result.children.keys
|
17
|
+
cmd = cmd_to_spell(arguments, result.names)
|
18
|
+
|
19
|
+
suggestions = DidYouMean::SpellChecker.new(dictionary: commands).correct(cmd.first)
|
20
|
+
if suggestions.any?
|
21
|
+
"I don't know how to '#{cmd.join(" ")}'. Did you mean: '#{suggestions.first}' ?"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# @since 1.1.1
|
26
|
+
# @api private
|
27
|
+
def self.cmd_to_spell(arguments, result_names)
|
28
|
+
arguments - result_names
|
29
|
+
end
|
30
|
+
|
31
|
+
# @since 1.1.1
|
32
|
+
# @api private
|
33
|
+
def self.ignore?(cmd)
|
34
|
+
cmd.empty? || cmd.first.start_with?("-")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/dry/cli/usage.rb
CHANGED
@@ -21,9 +21,11 @@ module Dry
|
|
21
21
|
max_length, commands = commands_and_arguments(result)
|
22
22
|
|
23
23
|
commands.map do |banner, node|
|
24
|
+
next if node.hidden
|
25
|
+
|
24
26
|
usage = description(node.command) if node.leaf?
|
25
27
|
"#{justify(banner, max_length, usage)}#{usage}"
|
26
|
-
end.unshift(header).join("\n")
|
28
|
+
end.compact.unshift(header).join("\n")
|
27
29
|
end
|
28
30
|
|
29
31
|
# @since 0.1.0
|
data/lib/dry/cli/version.rb
CHANGED
data/lib/dry/cli.rb
CHANGED
@@ -14,6 +14,7 @@ module Dry
|
|
14
14
|
require "dry/cli/registry"
|
15
15
|
require "dry/cli/parser"
|
16
16
|
require "dry/cli/usage"
|
17
|
+
require "dry/cli/spell_checker"
|
17
18
|
require "dry/cli/banner"
|
18
19
|
require "dry/cli/inflector"
|
19
20
|
|
@@ -108,7 +109,7 @@ module Dry
|
|
108
109
|
# @api private
|
109
110
|
def perform_registry(arguments)
|
110
111
|
result = registry.get(arguments)
|
111
|
-
return
|
112
|
+
return spell_checker(result, arguments) unless result.found?
|
112
113
|
|
113
114
|
command, args = parse(result.command, result.arguments, result.names)
|
114
115
|
|
@@ -161,9 +162,11 @@ module Dry
|
|
161
162
|
exit(1)
|
162
163
|
end
|
163
164
|
|
164
|
-
# @since
|
165
|
-
|
166
|
-
|
165
|
+
# @since 1.1.1
|
166
|
+
def spell_checker(result, arguments)
|
167
|
+
spell_checker = SpellChecker.call(result, arguments)
|
168
|
+
err.puts spell_checker if spell_checker
|
169
|
+
puts
|
167
170
|
err.puts Usage.call(result)
|
168
171
|
exit(1)
|
169
172
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -108,6 +108,7 @@ files:
|
|
108
108
|
- lib/dry/cli/parser.rb
|
109
109
|
- lib/dry/cli/program_name.rb
|
110
110
|
- lib/dry/cli/registry.rb
|
111
|
+
- lib/dry/cli/spell_checker.rb
|
111
112
|
- lib/dry/cli/usage.rb
|
112
113
|
- lib/dry/cli/version.rb
|
113
114
|
homepage: https://dry-rb.org/gems/dry-cli
|
@@ -118,7 +119,7 @@ metadata:
|
|
118
119
|
changelog_uri: https://github.com/dry-rb/dry-cli/blob/main/CHANGELOG.md
|
119
120
|
source_code_uri: https://github.com/dry-rb/dry-cli
|
120
121
|
bug_tracker_uri: https://github.com/dry-rb/dry-cli/issues
|
121
|
-
post_install_message:
|
122
|
+
post_install_message:
|
122
123
|
rdoc_options: []
|
123
124
|
require_paths:
|
124
125
|
- lib
|
@@ -134,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
135
|
version: '0'
|
135
136
|
requirements: []
|
136
137
|
rubygems_version: 3.3.27
|
137
|
-
signing_key:
|
138
|
+
signing_key:
|
138
139
|
specification_version: 4
|
139
140
|
summary: Common framework to build command line interfaces with Ruby
|
140
141
|
test_files: []
|