dry-cli 0.7.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: acfd9b78000e6f3ecef16d4eee260eee84bb4661251966e367e4f9a2001d3dac
4
- data.tar.gz: df37074af2d1ed387d24ab90ed37920247cc40dc4c508c1325f08e9cb395c277
3
+ metadata.gz: 3bb38a55577b2607724ceaafe32979ca39b83b62ece8d5e734f522646042d2f5
4
+ data.tar.gz: 05e3fe644ca5fceb2bd3dc740453faf8aab28faaf7ad5ae9ab39a23474f7f611
5
5
  SHA512:
6
- metadata.gz: c2b0035c9df7cbe7cf01fabd69a0207aaab945a13debf8b4a1441d764853343ac2a2dd1264c395aeda3296957870fcdcd87fa44041f6948d490afde897f2d837
7
- data.tar.gz: c74d981d7c23200a652f75013977a9ea3b720c1264e184fd93af83fcb33995ec00c6284021a7e29b3ea215e9ac5c51aaccbf2ff03c821f215aa52d433bf1fd62
6
+ metadata.gz: 97ff398081901a642d1d8d898a50eec46e33103defff2e4c77f11a0e5150dcb79fc7e568cbeaaeaa7e6af9f0e05835b265a2ceb7fda144f4983b8dfc27363728
7
+ data.tar.gz: 39b43443b842724a7096a909bba93dd93ceda1c470a2cfc2ec9ac9e02f2aee0b449f2dd6c2b7bf9c0c92485ad404a14ba1a352518d5070366535bbc19d5cb789
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
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
+
13
+ ## 1.0.0 2022-11-05
14
+
15
+
16
+ ### Changed
17
+
18
+ - Version bumped to 1.0.0 (@solnic)
19
+
20
+ [Compare v0.7.0...v1.0.0](https://github.com/dry-rb/dry-cli/compare/v0.7.0...v1.0.0)
21
+
3
22
  ## 0.7.0 2020-05-08
4
23
 
5
24
 
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2021 dry-rb team
3
+ Copyright (c) 2015-2023 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,28 +1,21 @@
1
+ <!--- this file is synced from dry-rb/template-gem project -->
1
2
  [gem]: https://rubygems.org/gems/dry-cli
2
3
  [actions]: https://github.com/dry-rb/dry-cli/actions
3
- [codacy]: https://www.codacy.com/gh/dry-rb/dry-cli
4
- [chat]: https://dry-rb.zulipchat.com
5
- [inchpages]: http://inch-ci.org/github/dry-rb/dry-cli
6
4
 
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
-
9
- [![Gem Version](https://badge.fury.io/rb/dry-cli.svg)][gem]
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
- [![Inline docs](http://inch-ci.org/github/dry-rb/dry-cli.svg?branch=master)][inchpages]
5
+ # dry-cli [![Gem Version](https://badge.fury.io/rb/dry-cli.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-cli/workflows/ci/badge.svg)][actions]
14
6
 
15
7
  ## Links
16
8
 
17
- * [User documentation](http://dry-rb.org/gems/dry-cli)
9
+ * [User documentation](https://dry-rb.org/gems/dry-cli)
18
10
  * [API documentation](http://rubydoc.info/gems/dry-cli)
11
+ * [Forum](https://discourse.dry-rb.org)
19
12
 
20
13
  ## Supported Ruby versions
21
14
 
22
15
  This library officially supports the following Ruby versions:
23
16
 
24
- * MRI >= `2.5`
25
- * jruby >= `9.2`
17
+ * MRI `>= 2.4.0`
18
+ * jruby `>= 9.4` (not tested on CI)
26
19
 
27
20
  ## License
28
21
 
data/dry-cli.gemspec CHANGED
@@ -1,33 +1,35 @@
1
1
  # frozen_string_literal: true
2
- # this file is managed by dry-rb/devtools project
3
2
 
4
- lib = File.expand_path('lib', __dir__)
3
+ # this file is synced from dry-rb/template-gem project
4
+
5
+ lib = File.expand_path("lib", __dir__)
5
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
- require 'dry/cli/version'
7
+ require "dry/cli/version"
7
8
 
8
9
  Gem::Specification.new do |spec|
9
- spec.name = 'dry-cli'
10
+ spec.name = "dry-cli"
10
11
  spec.authors = ["Luca Guidi"]
11
12
  spec.email = ["me@lucaguidi.com"]
12
- spec.license = 'MIT'
13
+ spec.license = "MIT"
13
14
  spec.version = Dry::CLI::VERSION.dup
14
15
 
15
16
  spec.summary = "Common framework to build command line interfaces with Ruby"
16
17
  spec.description = spec.summary
17
- spec.homepage = 'https://dry-rb.org/gems/dry-cli'
18
+ spec.homepage = "https://dry-rb.org/gems/dry-cli"
18
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-cli.gemspec", "lib/**/*"]
19
- spec.bindir = 'bin'
20
+ spec.bindir = "bin"
20
21
  spec.executables = []
21
- spec.require_paths = ['lib']
22
+ spec.require_paths = ["lib"]
22
23
 
23
- spec.metadata['allowed_push_host'] = 'https://rubygems.org'
24
- spec.metadata['changelog_uri'] = 'https://github.com/dry-rb/dry-cli/blob/master/CHANGELOG.md'
25
- spec.metadata['source_code_uri'] = 'https://github.com/dry-rb/dry-cli'
26
- spec.metadata['bug_tracker_uri'] = 'https://github.com/dry-rb/dry-cli/issues'
24
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-cli/blob/main/CHANGELOG.md"
26
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-cli"
27
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-cli/issues"
27
28
 
28
29
  spec.required_ruby_version = ">= 2.4.0"
29
30
 
30
31
  # to update dependencies edit project.yml
32
+
31
33
  spec.add_development_dependency "bundler", ">= 1.6", "< 3"
32
34
  spec.add_development_dependency "rake", "~> 13.0"
33
35
  spec.add_development_dependency "rspec", "~> 3.7"
@@ -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 Metrics/LineLength
90
- optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable Metrics/LineLength
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 Metrics/LineLength
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
@@ -45,11 +45,7 @@ module Dry
45
45
 
46
46
  # @since 0.7.0
47
47
  # @api private
48
- attr_reader :subcommands
49
-
50
- # @since 0.7.0
51
- # @api private
52
- attr_writer :subcommands
48
+ attr_accessor :subcommands
53
49
  end
54
50
 
55
51
  # Set the description of the command
@@ -213,7 +209,7 @@ module Dry
213
209
  # require "dry/cli"
214
210
  #
215
211
  # class Console < Dry::CLI::Command
216
- # param :engine
212
+ # option :engine
217
213
  #
218
214
  # def call(engine: nil, **)
219
215
  # puts "starting console (engine: #{engine || :irb})"
@@ -230,7 +226,7 @@ module Dry
230
226
  # require "dry/cli"
231
227
  #
232
228
  # class Console < Dry::CLI::Command
233
- # param :engine, values: %w(irb pry ripl)
229
+ # option :engine, values: %w(irb pry ripl)
234
230
  #
235
231
  # def call(engine: nil, **)
236
232
  # puts "starting console (engine: #{engine || :irb})"
@@ -250,7 +246,7 @@ module Dry
250
246
  # require "dry/cli"
251
247
  #
252
248
  # class Console < Dry::CLI::Command
253
- # param :engine, desc: "Force a console engine"
249
+ # option :engine, desc: "Force a console engine"
254
250
  #
255
251
  # def call(engine: nil, **)
256
252
  # # ...
@@ -268,7 +264,7 @@ module Dry
268
264
  # require "dry/cli"
269
265
  #
270
266
  # class Server < Dry::CLI::Command
271
- # param :code_reloading, type: :boolean, default: true
267
+ # option :code_reloading, type: :boolean, default: true
272
268
  #
273
269
  # def call(code_reloading:, **)
274
270
  # puts "staring server (code reloading: #{code_reloading})"
@@ -291,7 +287,7 @@ module Dry
291
287
  # require "dry/cli"
292
288
  #
293
289
  # class Server < Dry::CLI::Command
294
- # param :port, aliases: ["-p"]
290
+ # option :port, aliases: ["-p"]
295
291
  #
296
292
  # def call(options)
297
293
  # puts "staring server (port: #{options.fetch(:port, 2300)})"
@@ -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..-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
  #
@@ -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
 
@@ -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 Metrics/LineLength
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 Metrics/LineLength
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 Metrics/LineLength
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 Metrics/LineLength
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..-1]
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 Metrics/LineLength
59
- optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any? # rubocop:disable Metrics/LineLength
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?
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class CLI
5
5
  # @since 0.1.0
6
- VERSION = "0.7.0"
6
+ VERSION = "1.1.0"
7
7
  end
8
8
  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: 0.7.0
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: 2021-05-08 00:00:00.000000000 Z
11
+ date: 2024-07-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -115,7 +115,7 @@ licenses:
115
115
  - MIT
116
116
  metadata:
117
117
  allowed_push_host: https://rubygems.org
118
- changelog_uri: https://github.com/dry-rb/dry-cli/blob/master/CHANGELOG.md
118
+ changelog_uri: https://github.com/dry-rb/dry-cli/blob/main/CHANGELOG.md
119
119
  source_code_uri: https://github.com/dry-rb/dry-cli
120
120
  bug_tracker_uri: https://github.com/dry-rb/dry-cli/issues
121
121
  post_install_message:
@@ -133,7 +133,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
133
  - !ruby/object:Gem::Version
134
134
  version: '0'
135
135
  requirements: []
136
- rubygems_version: 3.1.6
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