dry-cli 0.5.0 → 0.5.1
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 +110 -21
- data/LICENSE +1 -1
- data/README.md +10 -12
- data/dry-cli.gemspec +21 -21
- data/lib/dry/cli.rb +39 -5
- data/lib/dry/cli/banner.rb +14 -16
- data/lib/dry/cli/command.rb +0 -10
- data/lib/dry/cli/command_registry.rb +3 -14
- data/lib/dry/cli/inflector.rb +1 -1
- data/lib/dry/cli/option.rb +8 -7
- data/lib/dry/cli/parser.rb +1 -1
- data/lib/dry/cli/registry.rb +10 -5
- data/lib/dry/cli/version.rb +1 -1
- metadata +9 -25
- data/.codeclimate.yml +0 -12
- data/.github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md +0 -10
- data/.github/ISSUE_TEMPLATE/---bug-report.md +0 -30
- data/.github/ISSUE_TEMPLATE/---feature-request.md +0 -18
- data/.github/workflows/custom_ci.yml +0 -77
- data/.github/workflows/docsite.yml +0 -34
- data/.github/workflows/sync_configs.yml +0 -34
- data/.gitignore +0 -11
- data/.rspec +0 -4
- data/.rubocop.yml +0 -95
- data/CODE_OF_CONDUCT.md +0 -13
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -14
- data/Rakefile +0 -16
- data/bin/console +0 -15
- data/bin/setup +0 -8
- data/docsite/source/index.html.md +0 -588
- data/script/ci +0 -51
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0976875bf08ad159133d9c103dccf46df45551875fe368d24aca74bc11263b6e'
|
4
|
+
data.tar.gz: 68d06b56349cc86c74812b1226d221cf11ad97c132ab836ea2161add4e8867d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9577fd903c55e544fe062aac19cf9226d3474a298299a8f30ce2ed58be60a9833e6b7d7ca56acfc33ec31b9899275a6ccaafa4aa732187987d0a72f3df0ab6f6
|
7
|
+
data.tar.gz: e3842ccf475c1a82fb53fb71dfa9deb96a28d23ca20ff25860f49a3db07fcaf1f2d0cd5cd0454afb41ca3b924475f190c091c1bc8e4182eb9981a24449f425ed
|
data/CHANGELOG.md
CHANGED
@@ -1,70 +1,159 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
## 0.5.1 2020-01-23
|
2
|
+
|
3
|
+
|
4
|
+
### Fixed
|
5
|
+
|
6
|
+
- Added missing 'set' require (@solnic)
|
7
|
+
|
8
|
+
|
9
|
+
[Compare v0.5.0...v0.5.1](https://github.com/dry-rb/dry-cli/compare/v0.5.0...v0.5.1)
|
10
|
+
|
11
|
+
## 0.5.0 2019-12-21
|
12
|
+
|
3
13
|
|
4
|
-
## v0.5.0 - 2019-12-21
|
5
14
|
### Added
|
15
|
+
|
6
16
|
- [Ivan Shamatov, Piotr Solnica, Luca Guidi] [Internal] removed runtime and development dependency against `hanami-utils`
|
7
17
|
|
8
|
-
|
18
|
+
|
19
|
+
[Compare v0.4.0...v0.5.0](https://github.com/dry-rb/dry-cli/compare/v0.4.0...v0.5.0)
|
20
|
+
|
21
|
+
## 0.4.0 2019-12-10
|
22
|
+
|
23
|
+
|
9
24
|
### Added
|
25
|
+
|
10
26
|
- [Ivan Shamatov, Piotr Solnica, Luca Guidi] `hanami-cli` => `dry-cli`
|
11
27
|
|
12
|
-
|
28
|
+
|
29
|
+
[Compare v0.3.1...v0.4.0](https://github.com/dry-rb/dry-cli/compare/v0.3.1...v0.4.0)
|
30
|
+
|
31
|
+
## 0.3.1 2019-01-18
|
32
|
+
|
33
|
+
|
13
34
|
### Added
|
35
|
+
|
14
36
|
- [Luca Guidi] Official support for Ruby: MRI 2.6
|
15
37
|
- [Luca Guidi] Support `bundler` 2.0+
|
16
38
|
|
17
|
-
## v0.3.0 - 2018-10-24
|
18
39
|
|
19
|
-
|
40
|
+
[Compare v0.3.0...v0.3.1](https://github.com/dry-rb/dry-cli/compare/v0.3.0...v0.3.1)
|
41
|
+
|
42
|
+
## 0.3.0 2018-10-24
|
43
|
+
|
44
|
+
|
45
|
+
|
46
|
+
[Compare v0.3.0.beta1...v0.3.0](https://github.com/dry-rb/dry-cli/compare/v0.3.0.beta1...v0.3.0)
|
47
|
+
|
48
|
+
## 0.3.0.beta1 2018-08-08
|
49
|
+
|
50
|
+
|
20
51
|
### Added
|
52
|
+
|
21
53
|
- [Anton Davydov & Alfonso Uceda] Introduce array type for arguments (`foo exec test spec/bookshelf/entities spec/bookshelf/repositories`)
|
22
54
|
- [Anton Davydov & Alfonso Uceda] Introduce array type for options (`foo generate config --apps=web,api`)
|
23
55
|
- [Alfonso Uceda] Introduce variadic arguments (`foo run ruby:latest -- ruby -v`)
|
24
56
|
- [Luca Guidi] Official support for JRuby 9.2.0.0
|
25
57
|
|
26
58
|
### Fixed
|
59
|
+
|
27
60
|
- [Anton Davydov] Print informative message when unknown or wrong option is passed (`"test" was called with arguments "--framework=unknown"`)
|
28
61
|
|
29
|
-
## v0.2.0 - 2018-04-11
|
30
62
|
|
31
|
-
|
63
|
+
[Compare v0.2.0...v0.3.0.beta1](https://github.com/dry-rb/dry-cli/compare/v0.2.0...v0.3.0.beta1)
|
64
|
+
|
65
|
+
## 0.2.0 2018-04-11
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
[Compare v0.2.0.rc2...v0.2.0](https://github.com/dry-rb/dry-cli/compare/v0.2.0.rc2...v0.2.0)
|
70
|
+
|
71
|
+
## 0.2.0.rc2 2018-04-06
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
[Compare v0.2.0.rc1...v0.2.0.rc2](https://github.com/dry-rb/dry-cli/compare/v0.2.0.rc1...v0.2.0.rc2)
|
76
|
+
|
77
|
+
## 0.2.0.rc1 2018-03-30
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
[Compare v0.2.0.beta2...v0.2.0.rc1](https://github.com/dry-rb/dry-cli/compare/v0.2.0.beta2...v0.2.0.rc1)
|
82
|
+
|
83
|
+
## 0.2.0.beta2 2018-03-23
|
32
84
|
|
33
|
-
## v0.2.0.rc1 - 2018-03-30
|
34
85
|
|
35
|
-
## v0.2.0.beta2 - 2018-03-23
|
36
86
|
### Added
|
87
|
+
|
37
88
|
- [Anton Davydov & Luca Guidi] Support objects as callbacks
|
38
89
|
|
39
90
|
### Fixed
|
91
|
+
|
40
92
|
- [Anton Davydov & Luca Guidi] Ensure callbacks' context of execution (aka `self`) to be the command that is being executed
|
41
93
|
|
42
|
-
|
94
|
+
|
95
|
+
[Compare v0.2.0.beta1...v0.2.0.beta2](https://github.com/dry-rb/dry-cli/compare/v0.2.0.beta1...v0.2.0.beta2)
|
96
|
+
|
97
|
+
## 0.2.0.beta1 2018-02-28
|
98
|
+
|
99
|
+
|
43
100
|
### Added
|
101
|
+
|
44
102
|
- [Anton Davydov] Register `before`/`after` callbacks for commands
|
45
103
|
|
46
|
-
|
104
|
+
|
105
|
+
[Compare v0.1.1...v0.2.0.beta1](https://github.com/dry-rb/dry-cli/compare/v0.1.1...v0.2.0.beta1)
|
106
|
+
|
107
|
+
## 0.1.1 2018-02-27
|
108
|
+
|
109
|
+
|
47
110
|
### Added
|
111
|
+
|
48
112
|
- [Luca Guidi] Official support for Ruby: MRI 2.5
|
49
113
|
|
50
114
|
### Fixed
|
115
|
+
|
51
116
|
- [Alfonso Uceda] Ensure default values for arguments to be sent to commands
|
52
117
|
- [Alfonso Uceda] Ensure to fail when a missing required argument isn't provider, but an option is provided instead
|
53
118
|
|
54
|
-
## v0.1.0 - 2017-10-25
|
55
119
|
|
56
|
-
|
120
|
+
[Compare v0.1.0...v0.1.1](https://github.com/dry-rb/dry-cli/compare/v0.1.0...v0.1.1)
|
121
|
+
|
122
|
+
## 0.1.0 2017-10-25
|
123
|
+
|
124
|
+
|
125
|
+
|
126
|
+
[Compare v0.1.0.rc1...v0.1.0](https://github.com/dry-rb/dry-cli/compare/v0.1.0.rc1...v0.1.0)
|
127
|
+
|
128
|
+
## 0.1.0.rc1 2017-10-16
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
[Compare v0.1.0.beta3...v0.1.0.rc1](https://github.com/dry-rb/dry-cli/compare/v0.1.0.beta3...v0.1.0.rc1)
|
133
|
+
|
134
|
+
## 0.1.0.beta3 2017-10-04
|
135
|
+
|
136
|
+
|
137
|
+
|
138
|
+
[Compare v0.1.0.beta2...v0.1.0.beta3](https://github.com/dry-rb/dry-cli/compare/v0.1.0.beta2...v0.1.0.beta3)
|
139
|
+
|
140
|
+
## 0.1.0.beta2 2017-10-03
|
57
141
|
|
58
|
-
## v0.1.0.beta3 - 2017-10-04
|
59
142
|
|
60
|
-
## v0.1.0.beta2 - 2017-10-03
|
61
143
|
### Added
|
62
|
-
- [Alfonso Uceda] Allow default value for arguments
|
63
144
|
|
64
|
-
|
145
|
+
- [Alfonso Uceda] Allow default value for arguments
|
146
|
+
|
147
|
+
|
148
|
+
[Compare v0.1.0.beta1...v0.1.0.beta2](https://github.com/dry-rb/dry-cli/compare/v0.1.0.beta1...v0.1.0.beta2)
|
149
|
+
|
150
|
+
## 0.1.0.beta1 2017-08-11
|
151
|
+
|
152
|
+
|
65
153
|
### Added
|
66
|
-
|
67
|
-
-
|
154
|
+
|
155
|
+
- [Alfonso Uceda, Luca Guidi] Commands banner and usage
|
156
|
+
- [Alfonso Uceda] Added support for subcommands
|
68
157
|
- [Alfonso Uceda] Validations for arguments and options
|
69
158
|
- [Alfonso Uceda] Commands arguments and options
|
70
159
|
- [Alfonso Uceda] Commands description
|
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,31 +1,29 @@
|
|
1
1
|
[gem]: https://rubygems.org/gems/dry-cli
|
2
|
-
[
|
3
|
-
[
|
2
|
+
[actions]: https://github.com/dry-rb/dry-cli/actions
|
3
|
+
[codacy]: https://www.codacy.com/gh/dry-rb/dry-cli
|
4
4
|
[chat]: https://dry-rb.zulipchat.com
|
5
5
|
[inchpages]: http://inch-ci.org/github/dry-rb/dry-cli
|
6
6
|
|
7
|
-
# dry-cli
|
7
|
+
# dry-cli [][chat]
|
8
8
|
|
9
9
|
[][gem]
|
10
|
-
[][actions]
|
11
|
+
[][codacy]
|
12
|
+
[][codacy]
|
13
13
|
[][inchpages]
|
14
14
|
|
15
15
|
## Links
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
- [Guidelines for contributing](CONTRIBUTING.md)
|
17
|
+
* [User documentation](http://dry-rb.org/gems/dry-cli)
|
18
|
+
* [API documentation](http://rubydoc.info/gems/dry-cli)
|
20
19
|
|
21
20
|
## Supported Ruby versions
|
22
21
|
|
23
22
|
This library officially supports the following Ruby versions:
|
24
23
|
|
25
|
-
|
26
|
-
|
24
|
+
* MRI >= `2.4`
|
25
|
+
* jruby >= `9.2`
|
27
26
|
|
28
27
|
## License
|
29
28
|
|
30
29
|
See `LICENSE` file.
|
31
|
-
|
data/dry-cli.gemspec
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
# this file is managed by dry-rb/devtools project
|
2
3
|
|
3
4
|
lib = File.expand_path('lib', __dir__)
|
4
5
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
@@ -6,30 +7,29 @@ require 'dry/cli/version'
|
|
6
7
|
|
7
8
|
Gem::Specification.new do |spec|
|
8
9
|
spec.name = 'dry-cli'
|
9
|
-
spec.
|
10
|
-
spec.
|
11
|
-
spec.
|
12
|
-
spec.
|
13
|
-
|
14
|
-
spec.summary =
|
15
|
-
spec.description =
|
16
|
-
spec.homepage = '
|
10
|
+
spec.authors = ["Luca Guidi"]
|
11
|
+
spec.email = ["me@lucaguidi.com"]
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.version = Dry::CLI::VERSION.dup
|
14
|
+
|
15
|
+
spec.summary = "Common framework to build command line interfaces with Ruby"
|
16
|
+
spec.description = spec.summary
|
17
|
+
spec.homepage = 'https://dry-rb.org/gems/dry-cli'
|
18
|
+
spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-cli.gemspec", "lib/**/*"]
|
19
|
+
spec.require_paths = ['lib']
|
17
20
|
|
18
21
|
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
-
spec.metadata['
|
20
|
-
|
21
|
-
spec.
|
22
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
|
-
spec.require_paths = ['lib']
|
22
|
+
spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-cli/blob/master/CHANGELOG.md'
|
23
|
+
spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-cli'
|
24
|
+
spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-cli/issues'
|
24
25
|
|
25
|
-
spec.
|
26
|
-
f.match(%r{^(test|spec|features)/})
|
27
|
-
end
|
26
|
+
spec.required_ruby_version = '>= 2.4.0'
|
28
27
|
|
29
|
-
|
28
|
+
# to update dependencies edit project.yml
|
29
|
+
spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
|
30
30
|
|
31
|
-
spec.add_development_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
31
|
+
spec.add_development_dependency "bundler", ">= 1.6", "< 3"
|
32
|
+
spec.add_development_dependency "rake", "~> 13.0"
|
33
|
+
spec.add_development_dependency "rspec", "~> 3.7"
|
34
|
+
spec.add_development_dependency "simplecov", "~> 0.17.1"
|
35
35
|
end
|
data/lib/dry/cli.rb
CHANGED
@@ -36,12 +36,17 @@ module Dry
|
|
36
36
|
|
37
37
|
# Create a new instance
|
38
38
|
#
|
39
|
-
# @param registry [Dry::CLI::Registry] a registry
|
39
|
+
# @param registry [Dry::CLI::Registry, Block] a registry or a configuration block
|
40
40
|
#
|
41
41
|
# @return [Dry::CLI] the new instance
|
42
|
-
# @since 0.
|
43
|
-
def initialize(registry)
|
44
|
-
@commands =
|
42
|
+
# @since 0.4.0
|
43
|
+
def initialize(registry = nil, &block)
|
44
|
+
@commands =
|
45
|
+
if block_given?
|
46
|
+
anonymous_registry(&block)
|
47
|
+
else
|
48
|
+
registry
|
49
|
+
end
|
45
50
|
end
|
46
51
|
|
47
52
|
# Invoke the CLI
|
@@ -84,12 +89,13 @@ module Dry
|
|
84
89
|
# @api private
|
85
90
|
def parse(result, out)
|
86
91
|
command = result.command
|
92
|
+
names = result.names
|
87
93
|
return [command, result.arguments] unless command?(command)
|
88
94
|
|
89
95
|
result = Parser.call(command, result.arguments, result.names)
|
90
96
|
|
91
97
|
if result.help?
|
92
|
-
Banner.call(command, out)
|
98
|
+
Banner.call(command, out, names)
|
93
99
|
exit(0)
|
94
100
|
end
|
95
101
|
|
@@ -126,5 +132,33 @@ module Dry
|
|
126
132
|
def command?(command)
|
127
133
|
CLI.command?(command)
|
128
134
|
end
|
135
|
+
|
136
|
+
# Generates registry in runtime
|
137
|
+
#
|
138
|
+
# @param &block [Block] configuration for the registry
|
139
|
+
#
|
140
|
+
# @return [Module] module extended with registry abilities and configured with a block
|
141
|
+
#
|
142
|
+
# @since 0.4.0
|
143
|
+
# @api private
|
144
|
+
def anonymous_registry(&block)
|
145
|
+
registry = Module.new { extend(Dry::CLI::Registry) }
|
146
|
+
if block.arity.zero?
|
147
|
+
registry.instance_eval(&block)
|
148
|
+
else
|
149
|
+
yield(registry)
|
150
|
+
end
|
151
|
+
registry
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
# Create a new instance
|
156
|
+
#
|
157
|
+
# @param registry [Dry::CLI::Registry, Block] a registry or a configuration block
|
158
|
+
#
|
159
|
+
# @return [Dry::CLI] the new instance
|
160
|
+
# @since 0.4.0
|
161
|
+
def self.CLI(registry = nil, &block)
|
162
|
+
CLI.new(registry, &block)
|
129
163
|
end
|
130
164
|
end
|
data/lib/dry/cli/banner.rb
CHANGED
@@ -16,14 +16,15 @@ module Dry
|
|
16
16
|
#
|
17
17
|
# @since 0.1.0
|
18
18
|
# @api private
|
19
|
-
def self.call(command, out)
|
19
|
+
def self.call(command, out, names)
|
20
|
+
full_command_name = full_command_name(names)
|
20
21
|
output = [
|
21
|
-
command_name(
|
22
|
-
command_name_and_arguments(command),
|
22
|
+
command_name(full_command_name),
|
23
|
+
command_name_and_arguments(command, full_command_name),
|
23
24
|
command_description(command),
|
24
25
|
command_arguments(command),
|
25
26
|
command_options(command),
|
26
|
-
command_examples(command)
|
27
|
+
command_examples(command, full_command_name)
|
27
28
|
].compact.join("\n")
|
28
29
|
|
29
30
|
out.puts output
|
@@ -31,22 +32,22 @@ module Dry
|
|
31
32
|
|
32
33
|
# @since 0.1.0
|
33
34
|
# @api private
|
34
|
-
def self.command_name(
|
35
|
-
"Command:\n #{
|
35
|
+
def self.command_name(name)
|
36
|
+
"Command:\n #{name}"
|
36
37
|
end
|
37
38
|
|
38
39
|
# @since 0.1.0
|
39
40
|
# @api private
|
40
|
-
def self.command_name_and_arguments(command)
|
41
|
-
"\nUsage:\n #{
|
41
|
+
def self.command_name_and_arguments(command, name)
|
42
|
+
"\nUsage:\n #{name}#{arguments(command)}"
|
42
43
|
end
|
43
44
|
|
44
45
|
# @since 0.1.0
|
45
46
|
# @api private
|
46
|
-
def self.command_examples(command)
|
47
|
+
def self.command_examples(command, name)
|
47
48
|
return if command.examples.empty?
|
48
49
|
|
49
|
-
"\nExamples:\n#{command.examples.map { |example| " #{
|
50
|
+
"\nExamples:\n#{command.examples.map { |example| " #{name} #{example}" }.join("\n")}" # rubocop:disable Metrics/LineLength
|
50
51
|
end
|
51
52
|
|
52
53
|
# @since 0.1.0
|
@@ -73,8 +74,8 @@ module Dry
|
|
73
74
|
|
74
75
|
# @since 0.1.0
|
75
76
|
# @api private
|
76
|
-
def self.full_command_name(
|
77
|
-
ProgramName.call(
|
77
|
+
def self.full_command_name(names)
|
78
|
+
ProgramName.call(names)
|
78
79
|
end
|
79
80
|
|
80
81
|
# @since 0.1.0
|
@@ -101,7 +102,6 @@ module Dry
|
|
101
102
|
# @since 0.1.0
|
102
103
|
# @api private
|
103
104
|
#
|
104
|
-
# rubocop:disable Metrics/AbcSize
|
105
105
|
def self.extended_command_options(command)
|
106
106
|
result = command.options.map do |option|
|
107
107
|
name = Inflector.dasherize(option.name)
|
@@ -110,8 +110,7 @@ module Dry
|
|
110
110
|
else
|
111
111
|
"#{name}=VALUE"
|
112
112
|
end
|
113
|
-
|
114
|
-
name = "#{name}, #{option.aliases.map { |a| a.start_with?('--') ? "#{a}=VALUE" : "#{a} VALUE" }.join(', ')}" unless option.aliases.empty? # rubocop:disable Metrics/LineLength
|
113
|
+
name = "#{name}, #{option.alias_names.join(', ')}" if option.aliases.any?
|
115
114
|
name = " --#{name.ljust(30)}"
|
116
115
|
name = "#{name}\t# #{option.desc}"
|
117
116
|
name = "#{name}, default: #{option.default.inspect}" unless option.default.nil?
|
@@ -121,7 +120,6 @@ module Dry
|
|
121
120
|
result << " --#{'help, -h'.ljust(30)}\t# Print this help"
|
122
121
|
result.join("\n")
|
123
122
|
end
|
124
|
-
# rubocop:enable Metrics/AbcSize
|
125
123
|
end
|
126
124
|
end
|
127
125
|
end
|