hanami-cli 0.2.0 → 0.3.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +141 -0
- data/.travis.yml +14 -4
- data/CHANGELOG.md +10 -0
- data/Gemfile +2 -2
- data/README.md +123 -5
- data/Rakefile +2 -6
- data/hanami-cli.gemspec +1 -2
- data/lib/hanami/cli/errors.rb +15 -3
- data/lib/hanami/cli/option.rb +8 -1
- data/lib/hanami/cli/parser.rb +31 -11
- data/lib/hanami/cli/registry.rb +3 -3
- data/lib/hanami/cli/version.rb +1 -1
- data/script/ci +35 -25
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e22967d2b79f1c565c5cc1be2b0709047c64dbd6b782d638f44c4d8f7c14b65
|
4
|
+
data.tar.gz: 0dad224cf8f6ffbb79ce75d2a7fe027fd417122b2d1624a40a3fa2f488c5de9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36e121113579eaf44a73ad62f3b129d852b6f8d4dfcd27e1470f0c14a3c3c8e1e8c257bc8168de631ea4944d5b593810ddf27bf2e87934cbe89e301f7422801d
|
7
|
+
data.tar.gz: 3bb1ed5b1efaf1b977a602d1ee5958652b0f65cb5d2f6138e528c2d8d5fcd18dbf89f8c85daca5bb39f7a67102bd4ff2ae470893e870be67ae1e19d59964c951
|
@@ -0,0 +1,141 @@
|
|
1
|
+
# Ruby CircleCI 2.0 configuration file
|
2
|
+
#
|
3
|
+
# Check https://circleci.com/docs/2.0/language-ruby/ for more details
|
4
|
+
#
|
5
|
+
version: 2
|
6
|
+
jobs:
|
7
|
+
"ruby-2.3":
|
8
|
+
docker:
|
9
|
+
- image: hanami/ruby-2.3
|
10
|
+
working_directory: ~/hanami-utils
|
11
|
+
steps:
|
12
|
+
- checkout
|
13
|
+
# Download and cache dependencies
|
14
|
+
- restore_cache:
|
15
|
+
keys:
|
16
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
17
|
+
# fallback to using the latest cache if no exact match is found
|
18
|
+
- v1-dependencies-
|
19
|
+
- run:
|
20
|
+
name: install dependencies
|
21
|
+
command: |
|
22
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
23
|
+
- save_cache:
|
24
|
+
paths:
|
25
|
+
- ./vendor/bundle
|
26
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
27
|
+
# run tests!
|
28
|
+
- run:
|
29
|
+
name: run tests
|
30
|
+
command: |
|
31
|
+
./script/ci
|
32
|
+
"ruby-2.4":
|
33
|
+
docker:
|
34
|
+
- image: hanami/ruby-2.4
|
35
|
+
working_directory: ~/hanami-utils
|
36
|
+
steps:
|
37
|
+
- checkout
|
38
|
+
# Download and cache dependencies
|
39
|
+
- restore_cache:
|
40
|
+
keys:
|
41
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
42
|
+
# fallback to using the latest cache if no exact match is found
|
43
|
+
- v1-dependencies-
|
44
|
+
- run:
|
45
|
+
name: install dependencies
|
46
|
+
command: |
|
47
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
48
|
+
- save_cache:
|
49
|
+
paths:
|
50
|
+
- ./vendor/bundle
|
51
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
52
|
+
# run tests!
|
53
|
+
- run:
|
54
|
+
name: run tests
|
55
|
+
command: |
|
56
|
+
./script/ci
|
57
|
+
"ruby-2.5":
|
58
|
+
docker:
|
59
|
+
- image: hanami/ruby-2.5
|
60
|
+
working_directory: ~/hanami-utils
|
61
|
+
steps:
|
62
|
+
- checkout
|
63
|
+
# Download and cache dependencies
|
64
|
+
- restore_cache:
|
65
|
+
keys:
|
66
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
67
|
+
# fallback to using the latest cache if no exact match is found
|
68
|
+
- v1-dependencies-
|
69
|
+
- run:
|
70
|
+
name: install dependencies
|
71
|
+
command: |
|
72
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
73
|
+
- save_cache:
|
74
|
+
paths:
|
75
|
+
- ./vendor/bundle
|
76
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
77
|
+
# run tests!
|
78
|
+
- run:
|
79
|
+
name: run tests
|
80
|
+
command: |
|
81
|
+
./script/ci
|
82
|
+
"jruby-9.1":
|
83
|
+
docker:
|
84
|
+
- image: hanami/jruby-9.1
|
85
|
+
working_directory: ~/hanami-utils
|
86
|
+
steps:
|
87
|
+
- checkout
|
88
|
+
# Download and cache dependencies
|
89
|
+
- restore_cache:
|
90
|
+
keys:
|
91
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
92
|
+
# fallback to using the latest cache if no exact match is found
|
93
|
+
- v1-dependencies-
|
94
|
+
- run:
|
95
|
+
name: install dependencies
|
96
|
+
command: |
|
97
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
98
|
+
- save_cache:
|
99
|
+
paths:
|
100
|
+
- ./vendor/bundle
|
101
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
102
|
+
# run tests!
|
103
|
+
- run:
|
104
|
+
name: run tests
|
105
|
+
command: |
|
106
|
+
./script/ci
|
107
|
+
"jruby-9.2":
|
108
|
+
docker:
|
109
|
+
- image: hanami/jruby-9.2
|
110
|
+
working_directory: ~/hanami-utils
|
111
|
+
steps:
|
112
|
+
- checkout
|
113
|
+
# Download and cache dependencies
|
114
|
+
- restore_cache:
|
115
|
+
keys:
|
116
|
+
- v1-dependencies-{{ checksum "Gemfile.lock" }}
|
117
|
+
# fallback to using the latest cache if no exact match is found
|
118
|
+
- v1-dependencies-
|
119
|
+
- run:
|
120
|
+
name: install dependencies
|
121
|
+
command: |
|
122
|
+
bundle install --jobs=4 --retry=3 --path vendor/bundle
|
123
|
+
- save_cache:
|
124
|
+
paths:
|
125
|
+
- ./vendor/bundle
|
126
|
+
key: v1-dependencies-{{ checksum "Gemfile.lock" }}
|
127
|
+
# run tests!
|
128
|
+
- run:
|
129
|
+
name: run tests
|
130
|
+
command: |
|
131
|
+
./script/ci
|
132
|
+
|
133
|
+
workflows:
|
134
|
+
version: 2
|
135
|
+
build:
|
136
|
+
jobs:
|
137
|
+
- "ruby-2.3"
|
138
|
+
- "ruby-2.4"
|
139
|
+
- "ruby-2.5"
|
140
|
+
- "jruby-9.1"
|
141
|
+
- "jruby-9.2"
|
data/.travis.yml
CHANGED
@@ -1,16 +1,26 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
|
+
before_script:
|
5
|
+
- gem update --system
|
4
6
|
script: ./script/ci
|
5
7
|
rvm:
|
6
|
-
- 2.
|
7
|
-
- 2.
|
8
|
-
- 2.5.
|
8
|
+
- 2.4.4
|
9
|
+
- 2.3.7
|
10
|
+
- 2.5.1
|
11
|
+
- jruby-9.1.9.0
|
9
12
|
- ruby-head
|
10
|
-
- jruby-9.1.13.0
|
11
13
|
- jruby-head
|
12
14
|
|
13
15
|
matrix:
|
14
16
|
allow_failures:
|
15
17
|
- rvm: ruby-head
|
16
18
|
- rvm: jruby-head
|
19
|
+
|
20
|
+
notifications:
|
21
|
+
webhooks:
|
22
|
+
urls:
|
23
|
+
- https://webhooks.gitter.im/e/fde2367248d53de4fe70
|
24
|
+
on_success: change # options: [always|never|change] default: always
|
25
|
+
on_failure: always # options: [always|never|change] default: always
|
26
|
+
on_start: never # options: [always|never|change] default: always
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
# Hanami::CLI
|
2
2
|
General purpose Command Line Interface (CLI) framework for Ruby
|
3
3
|
|
4
|
+
## v0.3.0.beta1 - 2018-08-08
|
5
|
+
### Added
|
6
|
+
- [Anton Davydov & Alfonso Uceda] Introduce array type for arguments (`foo exec test spec/bookshelf/entities spec/bookshelf/repositories`)
|
7
|
+
- [Anton Davydov & Alfonso Uceda] Introduce array type for options (`foo generate config --apps=web,api`)
|
8
|
+
- [Alfonso Uceda] Introduce variadic arguments (`foo run ruby:latest -- ruby -v`)
|
9
|
+
- [Luca Guidi] Official support for JRuby 9.2.0.0
|
10
|
+
|
11
|
+
### Fixed
|
12
|
+
- [Anton Davydov] Print informative message when unknown or wrong option is passed (`"test" was called with arguments "--framework=unknown"`)
|
13
|
+
|
4
14
|
## v0.2.0 - 2018-04-11
|
5
15
|
|
6
16
|
## v0.2.0.rc2 - 2018-04-06
|
data/Gemfile
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
unless ENV['
|
4
|
+
unless ENV['CI']
|
5
5
|
gem 'byebug', require: false, platforms: :mri
|
6
6
|
gem 'yard', require: false
|
7
7
|
end
|
8
8
|
|
9
|
-
gem 'hanami-utils', '~> 1.
|
9
|
+
gem 'hanami-utils', '~> 1.3.beta', require: false, git: 'https://github.com/hanami/utils.git', branch: 'develop'
|
10
10
|
|
11
11
|
gem 'hanami-devtools', require: false, git: 'https://github.com/hanami/devtools.git'
|
data/README.md
CHANGED
@@ -4,6 +4,44 @@ General purpose Command Line Interface (CLI) framework for Ruby.
|
|
4
4
|
|
5
5
|
:warning: **This is a general framework for Ruby (aka `thor` gem replacement), NOT the implementation of the `hanami` CLI commands** :warning:
|
6
6
|
|
7
|
+
## Status
|
8
|
+
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/hanami-cli.svg)](https://badge.fury.io/rb/hanami-cli)
|
10
|
+
[![TravisCI](https://travis-ci.org/hanami/cli.svg?branch=master)](https://travis-ci.org/hanami/cli)
|
11
|
+
[![CircleCI](https://circleci.com/gh/hanami/cli/tree/master.svg?style=svg)](https://circleci.com/gh/hanami/cli/tree/master)
|
12
|
+
[![Test Coverage](https://codecov.io/gh/hanami/cli/branch/master/graph/badge.svg)](https://codecov.io/gh/hanami/cli)
|
13
|
+
[![Depfu](https://badges.depfu.com/badges/2c1bc076f16c6b5508334c44b5800362/overview.svg)](https://depfu.com/github/hanami/cli?project=Bundler)
|
14
|
+
[![Inline Docs](http://inch-ci.org/github/hanami/cli.svg)](http://inch-ci.org/github/hanami/cli)
|
15
|
+
|
16
|
+
## Contact
|
17
|
+
|
18
|
+
* Home page: http://hanamirb.org
|
19
|
+
* Mailing List: http://hanamirb.org/mailing-list
|
20
|
+
* API Doc: http://rdoc.info/gems/hanami-utils
|
21
|
+
* Bugs/Issues: https://github.com/hanami/utils/issues
|
22
|
+
* Support: http://stackoverflow.com/questions/tagged/hanami
|
23
|
+
* Chat: http://chat.hanamirb.org
|
24
|
+
|
25
|
+
## Rubies
|
26
|
+
|
27
|
+
__Hanami::Utils__ supports Ruby (MRI) 2.3+, JRuby 9.1.5.0+
|
28
|
+
|
29
|
+
## Installation
|
30
|
+
|
31
|
+
Add this line to your application's Gemfile:
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'hanami-utils'
|
35
|
+
```
|
36
|
+
|
37
|
+
And then execute:
|
38
|
+
|
39
|
+
$ bundle
|
40
|
+
|
41
|
+
Or install it yourself as:
|
42
|
+
|
43
|
+
$ gem install hanami-utils
|
44
|
+
|
7
45
|
<!-- Tocer[start]: Auto-generated, don't remove. -->
|
8
46
|
|
9
47
|
## Table of Contents
|
@@ -14,6 +52,7 @@ General purpose Command Line Interface (CLI) framework for Ruby.
|
|
14
52
|
- [Subcommands](#subcommands)
|
15
53
|
- [Arguments](#arguments)
|
16
54
|
- [Option](#option)
|
55
|
+
- [Variadic arguments](#variadic-arguments)
|
17
56
|
- [Installation](#installation)
|
18
57
|
- [Usage](#usage)
|
19
58
|
- [Available commands](#available-commands)
|
@@ -22,6 +61,7 @@ General purpose Command Line Interface (CLI) framework for Ruby.
|
|
22
61
|
- [Required arguments](#required-arguments)
|
23
62
|
- [Options](#options)
|
24
63
|
- [Boolean options](#boolean-options)
|
64
|
+
- [Array options](#array-options)
|
25
65
|
- [Subcommands](#subcommands-1)
|
26
66
|
- [Aliases](#aliases)
|
27
67
|
- [Subcommand aliases](#subcommand-aliases)
|
@@ -204,9 +244,50 @@ Performing a request (mode: http2)
|
|
204
244
|
|
205
245
|
```shell
|
206
246
|
% foo request --mode=unknown
|
207
|
-
Error:
|
247
|
+
Error: "request" was called with arguments "--mode=unknown"
|
208
248
|
```
|
209
249
|
|
250
|
+
### Variadic arguments
|
251
|
+
|
252
|
+
Sometimes we need extra arguments because those will be forwarded to a sub-command like `ssh`, `docker` or `cat`.
|
253
|
+
|
254
|
+
By using `--` (double dash, aka hypen), the user indicates the end of the arguments and options belonging to the main command, and the beginning of the variadic arguments that can be forwarded to the sub-command.
|
255
|
+
These extra arguments are included as `:args` in the keyword arguments available for each command.
|
256
|
+
|
257
|
+
```ruby
|
258
|
+
#!/usr/bin/env ruby
|
259
|
+
require "bundler/setup"
|
260
|
+
require "hanami/cli"
|
261
|
+
|
262
|
+
module Foo
|
263
|
+
module CLI
|
264
|
+
module Commands
|
265
|
+
extend Hanami::CLI::Registry
|
266
|
+
|
267
|
+
class Runner < Hanami::CLI::Command
|
268
|
+
argument :image, required: true, desc: "Docker image"
|
269
|
+
|
270
|
+
def call(image:, args: [], **)
|
271
|
+
puts `docker run -it --rm #{image} #{args.join(" ")}`
|
272
|
+
end
|
273
|
+
end
|
274
|
+
|
275
|
+
register "run", Runner
|
276
|
+
end
|
277
|
+
end
|
278
|
+
end
|
279
|
+
|
280
|
+
Hanami::CLI.new(Foo::CLI::Commands).call
|
281
|
+
```
|
282
|
+
|
283
|
+
```shell
|
284
|
+
% foo run ruby:latest -- ruby -v
|
285
|
+
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
|
286
|
+
```
|
287
|
+
|
288
|
+
The user separates via `--` the arguments for `foo` and the command has to be run by the Docker container.
|
289
|
+
In this specific case, `ruby:latest` corresponds to the `image` mandatory argument for `foo`, whereas `ruby -v` is the variadic argument that is passed to Docker via `args`.
|
290
|
+
|
210
291
|
## Installation
|
211
292
|
|
212
293
|
Add this line to your application's Gemfile:
|
@@ -288,12 +369,25 @@ module Foo
|
|
288
369
|
end
|
289
370
|
end
|
290
371
|
|
372
|
+
class Exec < Hanami::CLI::Command
|
373
|
+
desc "Execute a task"
|
374
|
+
|
375
|
+
argument :task, type: :string, required: true, desc: "Task to be executed"
|
376
|
+
argument :dirs, type: :array, required: false, desc: "Optional directories"
|
377
|
+
|
378
|
+
def call(task:, dirs: [], **)
|
379
|
+
puts "exec - task: #{task}, dirs: #{dirs.inspect}"
|
380
|
+
end
|
381
|
+
end
|
382
|
+
|
291
383
|
module Generate
|
292
384
|
class Configuration < Hanami::CLI::Command
|
293
385
|
desc "Generate configuration"
|
294
386
|
|
295
|
-
|
296
|
-
|
387
|
+
option :apps, type: :array, default: [], desc: "Generate configuration for specific apps"
|
388
|
+
|
389
|
+
def call(apps:, **)
|
390
|
+
puts "generated configuration for apps: #{apps.inspect}"
|
297
391
|
end
|
298
392
|
end
|
299
393
|
|
@@ -312,6 +406,7 @@ module Foo
|
|
312
406
|
register "echo", Echo
|
313
407
|
register "start", Start
|
314
408
|
register "stop", Stop
|
409
|
+
register "exec", Exec
|
315
410
|
|
316
411
|
register "generate", aliases: ["g"] do |prefix|
|
317
412
|
prefix.register "config", Generate::Configuration
|
@@ -332,6 +427,7 @@ Let's have a look at the command line usage.
|
|
332
427
|
% foo
|
333
428
|
Commands:
|
334
429
|
foo echo [INPUT] # Print input
|
430
|
+
foo exec TASK [DIRS] # Execute a task
|
335
431
|
foo generate [SUBCOMMAND]
|
336
432
|
foo start ROOT # Start Foo machinery
|
337
433
|
foo stop # Stop Foo machinery
|
@@ -385,6 +481,21 @@ ERROR: "foo start" was called with no arguments
|
|
385
481
|
Usage: "foo start ROOT"
|
386
482
|
```
|
387
483
|
|
484
|
+
### Array arguments
|
485
|
+
|
486
|
+
Captures all the remaining arguments in a single array.
|
487
|
+
Please note that `array` argument must be used as last argument as it works as a _"catch-all"_.
|
488
|
+
|
489
|
+
```shell
|
490
|
+
% foo exec test
|
491
|
+
exec - task: test, dirs: []
|
492
|
+
```
|
493
|
+
|
494
|
+
```shell
|
495
|
+
% foo exec test spec/bookshelf/entities spec/bookshelf/repositories
|
496
|
+
exec - task: test, dirs: ["spec/bookshelf/entities", "spec/bookshelf/repositories"]
|
497
|
+
```
|
498
|
+
|
388
499
|
### Options
|
389
500
|
|
390
501
|
```shell
|
@@ -399,7 +510,7 @@ generated tests - framework: rspec
|
|
399
510
|
|
400
511
|
```shell
|
401
512
|
% foo generate test --framework=unknown
|
402
|
-
Error:
|
513
|
+
Error: "test" was called with arguments "--framework=unknown"
|
403
514
|
```
|
404
515
|
|
405
516
|
### Boolean options
|
@@ -414,6 +525,13 @@ stopped - graceful: true
|
|
414
525
|
stopped - graceful: false
|
415
526
|
```
|
416
527
|
|
528
|
+
### Array options
|
529
|
+
|
530
|
+
```shell
|
531
|
+
% foo generate config --apps=web,api
|
532
|
+
generated configuration for apps: ["web", "api"]
|
533
|
+
```
|
534
|
+
|
417
535
|
### Subcommands
|
418
536
|
|
419
537
|
```shell
|
@@ -449,7 +567,7 @@ Commands:
|
|
449
567
|
|
450
568
|
```shell
|
451
569
|
% foo g config
|
452
|
-
generated configuration
|
570
|
+
generated configuration for apps: []
|
453
571
|
```
|
454
572
|
|
455
573
|
### Callbacks
|
data/Rakefile
CHANGED
@@ -1,19 +1,15 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require 'rake/testtask'
|
3
2
|
require 'bundler/gem_tasks'
|
4
3
|
require 'rspec/core/rake_task'
|
4
|
+
require 'hanami/devtools/rake_tasks'
|
5
5
|
|
6
6
|
namespace :spec do
|
7
7
|
RSpec::Core::RakeTask.new(:unit) do |task|
|
8
8
|
file_list = FileList['spec/**/*_spec.rb']
|
9
|
+
file_list = file_list.exclude("spec/{integration,isolation}/**/*_spec.rb")
|
9
10
|
|
10
11
|
task.pattern = file_list
|
11
12
|
end
|
12
|
-
|
13
|
-
task :coverage do
|
14
|
-
ENV['COVERAGE'] = 'true'
|
15
|
-
Rake::Task['spec:unit'].invoke
|
16
|
-
end
|
17
13
|
end
|
18
14
|
|
19
15
|
task default: 'spec:unit'
|
data/hanami-cli.gemspec
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
lib = File.expand_path('../lib', __FILE__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'hanami/cli/version'
|
@@ -25,7 +24,7 @@ Gem::Specification.new do |spec|
|
|
25
24
|
f.match(%r{^(test|spec|features)/})
|
26
25
|
end
|
27
26
|
|
28
|
-
spec.add_dependency "hanami-utils", "~> 1.
|
27
|
+
spec.add_dependency "hanami-utils", "~> 1.3.beta"
|
29
28
|
spec.add_dependency "concurrent-ruby", "~> 1.0"
|
30
29
|
|
31
30
|
spec.add_development_dependency "bundler"
|
data/lib/hanami/cli/errors.rb
CHANGED
@@ -1,12 +1,17 @@
|
|
1
|
+
require "hanami/utils/deprecation"
|
2
|
+
|
1
3
|
module Hanami
|
4
|
+
# General purpose Command Line Interface (CLI) framework for Ruby
|
5
|
+
#
|
6
|
+
# @since 0.1.0
|
2
7
|
class CLI
|
3
8
|
# @since 0.2.0
|
4
9
|
class Error < StandardError
|
5
10
|
end
|
6
11
|
|
7
|
-
# @since 0.2.
|
8
|
-
class
|
9
|
-
# @since 0.2.
|
12
|
+
# @since 0.2.1
|
13
|
+
class UnknownCommandError < Error
|
14
|
+
# @since 0.2.1
|
10
15
|
# @api private
|
11
16
|
def initialize(command_name)
|
12
17
|
super("unknown command: `#{command_name}'")
|
@@ -28,5 +33,12 @@ module Hanami
|
|
28
33
|
super(message)
|
29
34
|
end
|
30
35
|
end
|
36
|
+
|
37
|
+
# @since 0.2.1
|
38
|
+
def self.const_missing(name)
|
39
|
+
super unless name == :UnkwnownCommandError
|
40
|
+
Hanami::Utils::Deprecation.new('UnkwnownCommandError is deprecated, please use UnknownCommandError')
|
41
|
+
UnknownCommandError
|
42
|
+
end
|
31
43
|
end
|
32
44
|
end
|
data/lib/hanami/cli/option.rb
CHANGED
@@ -59,6 +59,12 @@ module Hanami
|
|
59
59
|
type == :boolean
|
60
60
|
end
|
61
61
|
|
62
|
+
# @since 0.3.0
|
63
|
+
# @api private
|
64
|
+
def array?
|
65
|
+
type == :array
|
66
|
+
end
|
67
|
+
|
62
68
|
# @since 0.1.0
|
63
69
|
# @api private
|
64
70
|
def default
|
@@ -86,13 +92,14 @@ module Hanami
|
|
86
92
|
dasherized_name = Hanami::Utils::String.dasherize(name)
|
87
93
|
parser_options = []
|
88
94
|
|
89
|
-
if
|
95
|
+
if boolean?
|
90
96
|
parser_options << "--[no-]#{dasherized_name}"
|
91
97
|
else
|
92
98
|
parser_options << "--#{dasherized_name}=#{name}"
|
93
99
|
parser_options << "--#{dasherized_name} #{name}"
|
94
100
|
end
|
95
101
|
|
102
|
+
parser_options << Array if array?
|
96
103
|
parser_options << values if values
|
97
104
|
parser_options.unshift(alias_name) unless alias_name.nil?
|
98
105
|
parser_options << desc if desc
|
data/lib/hanami/cli/parser.rb
CHANGED
@@ -11,8 +11,9 @@ module Hanami
|
|
11
11
|
# @since 0.1.0
|
12
12
|
# @api private
|
13
13
|
#
|
14
|
-
# rubocop:disable Metrics/MethodLength
|
14
|
+
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
|
15
15
|
def self.call(command, arguments, names)
|
16
|
+
original_arguments = arguments.dup
|
16
17
|
parsed_options = {}
|
17
18
|
|
18
19
|
OptionParser.new do |opts|
|
@@ -30,9 +31,9 @@ module Hanami
|
|
30
31
|
parsed_options = command.default_params.merge(parsed_options)
|
31
32
|
parse_required_params(command, arguments, names, parsed_options)
|
32
33
|
rescue ::OptionParser::ParseError
|
33
|
-
Result.failure
|
34
|
+
Result.failure("Error: \"#{command.command_name}\" was called with arguments \"#{original_arguments.join(' ')}\"")
|
34
35
|
end
|
35
|
-
# rubocop:enable Metrics/MethodLength
|
36
|
+
# rubocop:enable Metrics/MethodLength, Metrics/AbcSize
|
36
37
|
|
37
38
|
# @since 0.1.0
|
38
39
|
# @api private
|
@@ -46,28 +47,47 @@ module Hanami
|
|
46
47
|
# rubocop:disable Metrics/AbcSize
|
47
48
|
# rubocop:disable Metrics/MethodLength
|
48
49
|
def self.parse_required_params(command, arguments, names, parsed_options)
|
49
|
-
|
50
|
-
|
51
|
-
all_required_params_satisfied = command.required_arguments.all? { |param| !
|
50
|
+
parsed_params = match_arguments(command.arguments, arguments)
|
51
|
+
parsed_required_params = match_arguments(command.required_arguments, arguments)
|
52
|
+
all_required_params_satisfied = command.required_arguments.all? { |param| !parsed_required_params[param.name].nil? }
|
53
|
+
|
54
|
+
unused_arguments = arguments.drop(command.required_arguments.length)
|
52
55
|
|
53
56
|
unless all_required_params_satisfied
|
54
|
-
|
57
|
+
parsed_required_params_values = parsed_required_params.values.compact
|
55
58
|
|
56
59
|
usage = "\nUsage: \"#{full_command_name(names)} #{command.required_arguments.map(&:description_name).join(' ')}\""
|
57
60
|
|
58
|
-
if
|
61
|
+
if parsed_required_params_values.empty? # rubocop:disable Style/GuardClause
|
59
62
|
return Result.failure("ERROR: \"#{full_command_name(names)}\" was called with no arguments#{usage}")
|
60
63
|
else
|
61
|
-
return Result.failure("ERROR: \"#{full_command_name(names)}\" was called with arguments #{
|
64
|
+
return Result.failure("ERROR: \"#{full_command_name(names)}\" was called with arguments #{parsed_required_params_values}#{usage}")
|
62
65
|
end
|
63
66
|
end
|
64
67
|
|
65
|
-
|
66
|
-
|
68
|
+
parsed_params.reject! { |_key, value| value.nil? }
|
69
|
+
parsed_options = parsed_options.merge(parsed_params)
|
70
|
+
parsed_options = parsed_options.merge(args: unused_arguments) if unused_arguments.any?
|
71
|
+
Result.success(parsed_options)
|
67
72
|
end
|
68
73
|
# rubocop:enable Metrics/MethodLength
|
69
74
|
# rubocop:enable Metrics/AbcSize
|
70
75
|
|
76
|
+
def self.match_arguments(command_arguments, arguments)
|
77
|
+
result = {}
|
78
|
+
|
79
|
+
command_arguments.each_with_index do |cmd_arg, index|
|
80
|
+
if cmd_arg.array?
|
81
|
+
result[cmd_arg.name] = arguments[index..-1]
|
82
|
+
break
|
83
|
+
else
|
84
|
+
result[cmd_arg.name] = arguments.at(index)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
result
|
89
|
+
end
|
90
|
+
|
71
91
|
# @since 0.1.0
|
72
92
|
# @api private
|
73
93
|
class Result
|
data/lib/hanami/cli/registry.rb
CHANGED
@@ -87,7 +87,7 @@ module Hanami
|
|
87
87
|
# it MUST respond to `#call`.
|
88
88
|
# @param blk [Proc] the callback espressed as a block
|
89
89
|
#
|
90
|
-
# @raise [Hanami::CLI::
|
90
|
+
# @raise [Hanami::CLI::UnknownCommandError] if the command isn't registered
|
91
91
|
# @raise [Hanami::CLI::InvalidCallbackError] if the given callback doesn't
|
92
92
|
# implement the required interface
|
93
93
|
#
|
@@ -173,7 +173,7 @@ module Hanami
|
|
173
173
|
# it MUST respond to `#call`.
|
174
174
|
# @param blk [Proc] the callback espressed as a block
|
175
175
|
#
|
176
|
-
# @raise [Hanami::CLI::
|
176
|
+
# @raise [Hanami::CLI::UnknownCommandError] if the command isn't registered
|
177
177
|
# @raise [Hanami::CLI::InvalidCallbackError] if the given callback doesn't
|
178
178
|
# implement the required interface
|
179
179
|
#
|
@@ -266,7 +266,7 @@ module Hanami
|
|
266
266
|
# @api private
|
267
267
|
def command(command_name)
|
268
268
|
get(command_name.split(COMMAND_NAME_SEPARATOR)).tap do |result|
|
269
|
-
raise
|
269
|
+
raise UnknownCommandError.new(command_name) unless result.found?
|
270
270
|
end
|
271
271
|
end
|
272
272
|
|
data/lib/hanami/cli/version.rb
CHANGED
data/script/ci
CHANGED
@@ -2,50 +2,60 @@
|
|
2
2
|
set -euo pipefail
|
3
3
|
IFS=$'\n\t'
|
4
4
|
|
5
|
+
prepare_build() {
|
6
|
+
if [ -d coverage ]; then
|
7
|
+
rm -rf coverage
|
8
|
+
fi
|
9
|
+
}
|
10
|
+
|
11
|
+
print_ruby_version() {
|
12
|
+
echo "Using $(ruby -v)"
|
13
|
+
echo
|
14
|
+
}
|
15
|
+
|
5
16
|
run_code_quality_checks() {
|
6
17
|
bundle exec rubocop .
|
7
18
|
}
|
8
19
|
|
9
20
|
run_unit_tests() {
|
10
|
-
bundle exec rake spec:
|
21
|
+
bundle exec rake spec:unit
|
11
22
|
}
|
12
23
|
|
13
|
-
|
24
|
+
run_integration_tests() {
|
14
25
|
local pwd=$PWD
|
15
|
-
local root="$pwd/spec/
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
done
|
28
|
-
fi
|
26
|
+
local root="$pwd/spec/integration"
|
27
|
+
|
28
|
+
for test in $(find $root -name '*_spec.rb')
|
29
|
+
do
|
30
|
+
run_test $test
|
31
|
+
|
32
|
+
if [ $? -ne 0 ]; then
|
33
|
+
local exit_code=$?
|
34
|
+
echo "Failing test: $test"
|
35
|
+
exit $exit_code
|
36
|
+
fi
|
37
|
+
done
|
29
38
|
}
|
30
39
|
|
31
|
-
|
40
|
+
run_test() {
|
32
41
|
local test=$1
|
42
|
+
local hash="$(shasum "$test" | cut -b 1-40)"
|
33
43
|
|
34
44
|
printf "\n\n\nRunning: $test\n"
|
35
|
-
|
45
|
+
SIMPLECOV_COMMAND_NAME=$hash bundle exec rspec $test
|
36
46
|
}
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
printf "\n\n\nRunning: $test\n"
|
42
|
-
COVERAGE=true bundle exec rspec $test
|
48
|
+
upload_code_coverage() {
|
49
|
+
bundle exec rake codecov:upload
|
43
50
|
}
|
44
51
|
|
45
52
|
main() {
|
46
|
-
|
53
|
+
prepare_build &&
|
54
|
+
print_ruby_version &&
|
55
|
+
run_code_quality_checks &&
|
47
56
|
run_unit_tests &&
|
48
|
-
|
57
|
+
run_integration_tests &&
|
58
|
+
upload_code_coverage
|
49
59
|
}
|
50
60
|
|
51
61
|
main
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hanami-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Luca Guidi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hanami-utils
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 1.3.beta
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 1.3.beta
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: concurrent-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,6 +87,7 @@ executables: []
|
|
87
87
|
extensions: []
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
|
+
- ".circleci/config.yml"
|
90
91
|
- ".gitignore"
|
91
92
|
- ".rspec"
|
92
93
|
- ".rubocop.yml"
|
@@ -127,12 +128,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
128
|
version: '0'
|
128
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
130
|
requirements:
|
130
|
-
- - "
|
131
|
+
- - ">"
|
131
132
|
- !ruby/object:Gem::Version
|
132
|
-
version:
|
133
|
+
version: 1.3.1
|
133
134
|
requirements: []
|
134
135
|
rubyforge_project:
|
135
|
-
rubygems_version: 2.7.
|
136
|
+
rubygems_version: 2.7.7
|
136
137
|
signing_key:
|
137
138
|
specification_version: 4
|
138
139
|
summary: Hanami CLI
|