dry-cli 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -352,16 +352,6 @@ module Dry
352
352
  required_arguments
353
353
  optional_arguments
354
354
  ] => 'self.class'
355
-
356
- # @since 0.1.0
357
- # @api private
358
- attr_reader :command_name
359
-
360
- # @since 0.1.0
361
- # @api private
362
- def initialize(command_name:, **)
363
- @command_name = command_name
364
- end
365
355
  end
366
356
  end
367
357
  end
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'set'
3
4
  require 'concurrent/hash'
4
5
 
5
6
  module Dry
@@ -17,9 +18,9 @@ module Dry
17
18
 
18
19
  # @since 0.1.0
19
20
  # @api private
20
- def set(name, command, aliases, **options)
21
+ def set(name, command, aliases)
21
22
  node = @root
22
- command = command_for(name, command, **options)
23
+ command = command.new if command
23
24
  name.split(/[[:space:]]/).each do |token|
24
25
  node = node.put(node, token)
25
26
  end
@@ -61,18 +62,6 @@ module Dry
61
62
  result
62
63
  end
63
64
 
64
- private
65
-
66
- # @since 0.1.0
67
- # @api private
68
- def command_for(name, command, **options)
69
- if command.nil?
70
- command
71
- else
72
- command.new(command_name: name, **options)
73
- end
74
- end
75
-
76
65
  # Node of the registry
77
66
  #
78
67
  # @since 0.1.0
@@ -10,7 +10,7 @@ module Dry
10
10
  def self.dasherize(input)
11
11
  return nil unless input
12
12
 
13
- input.to_s.downcase.gsub(/[[[:space:]]_]/, "-")
13
+ input.to_s.downcase.gsub(/[[[:space:]]_]/, '-')
14
14
  end
15
15
  end
16
16
  end
@@ -86,7 +86,6 @@ module Dry
86
86
  # @since 0.1.0
87
87
  # @api private
88
88
  #
89
- # rubocop:disable Metrics/AbcSize
90
89
  def parser_options
91
90
  dasherized_name = Inflector.dasherize(name)
92
91
  parser_options = []
@@ -100,18 +99,20 @@ module Dry
100
99
 
101
100
  parser_options << Array if array?
102
101
  parser_options << values if values
103
- parser_options.unshift(alias_name) unless alias_name.nil?
102
+ parser_options.unshift(*alias_names) if aliases.any?
104
103
  parser_options << desc if desc
105
104
  parser_options
106
105
  end
107
- # rubocop:enable Metrics/AbcSize
108
-
109
- private
110
106
 
111
107
  # @since 0.1.0
112
108
  # @api private
113
- def alias_name
114
- aliases.join(' ') if aliases.any?
109
+ def alias_names
110
+ aliases
111
+ .map { |name| name.gsub(/^-{1,2}/, '') }
112
+ .compact
113
+ .uniq
114
+ .map { |name| name.size == 1 ? "-#{name}" : "--#{name}" }
115
+ .map { |name| boolean? ? name : "#{name} VALUE" }
115
116
  end
116
117
  end
117
118
 
@@ -32,7 +32,7 @@ module Dry
32
32
  parsed_options = command.default_params.merge(parsed_options)
33
33
  parse_required_params(command, arguments, names, parsed_options)
34
34
  rescue ::OptionParser::ParseError
35
- Result.failure("Error: \"#{command.command_name}\" was called with arguments \"#{original_arguments.join(' ')}\"") # rubocop:disable Metrics/LineLength
35
+ Result.failure("Error: \"#{names.last}\" was called with arguments \"#{original_arguments.join(' ')}\"") # rubocop:disable Metrics/LineLength
36
36
  end
37
37
 
38
38
  # @since 0.1.0
@@ -74,11 +74,16 @@ module Dry
74
74
  # end
75
75
  # end
76
76
  # end
77
- def register(name, command = nil, aliases: [], **options)
77
+ def register(name, command = nil, aliases: [], &block)
78
78
  if block_given?
79
- yield Prefix.new(@commands, name, aliases)
79
+ prefix = Prefix.new(@commands, name, aliases)
80
+ if block.arity.zero?
81
+ prefix.instance_eval(&block)
82
+ else
83
+ yield(prefix)
84
+ end
80
85
  else
81
- @commands.set(name, command, aliases, **options)
86
+ @commands.set(name, command, aliases)
82
87
  end
83
88
  end
84
89
 
@@ -308,9 +313,9 @@ module Dry
308
313
  # @since 0.1.0
309
314
  #
310
315
  # @see Dry::CLI::Registry#register
311
- def register(name, command, aliases: [], **options)
316
+ def register(name, command, aliases: [])
312
317
  command_name = "#{prefix} #{name}"
313
- registry.set(command_name, command, aliases, **options)
318
+ registry.set(command_name, command, aliases)
314
319
  end
315
320
 
316
321
  private
@@ -3,6 +3,6 @@
3
3
  module Dry
4
4
  class CLI
5
5
  # @since 0.1.0
6
- VERSION = '0.5.0'
6
+ VERSION = '0.5.1'
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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Luca Guidi
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-21 00:00:00.000000000 Z
11
+ date: 2020-01-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -93,26 +93,9 @@ executables: []
93
93
  extensions: []
94
94
  extra_rdoc_files: []
95
95
  files:
96
- - ".codeclimate.yml"
97
- - ".github/ISSUE_TEMPLATE/----please-don-t-ask-for-support-via-issues.md"
98
- - ".github/ISSUE_TEMPLATE/---bug-report.md"
99
- - ".github/ISSUE_TEMPLATE/---feature-request.md"
100
- - ".github/workflows/custom_ci.yml"
101
- - ".github/workflows/docsite.yml"
102
- - ".github/workflows/sync_configs.yml"
103
- - ".gitignore"
104
- - ".rspec"
105
- - ".rubocop.yml"
106
96
  - CHANGELOG.md
107
- - CODE_OF_CONDUCT.md
108
- - CONTRIBUTING.md
109
- - Gemfile
110
97
  - LICENSE
111
98
  - README.md
112
- - Rakefile
113
- - bin/console
114
- - bin/setup
115
- - docsite/source/index.html.md
116
99
  - dry-cli.gemspec
117
100
  - lib/dry/cli.rb
118
101
  - lib/dry/cli/banner.rb
@@ -127,13 +110,14 @@ files:
127
110
  - lib/dry/cli/usage.rb
128
111
  - lib/dry/cli/utils/files.rb
129
112
  - lib/dry/cli/version.rb
130
- - script/ci
131
- homepage: http://dry-rb.org
113
+ homepage: https://dry-rb.org/gems/dry-cli
132
114
  licenses:
133
115
  - MIT
134
116
  metadata:
135
117
  allowed_push_host: https://rubygems.org
118
+ changelog_uri: https://github.com/dry-rb/dry-cli/blob/master/CHANGELOG.md
136
119
  source_code_uri: https://github.com/dry-rb/dry-cli
120
+ bug_tracker_uri: https://github.com/dry-rb/dry-cli/issues
137
121
  post_install_message:
138
122
  rdoc_options: []
139
123
  require_paths:
@@ -142,15 +126,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
126
  requirements:
143
127
  - - ">="
144
128
  - !ruby/object:Gem::Version
145
- version: '0'
129
+ version: 2.4.0
146
130
  required_rubygems_version: !ruby/object:Gem::Requirement
147
131
  requirements:
148
132
  - - ">="
149
133
  - !ruby/object:Gem::Version
150
134
  version: '0'
151
135
  requirements: []
152
- rubygems_version: 3.0.6
136
+ rubygems_version: 3.0.3
153
137
  signing_key:
154
138
  specification_version: 4
155
- summary: Dry CLI
139
+ summary: Common framework to build command line interfaces with Ruby
156
140
  test_files: []
@@ -1,12 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- version: "2"
4
-
5
- exclude_patterns:
6
- - "benchmarks/"
7
- - "examples/"
8
- - "spec/"
9
-
10
- plugins:
11
- rubocop:
12
- enabled: true
@@ -1,10 +0,0 @@
1
- ---
2
- name: "⚠️ Please don't ask for support via issues"
3
- about: See CONTRIBUTING.md for more information
4
- title: ''
5
- labels: ''
6
- assignees: ''
7
-
8
- ---
9
-
10
-
@@ -1,30 +0,0 @@
1
- ---
2
- name: "\U0001F41B Bug report"
3
- about: See CONTRIBUTING.md for more information
4
- title: ''
5
- labels: bug
6
- assignees: ''
7
-
8
- ---
9
-
10
- **Before you submit this: WE ONLY ACCEPT BUG REPORTS AND FEATURE REQUESTS**
11
-
12
- For more information see `CONTRIBUTING.md`.
13
-
14
- **Describe the bug**
15
-
16
- A clear and concise description of what the bug is.
17
-
18
- **To Reproduce**
19
-
20
- Provide detailed steps to reproduce, an executable script would be best.
21
-
22
- **Expected behavior**
23
-
24
- A clear and concise description of what you expected to happen.
25
-
26
- **Your environment**
27
-
28
- - Affects my production application: **YES/NO**
29
- - Ruby version: ...
30
- - OS: ...
@@ -1,18 +0,0 @@
1
- ---
2
- name: "\U0001F6E0 Feature request"
3
- about: See CONTRIBUTING.md for more information
4
- title: ''
5
- labels: feature
6
- assignees: ''
7
-
8
- ---
9
-
10
- Summary of what the feature is supposed to do.
11
-
12
- ## Examples
13
-
14
- Code examples showing how the feature could be used.
15
-
16
- ## Resources
17
-
18
- Additional information, like a link to the discussion forum thread where the feature was discussed etc.
@@ -1,77 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- name: ci
4
-
5
- on:
6
- push:
7
- paths:
8
- - .github/workflows/ci.yml
9
- - lib/**
10
- - spec/**
11
- - Gemfile
12
- - "*.gemspec"
13
- pull_request:
14
- branches:
15
- - master
16
-
17
- jobs:
18
- tests-mri:
19
- runs-on: ubuntu-latest
20
- strategy:
21
- fail-fast: false
22
- matrix:
23
- ruby: ["2.6.x", "2.5.x", "2.4.x"]
24
- include:
25
- - ruby: "2.6.x"
26
- coverage: "true"
27
- steps:
28
- - uses: actions/checkout@v1
29
- - name: Set up Ruby
30
- uses: actions/setup-ruby@v1
31
- with:
32
- ruby-version: ${{matrix.ruby}}
33
- - name: Download test reporter
34
- if: "matrix.coverage == 'true'"
35
- run: |
36
- mkdir -p tmp/
37
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./tmp/cc-test-reporter
38
- chmod +x ./tmp/cc-test-reporter
39
- ./tmp/cc-test-reporter before-build
40
- - name: Run all tests
41
- env:
42
- COVERAGE: ${{matrix.coverage}}
43
- run: |
44
- gem install bundler
45
- bundle install --jobs 4 --retry 3 --without tools docs benchmarks
46
- script/ci
47
- - name: Send coverage results
48
- if: "matrix.coverage == 'true'"
49
- env:
50
- CC_TEST_REPORTER_ID: ${{secrets.CC_TEST_REPORTER_ID}}
51
- GIT_COMMIT_SHA: ${{github.sha}}
52
- GIT_BRANCH: ${{github.ref}}
53
- GIT_COMMITTED_AT: ${{github.event.head_commit.timestamp}}
54
- run: |
55
- GIT_BRANCH=`ruby -e "puts ENV['GITHUB_REF'].split('/', 3).last"` \
56
- GIT_COMMITTED_AT=`ruby -r time -e "puts Time.iso8601(ENV['GIT_COMMITTED_AT']).to_i"` \
57
- ./tmp/cc-test-reporter after-build
58
-
59
- tests-others:
60
- runs-on: ubuntu-latest
61
- strategy:
62
- fail-fast: false
63
- matrix:
64
- image: ["jruby:9.2.8", "ruby:rc"]
65
- container:
66
- image: ${{matrix.image}}
67
- steps:
68
- - uses: actions/checkout@v1
69
- - name: Install git
70
- run: |
71
- apt-get update
72
- apt-get install -y --no-install-recommends git
73
- - name: Run all tests
74
- run: |
75
- gem install bundler
76
- bundle install --jobs 4 --retry 3 --without tools docs benchmarks
77
- script/ci
@@ -1,34 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- name: docsite
4
-
5
- on:
6
- push:
7
- paths:
8
- - docsite/**
9
- - .github/workflows/docsite.yml
10
- branches:
11
- - master
12
- - release-**
13
- tags:
14
-
15
- jobs:
16
- update-docs:
17
- runs-on: ubuntu-latest
18
- steps:
19
- - uses: actions/checkout@v1
20
- - name: Set up Ruby
21
- uses: actions/setup-ruby@v1
22
- with:
23
- ruby-version: "2.6.x"
24
- - name: Install dependencies
25
- run: |
26
- gem install bundler
27
- bundle install --jobs 4 --retry 3 --without benchmarks sql
28
- - name: Symlink ossy
29
- run: mkdir -p bin && ln -sf "$(bundle show ossy)/bin/ossy" bin/ossy
30
- - name: Trigger dry-rb.org deploy
31
- env:
32
- GITHUB_LOGIN: dry-bot
33
- GITHUB_TOKEN: ${{ secrets.GH_PAT }}
34
- run: bin/ossy github workflow dry-rb/dry-rb.org ci
@@ -1,34 +0,0 @@
1
- # this file is managed by dry-rb/devtools project
2
-
3
- name: sync_configs
4
-
5
- on:
6
- repository_dispatch:
7
-
8
- jobs:
9
- sync-configs:
10
- runs-on: ubuntu-latest
11
- if: github.event.action == 'sync_configs'
12
- steps:
13
- - uses: actions/checkout@v1
14
- - name: Update configuration files from devtools
15
- env:
16
- GITHUB_LOGIN: dry-bot
17
- GITHUB_TOKEN: ${{ secrets.GH_PAT }}
18
- run: |
19
- git clone https://github.com/dry-rb/devtools.git tmp/devtools
20
-
21
- if [ -f ".github/workflows/custom_ci.yml" ]; then
22
- rsync -av --exclude '.github/workflows/ci.yml' tmp/devtools/shared/ . ;
23
- else
24
- rsync -av tmp/devtools/shared/ . ;
25
- fi
26
-
27
- git config --local user.email "dry-bot@dry-rb.org"
28
- git config --local user.name "dry-bot"
29
- git add -A
30
- git commit -m "[devtools] config sync" || echo "nothing changed"
31
- - name: Push changes
32
- uses: ad-m/github-push-action@master
33
- with:
34
- github_token: ${{ secrets.GH_PAT }}