dry-cli 0.4.0 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +0 -4
- data/docsite/source/index.html.md +1 -1
- data/dry-cli.gemspec +0 -1
- data/lib/dry/cli.rb +1 -0
- data/lib/dry/cli/banner.rb +1 -1
- data/lib/dry/cli/command_registry.rb +32 -3
- data/lib/dry/cli/errors.rb +0 -2
- data/lib/dry/cli/inflector.rb +17 -0
- data/lib/dry/cli/option.rb +1 -3
- data/lib/dry/cli/version.rb +1 -1
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10c2bb5f82ae29dc19f705e9caee094e6e756e6de6a110e7ad82a540a98f08fa
|
4
|
+
data.tar.gz: 9ecf08520054dae86e45f61abcaf653d0da1eb6ee3b3c1907cf2fd44706b3a4c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c37d5cfb952cb82bb591ce4fd584675e117e76e73f2b5c65990b321de7b156cb56df55554caab94666c370c97d896602043edd39f5ac9e0a53cf33ada678d82e
|
7
|
+
data.tar.gz: ca346d815e518cb1306a4ddf1c9d178494bd0b1ba61024f65fe0eff282e3dac2caf57070439da99840ee719f38bcc30d6cda00158f4151001fde82c8a7ab4d40
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# Dry::CLI
|
2
2
|
General purpose Command Line Interface (CLI) framework for Ruby
|
3
3
|
|
4
|
+
## v0.5.0 - 2019-12-21
|
5
|
+
### Added
|
6
|
+
- [Ivan Shamatov, Piotr Solnica, Luca Guidi] [Internal] removed runtime and development dependency against `hanami-utils`
|
7
|
+
|
4
8
|
## v0.4.0 - 2019-12-10
|
5
9
|
### Added
|
6
10
|
- [Ivan Shamatov, Piotr Solnica, Luca Guidi] `hanami-cli` => `dry-cli`
|
data/Gemfile
CHANGED
@@ -567,7 +567,7 @@ cli.call
|
|
567
567
|
|
568
568
|
The `foo-bar` gem enhances `hello` command with callbacks:
|
569
569
|
|
570
|
-
```
|
570
|
+
```ruby
|
571
571
|
Foo::CLI::Commands.before("hello") { |args| puts "debug: #{args.inspect}" } # syntax 1
|
572
572
|
Foo::CLI::Commands.after "hello", &->(args) { puts "bye, #{args.fetch(:name)}" } # syntax 2
|
573
573
|
```
|
data/dry-cli.gemspec
CHANGED
data/lib/dry/cli.rb
CHANGED
data/lib/dry/cli/banner.rb
CHANGED
@@ -104,7 +104,7 @@ module Dry
|
|
104
104
|
# rubocop:disable Metrics/AbcSize
|
105
105
|
def self.extended_command_options(command)
|
106
106
|
result = command.options.map do |option|
|
107
|
-
name =
|
107
|
+
name = Inflector.dasherize(option.name)
|
108
108
|
name = if option.boolean?
|
109
109
|
"[no-]#{name}"
|
110
110
|
else
|
@@ -1,7 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'concurrent/hash'
|
4
|
-
require 'hanami/utils/callbacks'
|
5
4
|
|
6
5
|
module Dry
|
7
6
|
class CLI
|
@@ -111,8 +110,8 @@ module Dry
|
|
111
110
|
@aliases = Concurrent::Hash.new
|
112
111
|
@command = nil
|
113
112
|
|
114
|
-
@before_callbacks =
|
115
|
-
@after_callbacks =
|
113
|
+
@before_callbacks = Chain.new
|
114
|
+
@after_callbacks = Chain.new
|
116
115
|
end
|
117
116
|
|
118
117
|
# @since 0.1.0
|
@@ -206,6 +205,36 @@ module Dry
|
|
206
205
|
@node.after_callbacks
|
207
206
|
end
|
208
207
|
end
|
208
|
+
|
209
|
+
# Callbacks chain
|
210
|
+
#
|
211
|
+
# @since 0.4.0
|
212
|
+
# @api private
|
213
|
+
class Chain
|
214
|
+
# @since 0.4.0
|
215
|
+
# @api private
|
216
|
+
attr_reader :chain
|
217
|
+
|
218
|
+
# @since 0.4.0
|
219
|
+
# @api private
|
220
|
+
def initialize
|
221
|
+
@chain = Set.new
|
222
|
+
end
|
223
|
+
|
224
|
+
# @since 0.4.0
|
225
|
+
# @api private
|
226
|
+
def append(&callback)
|
227
|
+
chain.add(callback)
|
228
|
+
end
|
229
|
+
|
230
|
+
# @since 0.4.0
|
231
|
+
# @api private
|
232
|
+
def run(context, *args)
|
233
|
+
chain.each do |callback|
|
234
|
+
context.instance_exec(*args, &callback)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
209
238
|
end
|
210
239
|
end
|
211
240
|
end
|
data/lib/dry/cli/errors.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Dry
|
4
|
+
class CLI
|
5
|
+
# @api private
|
6
|
+
# @since 0.5.0
|
7
|
+
module Inflector
|
8
|
+
# @api private
|
9
|
+
# @since 0.5.0
|
10
|
+
def self.dasherize(input)
|
11
|
+
return nil unless input
|
12
|
+
|
13
|
+
input.to_s.downcase.gsub(/[[[:space:]]_]/, "-")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/dry/cli/option.rb
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'hanami/utils/string'
|
4
|
-
|
5
3
|
module Dry
|
6
4
|
class CLI
|
7
5
|
# Command line option
|
@@ -90,7 +88,7 @@ module Dry
|
|
90
88
|
#
|
91
89
|
# rubocop:disable Metrics/AbcSize
|
92
90
|
def parser_options
|
93
|
-
dasherized_name =
|
91
|
+
dasherized_name = Inflector.dasherize(name)
|
94
92
|
parser_options = []
|
95
93
|
|
96
94
|
if boolean?
|
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: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: concurrent-ruby
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: hanami-utils
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '1.3'
|
34
|
-
type: :runtime
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '1.3'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: bundler
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -133,6 +119,7 @@ files:
|
|
133
119
|
- lib/dry/cli/command.rb
|
134
120
|
- lib/dry/cli/command_registry.rb
|
135
121
|
- lib/dry/cli/errors.rb
|
122
|
+
- lib/dry/cli/inflector.rb
|
136
123
|
- lib/dry/cli/option.rb
|
137
124
|
- lib/dry/cli/parser.rb
|
138
125
|
- lib/dry/cli/program_name.rb
|