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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 10c2bb5f82ae29dc19f705e9caee094e6e756e6de6a110e7ad82a540a98f08fa
4
- data.tar.gz: 9ecf08520054dae86e45f61abcaf653d0da1eb6ee3b3c1907cf2fd44706b3a4c
3
+ metadata.gz: '0976875bf08ad159133d9c103dccf46df45551875fe368d24aca74bc11263b6e'
4
+ data.tar.gz: 68d06b56349cc86c74812b1226d221cf11ad97c132ab836ea2161add4e8867d5
5
5
  SHA512:
6
- metadata.gz: c37d5cfb952cb82bb591ce4fd584675e117e76e73f2b5c65990b321de7b156cb56df55554caab94666c370c97d896602043edd39f5ac9e0a53cf33ada678d82e
7
- data.tar.gz: ca346d815e518cb1306a4ddf1c9d178494bd0b1ba61024f65fe0eff282e3dac2caf57070439da99840ee719f38bcc30d6cda00158f4151001fde82c8a7ab4d40
6
+ metadata.gz: 9577fd903c55e544fe062aac19cf9226d3474a298299a8f30ce2ed58be60a9833e6b7d7ca56acfc33ec31b9899275a6ccaafa4aa732187987d0a72f3df0ab6f6
7
+ data.tar.gz: e3842ccf475c1a82fb53fb71dfa9deb96a28d23ca20ff25860f49a3db07fcaf1f2d0cd5cd0454afb41ca3b924475f190c091c1bc8e4182eb9981a24449f425ed
@@ -1,70 +1,159 @@
1
- # Dry::CLI
2
- General purpose Command Line Interface (CLI) framework for Ruby
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
- ## v0.4.0 - 2019-12-10
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
- ## v0.3.1 - 2019-01-18
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
- ## v0.3.0.beta1 - 2018-08-08
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
- ## v0.2.0.rc2 - 2018-04-06
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
- ## v0.2.0.beta1 - 2018-02-28
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
- ## v0.1.1 - 2018-02-27
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
- ## v0.1.0.rc1 - 2017-10-16
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
- ## v0.1.0.beta1 - 2017-08-11
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
- - [Alfonso Uceda, Luca Guidi] Commands banner and usage
67
- - [Alfonso Uceda] Added support for subcommands
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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2019 dry-rb team
3
+ Copyright (c) 2015-2020 dry-rb team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
data/README.md CHANGED
@@ -1,31 +1,29 @@
1
1
  [gem]: https://rubygems.org/gems/dry-cli
2
- [ci]: https://github.com/dry-rb/dry-cli/actions?query=workflow%3Aci
3
- [codeclimate]: https://codeclimate.com/github/dry-rb/dry-cli
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 (formerly known as hanami-cli)[![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
7
+ # dry-cli [![Join the chat at https://dry-rb.zulipchat.com](https://img.shields.io/badge/dry--rb-join%20chat-%23346b7a.svg)][chat]
8
8
 
9
9
  [![Gem Version](https://badge.fury.io/rb/dry-cli.svg)][gem]
10
- [![Build Status](https://github.com/dry-rb/dry-cli/workflows/ci/badge.svg)][ci]
11
- [![Code Climate](https://codeclimate.com/github/dry-rb/dry-cli/badges/gpa.svg)][codeclimate]
12
- [![Test Coverage](https://codeclimate.com/github/dry-rb/dry-cli/badges/coverage.svg)][codeclimate]
10
+ [![CI Status](https://github.com/dry-rb/dry-cli/workflows/ci/badge.svg)][actions]
11
+ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/61dd5d070fc74f0cacf575b19d4930e1)][codacy]
12
+ [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/61dd5d070fc74f0cacf575b19d4930e1)][codacy]
13
13
  [![Inline docs](http://inch-ci.org/github/dry-rb/dry-cli.svg?branch=master)][inchpages]
14
14
 
15
15
  ## Links
16
16
 
17
- - [User documentation](https://dry-rb.org/gems/dry-cli)
18
- - [API documentation](http://rubydoc.info/gems/dry-cli)
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
- - MRI >= `2.3`
26
- - jruby >= `9.2`
24
+ * MRI >= `2.4`
25
+ * jruby >= `9.2`
27
26
 
28
27
  ## License
29
28
 
30
29
  See `LICENSE` file.
31
-
@@ -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.version = Dry::CLI::VERSION
10
- spec.authors = ['Luca Guidi']
11
- spec.email = ['me@lucaguidi.com']
12
- spec.licenses = ['MIT']
13
-
14
- spec.summary = 'Dry CLI'
15
- spec.description = 'Common framework to build command line interfaces with Ruby'
16
- spec.homepage = 'http://dry-rb.org'
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['source_code_uri'] = 'https://github.com/dry-rb/dry-cli'
20
-
21
- spec.bindir = 'exe'
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.files = `git ls-files -z`.split("\x0").reject do |f|
26
- f.match(%r{^(test|spec|features)/})
27
- end
26
+ spec.required_ruby_version = '>= 2.4.0'
28
27
 
29
- spec.add_dependency 'concurrent-ruby', '~> 1.0'
28
+ # to update dependencies edit project.yml
29
+ spec.add_runtime_dependency "concurrent-ruby", "~> 1.0"
30
30
 
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'
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
@@ -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.1.0
43
- def initialize(registry)
44
- @commands = registry
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
@@ -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(command),
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(command)
35
- "Command:\n #{full_command_name(command)}"
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 #{full_command_name(command)}#{arguments(command)}"
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| " #{full_command_name(command)} #{example}" }.join("\n")}" # rubocop:disable Metrics/LineLength
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(command)
77
- ProgramName.call(command.command_name)
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