dry-cli 1.0.0 → 1.1.0
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/CHANGELOG.md +10 -0
- data/LICENSE +1 -1
- data/README.md +3 -11
- data/dry-cli.gemspec +1 -1
- data/lib/dry/cli/banner.rb +5 -3
- data/lib/dry/cli/command.rb +1 -5
- data/lib/dry/cli/command_registry.rb +3 -2
- data/lib/dry/cli/option.rb +8 -1
- data/lib/dry/cli/parser.rb +7 -7
- data/lib/dry/cli/usage.rb +2 -2
- data/lib/dry/cli/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3bb38a55577b2607724ceaafe32979ca39b83b62ece8d5e734f522646042d2f5
|
4
|
+
data.tar.gz: 05e3fe644ca5fceb2bd3dc740453faf8aab28faaf7ad5ae9ab39a23474f7f611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97ff398081901a642d1d8d898a50eec46e33103defff2e4c77f11a0e5150dcb79fc7e568cbeaaeaa7e6af9f0e05835b265a2ceb7fda144f4983b8dfc27363728
|
7
|
+
data.tar.gz: 39b43443b842724a7096a909bba93dd93ceda1c470a2cfc2ec9ac9e02f2aee0b449f2dd6c2b7bf9c0c92485ad404a14ba1a352518d5070366535bbc19d5cb789
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,15 @@
|
|
1
1
|
<!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
|
2
2
|
|
3
|
+
## 1.1.0 2024-07-14
|
4
|
+
|
5
|
+
|
6
|
+
### Added
|
7
|
+
|
8
|
+
- Added `:flag` option type. This acts like a `:boolean` that can only be set to true, so has no `--no-` prefix to disable it. (@Billiam in #117)
|
9
|
+
|
10
|
+
|
11
|
+
[Compare v1.0.0...v1.1.0](https://github.com/dry-rb/dry-cli/compare/v1.0.0...v1.1.0)
|
12
|
+
|
3
13
|
## 1.0.0 2022-11-05
|
4
14
|
|
5
15
|
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,29 +1,21 @@
|
|
1
1
|
<!--- this file is synced from dry-rb/template-gem project -->
|
2
2
|
[gem]: https://rubygems.org/gems/dry-cli
|
3
3
|
[actions]: https://github.com/dry-rb/dry-cli/actions
|
4
|
-
[codacy]: https://www.codacy.com/gh/dry-rb/dry-cli
|
5
|
-
[chat]: https://dry-rb.zulipchat.com
|
6
|
-
[inchpages]: http://inch-ci.org/github/dry-rb/dry-cli
|
7
4
|
|
8
|
-
# dry-cli [][gem]
|
11
|
-
[][actions]
|
12
|
-
[][codacy]
|
13
|
-
[][codacy]
|
14
|
-
[][inchpages]
|
5
|
+
# dry-cli [][gem] [][actions]
|
15
6
|
|
16
7
|
## Links
|
17
8
|
|
18
9
|
* [User documentation](https://dry-rb.org/gems/dry-cli)
|
19
10
|
* [API documentation](http://rubydoc.info/gems/dry-cli)
|
11
|
+
* [Forum](https://discourse.dry-rb.org)
|
20
12
|
|
21
13
|
## Supported Ruby versions
|
22
14
|
|
23
15
|
This library officially supports the following Ruby versions:
|
24
16
|
|
25
17
|
* MRI `>= 2.4.0`
|
26
|
-
* jruby `>= 9.
|
18
|
+
* jruby `>= 9.4` (not tested on CI)
|
27
19
|
|
28
20
|
## License
|
29
21
|
|
data/dry-cli.gemspec
CHANGED
@@ -26,7 +26,7 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-cli"
|
27
27
|
spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-cli/issues"
|
28
28
|
|
29
|
-
spec.required_ruby_version = ">= 2.
|
29
|
+
spec.required_ruby_version = ">= 2.4.0"
|
30
30
|
|
31
31
|
# to update dependencies edit project.yml
|
32
32
|
|
data/lib/dry/cli/banner.rb
CHANGED
@@ -86,8 +86,8 @@ module Dry
|
|
86
86
|
required_arguments = command.required_arguments
|
87
87
|
optional_arguments = command.optional_arguments
|
88
88
|
|
89
|
-
required = required_arguments.map { |arg| arg.name.upcase }.join(" ") if required_arguments.any? # rubocop:disable
|
90
|
-
optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable
|
89
|
+
required = required_arguments.map { |arg| arg.name.upcase }.join(" ") if required_arguments.any? # rubocop:disable Layout/LineLength
|
90
|
+
optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable Layout/LineLength
|
91
91
|
result = [required, optional].compact
|
92
92
|
|
93
93
|
" #{result.join(" ")}" unless result.empty?
|
@@ -97,7 +97,7 @@ module Dry
|
|
97
97
|
# @api private
|
98
98
|
def self.extended_command_arguments(command)
|
99
99
|
command.arguments.map do |argument|
|
100
|
-
" #{argument.name.to_s.upcase.ljust(32)} # #{"REQUIRED " if argument.required?}#{argument.desc}" # rubocop:disable
|
100
|
+
" #{argument.name.to_s.upcase.ljust(32)} # #{"REQUIRED " if argument.required?}#{argument.desc}" # rubocop:disable Layout/LineLength
|
101
101
|
end.join("\n")
|
102
102
|
end
|
103
103
|
|
@@ -109,6 +109,8 @@ module Dry
|
|
109
109
|
name = Inflector.dasherize(option.name)
|
110
110
|
name = if option.boolean?
|
111
111
|
"[no-]#{name}"
|
112
|
+
elsif option.flag?
|
113
|
+
name
|
112
114
|
elsif option.array?
|
113
115
|
"#{name}=VALUE1,VALUE2,.."
|
114
116
|
else
|
data/lib/dry/cli/command.rb
CHANGED
@@ -37,7 +37,7 @@ module Dry
|
|
37
37
|
|
38
38
|
# @since 0.1.0
|
39
39
|
# @api private
|
40
|
-
#
|
40
|
+
# rubocop:disable Metrics/AbcSize
|
41
41
|
def get(arguments)
|
42
42
|
@_mutex.synchronize do
|
43
43
|
node = @root
|
@@ -56,7 +56,7 @@ module Dry
|
|
56
56
|
result = LookupResult.new(node, args, names, false)
|
57
57
|
break
|
58
58
|
elsif tmp.leaf?
|
59
|
-
args = arguments[i + 1
|
59
|
+
args = arguments[i + 1..]
|
60
60
|
names = arguments[0..i]
|
61
61
|
node = tmp
|
62
62
|
result = LookupResult.new(node, args, names, true)
|
@@ -72,6 +72,7 @@ module Dry
|
|
72
72
|
result
|
73
73
|
end
|
74
74
|
end
|
75
|
+
# rubocop:enable Metrics/AbcSize
|
75
76
|
|
76
77
|
# Node of the registry
|
77
78
|
#
|
data/lib/dry/cli/option.rb
CHANGED
@@ -59,6 +59,11 @@ module Dry
|
|
59
59
|
type == :boolean
|
60
60
|
end
|
61
61
|
|
62
|
+
# @api private
|
63
|
+
def flag?
|
64
|
+
type == :flag
|
65
|
+
end
|
66
|
+
|
62
67
|
# @since 0.3.0
|
63
68
|
# @api private
|
64
69
|
def array?
|
@@ -92,6 +97,8 @@ module Dry
|
|
92
97
|
|
93
98
|
if boolean?
|
94
99
|
parser_options << "--[no-]#{dasherized_name}"
|
100
|
+
elsif flag?
|
101
|
+
parser_options << "--#{dasherized_name}"
|
95
102
|
else
|
96
103
|
parser_options << "--#{dasherized_name}=#{name}"
|
97
104
|
parser_options << "--#{dasherized_name} #{name}"
|
@@ -112,7 +119,7 @@ module Dry
|
|
112
119
|
.compact
|
113
120
|
.uniq
|
114
121
|
.map { |name| name.size == 1 ? "-#{name}" : "--#{name}" }
|
115
|
-
.map { |name| boolean? ? name : "#{name} VALUE" }
|
122
|
+
.map { |name| boolean? || flag? ? name : "#{name} VALUE" }
|
116
123
|
end
|
117
124
|
end
|
118
125
|
|
data/lib/dry/cli/parser.rb
CHANGED
@@ -32,24 +32,24 @@ module Dry
|
|
32
32
|
parsed_options = command.default_params.merge(parsed_options)
|
33
33
|
parse_required_params(command, arguments, prog_name, parsed_options)
|
34
34
|
rescue ::OptionParser::ParseError
|
35
|
-
Result.failure("ERROR: \"#{prog_name}\" was called with arguments \"#{original_arguments.join(" ")}\"") # rubocop:disable
|
35
|
+
Result.failure("ERROR: \"#{prog_name}\" was called with arguments \"#{original_arguments.join(" ")}\"") # rubocop:disable Layout/LineLength
|
36
36
|
end
|
37
37
|
|
38
38
|
# @since 0.1.0
|
39
39
|
# @api private
|
40
40
|
#
|
41
|
-
# rubocop:disable Metrics/AbcSize
|
41
|
+
# rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
|
42
42
|
def self.parse_required_params(command, arguments, prog_name, parsed_options)
|
43
43
|
parsed_params = match_arguments(command.arguments, arguments)
|
44
44
|
parsed_required_params = match_arguments(command.required_arguments, arguments)
|
45
|
-
all_required_params_satisfied = command.required_arguments.all? { |param| !parsed_required_params[param.name].nil? } # rubocop:disable
|
45
|
+
all_required_params_satisfied = command.required_arguments.all? { |param| !parsed_required_params[param.name].nil? } # rubocop:disable Layout/LineLength
|
46
46
|
|
47
47
|
unused_arguments = arguments.drop(command.required_arguments.length)
|
48
48
|
|
49
49
|
unless all_required_params_satisfied
|
50
50
|
parsed_required_params_values = parsed_required_params.values.compact
|
51
51
|
|
52
|
-
usage = "\nUsage: \"#{prog_name} #{command.required_arguments.map(&:description_name).join(" ")}" # rubocop:disable
|
52
|
+
usage = "\nUsage: \"#{prog_name} #{command.required_arguments.map(&:description_name).join(" ")}" # rubocop:disable Layout/LineLength
|
53
53
|
|
54
54
|
usage += " | #{prog_name} SUBCOMMAND" if command.subcommands.any?
|
55
55
|
|
@@ -58,7 +58,7 @@ module Dry
|
|
58
58
|
if parsed_required_params_values.empty?
|
59
59
|
return Result.failure("ERROR: \"#{prog_name}\" was called with no arguments#{usage}")
|
60
60
|
else
|
61
|
-
return Result.failure("ERROR: \"#{prog_name}\" was called with arguments #{parsed_required_params_values}#{usage}") # rubocop:disable
|
61
|
+
return Result.failure("ERROR: \"#{prog_name}\" was called with arguments #{parsed_required_params_values}#{usage}") # rubocop:disable Layout/LineLength
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -67,14 +67,14 @@ module Dry
|
|
67
67
|
parsed_options = parsed_options.merge(args: unused_arguments) if unused_arguments.any?
|
68
68
|
Result.success(parsed_options)
|
69
69
|
end
|
70
|
-
# rubocop:enable Metrics/AbcSize
|
70
|
+
# rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
|
71
71
|
|
72
72
|
def self.match_arguments(command_arguments, arguments)
|
73
73
|
result = {}
|
74
74
|
|
75
75
|
command_arguments.each_with_index do |cmd_arg, index|
|
76
76
|
if cmd_arg.array?
|
77
|
-
result[cmd_arg.name] = arguments[index
|
77
|
+
result[cmd_arg.name] = arguments[index..]
|
78
78
|
break
|
79
79
|
else
|
80
80
|
result[cmd_arg.name] = arguments.at(index)
|
data/lib/dry/cli/usage.rb
CHANGED
@@ -55,8 +55,8 @@ module Dry
|
|
55
55
|
required_arguments = command.required_arguments
|
56
56
|
optional_arguments = command.optional_arguments
|
57
57
|
|
58
|
-
required = required_arguments.map { |arg| arg.name.upcase }.join(" ") if required_arguments.any? # rubocop:disable
|
59
|
-
optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable
|
58
|
+
required = required_arguments.map { |arg| arg.name.upcase }.join(" ") if required_arguments.any? # rubocop:disable Layout/LineLength
|
59
|
+
optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable Layout/LineLength
|
60
60
|
result = [required, optional].compact
|
61
61
|
|
62
62
|
" #{result.join(" ")}" unless result.empty?
|
data/lib/dry/cli/version.rb
CHANGED
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.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -126,14 +126,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
126
126
|
requirements:
|
127
127
|
- - ">="
|
128
128
|
- !ruby/object:Gem::Version
|
129
|
-
version: 2.
|
129
|
+
version: 2.4.0
|
130
130
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
131
131
|
requirements:
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
134
|
version: '0'
|
135
135
|
requirements: []
|
136
|
-
rubygems_version: 3.
|
136
|
+
rubygems_version: 3.3.27
|
137
137
|
signing_key:
|
138
138
|
specification_version: 4
|
139
139
|
summary: Common framework to build command line interfaces with Ruby
|