hanami-cli 2.0.0.alpha8 → 2.0.0.beta2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -1
- data/CHANGELOG.md +68 -1
- data/Gemfile +3 -3
- data/README.md +13 -11
- data/hanami-cli.gemspec +3 -2
- data/lib/hanami/cli/bundler.rb +3 -7
- data/lib/hanami/cli/commands/app/command.rb +67 -0
- data/lib/hanami/cli/commands/{monolith → app}/console.rb +7 -6
- data/lib/hanami/cli/commands/{monolith → app}/db/create.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/create_migration.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/drop.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/migrate.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/reset.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/rollback.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/sample_data.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/seed.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/db/setup.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/structure/dump.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/db/version.rb +3 -3
- data/lib/hanami/cli/commands/{monolith → app}/generate/action.rb +12 -12
- data/lib/hanami/cli/commands/{monolith → app}/generate/slice.rb +4 -4
- data/lib/hanami/cli/commands/{monolith → app}/generate.rb +1 -1
- data/lib/hanami/cli/commands/{monolith → app}/install.rb +1 -1
- data/lib/hanami/cli/commands/app/middlewares.rb +47 -0
- data/lib/hanami/cli/commands/app/routes.rb +82 -0
- data/lib/hanami/cli/commands/app/server.rb +58 -0
- data/lib/hanami/cli/commands/{monolith → app}/version.rb +1 -1
- data/lib/hanami/cli/commands/app.rb +44 -0
- data/lib/hanami/cli/commands/db/utils/database.rb +10 -10
- data/lib/hanami/cli/commands/gem/new.rb +29 -38
- data/lib/hanami/cli/commands/gem/version.rb +21 -1
- data/lib/hanami/cli/commands/gem.rb +2 -4
- data/lib/hanami/cli/commands.rb +18 -10
- data/lib/hanami/cli/generators/app/action/action.erb +13 -0
- data/lib/hanami/cli/generators/{monolith/action/action.erb → app/action/slice_action.erb} +3 -3
- data/lib/hanami/cli/generators/{monolith → app}/action/template.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action/template.html.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action/view.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/action.rb +44 -27
- data/lib/hanami/cli/generators/{monolith → app}/action_context.rb +3 -3
- data/lib/hanami/cli/generators/{monolith → app}/slice/action.erb +0 -2
- data/lib/hanami/cli/generators/{monolith → app}/slice/entities.erb +0 -0
- data/lib/hanami/cli/generators/{gem/application/monolith → app/slice}/keep.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/repository.erb +0 -0
- data/lib/hanami/cli/generators/app/slice/routes.erb +3 -0
- data/lib/hanami/cli/generators/app/slice/slice.erb +6 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/view.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice.rb +13 -12
- data/lib/hanami/cli/generators/{monolith → app}/slice_context.rb +1 -1
- data/lib/hanami/cli/generators/context.rb +2 -2
- data/lib/hanami/cli/generators/gem/{application/monolith/entities.erb → app/action.erb} +3 -3
- data/lib/hanami/cli/generators/gem/{application/monolith/application.erb → app/app.erb} +1 -1
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/config_ru.erb +0 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/env.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/gemfile.erb +20 -0
- data/lib/hanami/cli/generators/{monolith/slice → gem/app}/keep.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/rakefile.erb +3 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/readme.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/routes.erb +9 -0
- data/lib/hanami/cli/generators/gem/app/settings.erb +11 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/types.erb +3 -2
- data/lib/hanami/cli/generators/gem/app/validator.erb +12 -0
- data/lib/hanami/cli/generators/gem/app.rb +64 -0
- data/lib/hanami/cli/generators/version.rb +55 -0
- data/lib/hanami/cli/middleware_stack_inspector.rb +41 -0
- data/lib/hanami/cli/rake_tasks.rb +54 -0
- data/lib/hanami/cli/repl/core.rb +7 -7
- data/lib/hanami/cli/server.rb +45 -0
- data/lib/hanami/cli/version.rb +1 -1
- data/lib/hanami/console/context.rb +12 -12
- data/lib/hanami/console/plugins/slice_readers.rb +3 -3
- metadata +81 -59
- data/lib/hanami/cli/commands/application.rb +0 -67
- data/lib/hanami/cli/commands/monolith.rb +0 -55
- data/lib/hanami/cli/generators/gem/application/monolith/action.erb +0 -21
- data/lib/hanami/cli/generators/gem/application/monolith/functions.erb +0 -13
- data/lib/hanami/cli/generators/gem/application/monolith/gemfile.erb +0 -19
- data/lib/hanami/cli/generators/gem/application/monolith/operation.erb +0 -18
- data/lib/hanami/cli/generators/gem/application/monolith/rakefile.erb +0 -3
- data/lib/hanami/cli/generators/gem/application/monolith/repository.erb +0 -13
- data/lib/hanami/cli/generators/gem/application/monolith/routes.erb +0 -4
- data/lib/hanami/cli/generators/gem/application/monolith/settings.erb +0 -6
- data/lib/hanami/cli/generators/gem/application/monolith/validation_contract.erb +0 -14
- data/lib/hanami/cli/generators/gem/application/monolith/view_context.erb +0 -15
- data/lib/hanami/cli/generators/gem/application/monolith.rb +0 -83
- data/lib/hanami/cli/generators/gem/application.rb +0 -21
- data/lib/hanami/cli/generators/monolith/slice/routes.erb +0 -2
- data/lib/hanami/rake_tasks.rb +0 -52
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 511daafabba67025eb83dd27f06c62a9809ab89c8901445e5c00f15bbf8fd8ca
|
4
|
+
data.tar.gz: 7d303b0c72fb47c2cf0ba107af0e6899d83b14b580565f4b30c43f4bc87ab4f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 716e634d4c572a09cd9954484d9dafc6affaafc13d03ec1e79703436b3efd305d1823dc4d35e92207b5388ebc33aef9f9ba603089cf73b3aec904957fe760bd6
|
7
|
+
data.tar.gz: e7d545d1cd6bfabcc5b4305b755c319c06a4e688e74a4639765c8f0026aac6b039d3459d670014a096ebd726b4a3192f694e273285341698b52a02b0762ae4a4
|
data/.rubocop.yml
CHANGED
@@ -7,9 +7,10 @@ inherit_from:
|
|
7
7
|
Layout/LineLength:
|
8
8
|
Exclude:
|
9
9
|
- Gemfile
|
10
|
+
- 'spec/**/*.rb'
|
10
11
|
Lint/EmptyFile:
|
11
12
|
Exclude:
|
12
|
-
-
|
13
|
+
- 'spec/fixtures/**/*.rb'
|
13
14
|
Naming/HeredocDelimiterNaming:
|
14
15
|
Enabled: false
|
15
16
|
Naming/MethodParameterName:
|
@@ -29,3 +30,5 @@ Style/TrailingCommaInArrayLiteral:
|
|
29
30
|
Enabled: false
|
30
31
|
Style/TrailingCommaInHashLiteral:
|
31
32
|
Enabled: false
|
33
|
+
Style/StringConcatenation:
|
34
|
+
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,41 +1,86 @@
|
|
1
1
|
# Hanami::CLI
|
2
|
+
|
2
3
|
Hanami Command Line Interface
|
3
4
|
|
4
|
-
## v2.0.0.
|
5
|
+
## v2.0.0.beta2 - 2022-08-16
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- [Luca Guidi] Added `hanami generate slice` command, for generating a new slice [#32]
|
10
|
+
- [Luca Guidi] Added `hanami generate action` command, for generating a new action in the app or a slice [#33]
|
11
|
+
- [Marc Busqué] Added `hanami middlewares` command, for listing middleware configed in app and/or in `config/routes.rb` [#30]
|
12
|
+
|
13
|
+
### Changed
|
14
|
+
|
15
|
+
- [Marc Busqué, Tim Riley] `hanami` command will detect the app even when called inside nested subdirectories [#34]
|
16
|
+
- [Seb Wilgosz] Include hanami-validations in generated app’s `Gemfile`, allowing action classes to specify `.params` [#31]
|
17
|
+
- [Tim Riley] Include dry-types in generated app’s `Gemfile`, which is used by the types module defined in `lib/[app_name]/types.rb` (dry-types is no longer a hard dependency of the hanami gem as of 2.0.0.beta2) [#29]
|
18
|
+
- [Tim Riley] Include dotenv in generated app’s `Gemfile`, allowing `ENV` values to be loaded from `.env*` files [#29]
|
19
|
+
|
20
|
+
## v2.0.0.beta1 - 2022-07-20
|
21
|
+
|
22
|
+
### Added
|
23
|
+
|
24
|
+
- [Luca Guidi] Implemented `hanami new` to generate a new Hanami app
|
25
|
+
- [Piotr Solnica] Implemented `hanami console` to start an interactive console (REPL)
|
26
|
+
- [Marc Busqué] Implemented `hanami server` to start a HTTP server based on Rack
|
27
|
+
- [Marc Busqué] Implemented `hanami routes` to print app routes
|
28
|
+
- [Luca Guidi] Implemented `hanami version` to print app Hanami version
|
29
|
+
|
30
|
+
## v2.0.0.alpha8.1 - 2022-05-23
|
31
|
+
|
32
|
+
### Fixed
|
33
|
+
|
34
|
+
- [Tim Riley] Ensure CLI starts properly by fixing use of `Slice.slice_name`
|
35
|
+
|
36
|
+
## v2.0.0.alpha8 - 2022-05-19
|
5
37
|
|
6
38
|
### Fixed
|
39
|
+
|
7
40
|
- [Andrew Croome] Respect HANAMI_ENV env var to set Hanami env if no `--env` option is supplied
|
8
41
|
- [Lucas Mendelowski] Ensure Sequel migrations extension is loaded before related `db` commands are run
|
9
42
|
|
10
43
|
## v2.0.0.alpha7 - 2022-03-11
|
11
44
|
|
12
45
|
### Changed
|
46
|
+
|
13
47
|
- [Tim Riley] [Internal] Update console slice readers to work with new `Hanami::Application.slices` API
|
14
48
|
|
15
49
|
## v2.0.0.alpha6.1 - 2022-02-11
|
50
|
+
|
16
51
|
### Fixed
|
52
|
+
|
17
53
|
- [Viet Tran] Ensure `hanami db` commands to work with `hanami` `v2.0.0.alpha6`
|
18
54
|
|
19
55
|
## v2.0.0.alpha6 - 2022-02-10
|
56
|
+
|
20
57
|
### Added
|
58
|
+
|
21
59
|
- [Luca Guidi] Official support for Ruby: MRI 3.1
|
22
60
|
|
23
61
|
### Changed
|
62
|
+
|
24
63
|
- [Luca Guidi] Drop support for Ruby: MRI 2.6, and 2.7
|
25
64
|
|
26
65
|
## v2.0.0.alpha4 - 2021-12-07
|
66
|
+
|
27
67
|
### Added
|
68
|
+
|
28
69
|
- [Tim Riley] Display a custom prompt when using irb-based console (consistent with pry-based console)
|
29
70
|
- [Phil Arndt] Support `postgresql://` URL schemes (in addition to existing `postgres://` support) for `db` subcommands
|
30
71
|
|
31
72
|
### Fixed
|
73
|
+
|
32
74
|
- [Tim Riley] Ensure slice helper methods work in console (e.g. top-level `main` method will return `Main::Slice` if an app has a "main" slice defined)
|
33
75
|
|
34
76
|
## v2.0.0.alpha3 - 2021-11-09
|
77
|
+
|
35
78
|
No changes.
|
36
79
|
|
37
80
|
## v2.0.0.alpha2 - 2021-05-04
|
81
|
+
|
38
82
|
### Added
|
83
|
+
|
39
84
|
- [Luca Guidi] Official support for Ruby: MRI 3.0
|
40
85
|
- [Luca Guidi] Dynamically change the set of available commands depending on the context (outside or inside an Hanami app)
|
41
86
|
- [Luca Guidi] Dynamically change the set of available commands depending on Hanami app architecture
|
@@ -44,32 +89,41 @@ No changes.
|
|
44
89
|
- [Piotr Solnica] Implemented `console` command with support for `IRB` and `Pry` (`pry` is auto-detected)
|
45
90
|
|
46
91
|
### Changed
|
92
|
+
|
47
93
|
- [Luca Guidi] Changed the purpose of this gem: the CLI Ruby framework has been extracted into `dry-cli` gem. `hanami-cli` is now the `hanami` command line.
|
48
94
|
- [Luca Guidi] Drop support for Ruby: MRI 2.5.
|
49
95
|
|
50
96
|
## v1.0.0.alpha1 - 2019-01-30
|
97
|
+
|
51
98
|
### Added
|
99
|
+
|
52
100
|
- [Luca Guidi] Inheritng from subclasses of `Hanami::CLI::Command`, allows to inherit arguments, options, description, and examples.
|
53
101
|
- [Luca Guidi] Allow to use `super` from `#call`
|
54
102
|
|
55
103
|
### Changed
|
104
|
+
|
56
105
|
- [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
|
57
106
|
|
58
107
|
## v0.3.1 - 2019-01-18
|
108
|
+
|
59
109
|
### Added
|
110
|
+
|
60
111
|
- [Luca Guidi] Official support for Ruby: MRI 2.6
|
61
112
|
- [Luca Guidi] Support `bundler` 2.0+
|
62
113
|
|
63
114
|
## v0.3.0 - 2018-10-24
|
64
115
|
|
65
116
|
## v0.3.0.beta1 - 2018-08-08
|
117
|
+
|
66
118
|
### Added
|
119
|
+
|
67
120
|
- [Anton Davydov & Alfonso Uceda] Introduce array type for arguments (`foo exec test spec/bookshelf/entities spec/bookshelf/repositories`)
|
68
121
|
- [Anton Davydov & Alfonso Uceda] Introduce array type for options (`foo generate config --apps=web,api`)
|
69
122
|
- [Alfonso Uceda] Introduce variadic arguments (`foo run ruby:latest -- ruby -v`)
|
70
123
|
- [Luca Guidi] Official support for JRuby 9.2.0.0
|
71
124
|
|
72
125
|
### Fixed
|
126
|
+
|
73
127
|
- [Anton Davydov] Print informative message when unknown or wrong option is passed (`"test" was called with arguments "--framework=unknown"`)
|
74
128
|
|
75
129
|
## v0.2.0 - 2018-04-11
|
@@ -79,21 +133,29 @@ No changes.
|
|
79
133
|
## v0.2.0.rc1 - 2018-03-30
|
80
134
|
|
81
135
|
## v0.2.0.beta2 - 2018-03-23
|
136
|
+
|
82
137
|
### Added
|
138
|
+
|
83
139
|
- [Anton Davydov & Luca Guidi] Support objects as callbacks
|
84
140
|
|
85
141
|
### Fixed
|
142
|
+
|
86
143
|
- [Anton Davydov & Luca Guidi] Ensure callbacks' context of execution (aka `self`) to be the command that is being executed
|
87
144
|
|
88
145
|
## v0.2.0.beta1 - 2018-02-28
|
146
|
+
|
89
147
|
### Added
|
148
|
+
|
90
149
|
- [Anton Davydov] Register `before`/`after` callbacks for commands
|
91
150
|
|
92
151
|
## v0.1.1 - 2018-02-27
|
152
|
+
|
93
153
|
### Added
|
154
|
+
|
94
155
|
- [Luca Guidi] Official support for Ruby: MRI 2.5
|
95
156
|
|
96
157
|
### Fixed
|
158
|
+
|
97
159
|
- [Alfonso Uceda] Ensure default values for arguments to be sent to commands
|
98
160
|
- [Alfonso Uceda] Ensure to fail when a missing required argument isn't provider, but an option is provided instead
|
99
161
|
|
@@ -104,13 +166,18 @@ No changes.
|
|
104
166
|
## v0.1.0.beta3 - 2017-10-04
|
105
167
|
|
106
168
|
## v0.1.0.beta2 - 2017-10-03
|
169
|
+
|
107
170
|
### Added
|
171
|
+
|
108
172
|
- [Alfonso Uceda] Allow default value for arguments
|
109
173
|
|
110
174
|
## v0.1.0.beta1 - 2017-08-11
|
175
|
+
|
111
176
|
### Added
|
177
|
+
|
112
178
|
- [Alfonso Uceda, Luca Guidi] Commands banner and usage
|
113
179
|
- [Alfonso Uceda] Added support for subcommands
|
180
|
+
|
114
181
|
- [Alfonso Uceda] Validations for arguments and options
|
115
182
|
- [Alfonso Uceda] Commands arguments and options
|
116
183
|
- [Alfonso Uceda] Commands description
|
data/Gemfile
CHANGED
@@ -8,9 +8,9 @@ unless ENV["CI"]
|
|
8
8
|
gem "yard", require: false
|
9
9
|
end
|
10
10
|
|
11
|
-
gem "
|
12
|
-
gem "hanami
|
13
|
-
gem "hanami-
|
11
|
+
gem "dry-files", require: false, github: "dry-rb/dry-files", branch: :main
|
12
|
+
gem "hanami", require: false, github: "hanami/hanami", branch: :main
|
13
|
+
gem "hanami-router", github: "hanami/router", branch: :main
|
14
14
|
|
15
15
|
gem "rack"
|
16
16
|
|
data/README.md
CHANGED
@@ -2,23 +2,25 @@
|
|
2
2
|
|
3
3
|
CLI commands for [full-stack Hanami applications](`https://github.com/hanami/hanami`).
|
4
4
|
|
5
|
-
**NOTE**: For versions 0.4 and below, there was a general purpose CLI utility library with this same name. That library has since been renamed to [dry-rb/cli](https://github.com/dry-rb/dry-cli). Please update your Gemfiles accordingly.
|
5
|
+
**NOTE**: For versions 0.4 and below, there was a general purpose CLI utility library with this same name. That library has since been renamed to [dry-rb/dry-cli](https://github.com/dry-rb/dry-cli). Please update your Gemfiles accordingly.
|
6
6
|
|
7
|
-
##
|
7
|
+
## Status
|
8
8
|
|
9
|
-
|
9
|
+
[![Gem Version](https://badge.fury.io/rb/hanami-cli.svg)](https://badge.fury.io/rb/hanami-cli)
|
10
|
+
[![CI](https://github.com/hanami/cli/workflows/ci/badge.svg?branch=main)](https://github.com/hanami/cli/actions?query=workflow%3Aci+branch%3Amain)
|
11
|
+
[![Depfu](https://badges.depfu.com/badges/a8545fb67cf32a2c75b6227bc0821027/overview.svg)](https://depfu.com/github/hanami/cli?project=Bundler)
|
10
12
|
|
11
|
-
|
12
|
-
gem 'hanami-cli'
|
13
|
-
```
|
13
|
+
## Contact
|
14
14
|
|
15
|
-
|
15
|
+
- Home page: http://hanamirb.org
|
16
|
+
- Mailing List: http://hanamirb.org/mailing-list
|
17
|
+
- Bugs/Issues: https://github.com/hanami/cli/issues
|
18
|
+
- Support: http://stackoverflow.com/questions/tagged/hanami
|
19
|
+
- Chat: http://chat.hanamirb.org
|
16
20
|
|
17
|
-
|
21
|
+
## Rubies
|
18
22
|
|
19
|
-
|
20
|
-
|
21
|
-
$ gem install hanami-cli
|
23
|
+
**Hanami::RSpec** supports Ruby (MRI) 3.0+
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
data/hanami-cli.gemspec
CHANGED
@@ -32,10 +32,11 @@ Gem::Specification.new do |spec|
|
|
32
32
|
|
33
33
|
spec.add_dependency "bundler", "~> 2.1"
|
34
34
|
spec.add_dependency "rake", "~> 13.0"
|
35
|
-
spec.add_dependency "dry-cli", "~> 0.
|
36
|
-
spec.add_dependency "dry-files", "~> 0.
|
35
|
+
spec.add_dependency "dry-cli", "~> 0.7"
|
36
|
+
spec.add_dependency "dry-files", "~> 0.2", ">= 0.2.0"
|
37
37
|
spec.add_dependency "dry-inflector", "~> 0.2"
|
38
38
|
|
39
39
|
spec.add_development_dependency "rspec", "~> 3.9"
|
40
40
|
spec.add_development_dependency "rubocop", "~> 1.0"
|
41
|
+
spec.add_development_dependency "puma"
|
41
42
|
end
|
data/lib/hanami/cli/bundler.rb
CHANGED
@@ -16,7 +16,7 @@ module Hanami
|
|
16
16
|
private_constant :DEFAULT_GEMFILE_PATH
|
17
17
|
|
18
18
|
def self.require(*groups)
|
19
|
-
return unless File.exist?(ENV
|
19
|
+
return unless File.exist?(ENV.fetch(BUNDLE_GEMFILE) { DEFAULT_GEMFILE_PATH })
|
20
20
|
|
21
21
|
::Bundler.require(*groups)
|
22
22
|
end
|
@@ -57,13 +57,9 @@ module Hanami
|
|
57
57
|
|
58
58
|
# Adapted from https://stackoverflow.com/a/5471032/498386
|
59
59
|
def which(cmd)
|
60
|
-
exts = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
|
61
|
-
|
62
60
|
ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
|
63
|
-
|
64
|
-
|
65
|
-
return exe if fs.executable?(exe) && !fs.directory?(exe)
|
66
|
-
end
|
61
|
+
exe = fs.join(path, cmd)
|
62
|
+
return exe if fs.executable?(exe) && !fs.directory?(exe)
|
67
63
|
end
|
68
64
|
|
69
65
|
nil
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "dry/files"
|
4
|
+
require_relative "../db/utils/database"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module App
|
10
|
+
class Command < Hanami::CLI::Command
|
11
|
+
module Environment
|
12
|
+
def call(**opts)
|
13
|
+
env = opts[:env]
|
14
|
+
|
15
|
+
hanami_env = env ? env.to_s : ENV.fetch("HANAMI_ENV", "development")
|
16
|
+
|
17
|
+
ENV["HANAMI_ENV"] = hanami_env
|
18
|
+
|
19
|
+
super(**opts)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.inherited(klass)
|
24
|
+
super
|
25
|
+
klass.prepend(Environment)
|
26
|
+
end
|
27
|
+
|
28
|
+
def app
|
29
|
+
@app ||=
|
30
|
+
begin
|
31
|
+
require "hanami/prepare"
|
32
|
+
Hanami.app
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def run_command(klass, *args)
|
37
|
+
klass.new(
|
38
|
+
out: out,
|
39
|
+
inflector: app.inflector,
|
40
|
+
fs: Dry::Files
|
41
|
+
).call(*args)
|
42
|
+
end
|
43
|
+
|
44
|
+
def measure(desc)
|
45
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
46
|
+
result = yield
|
47
|
+
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
48
|
+
|
49
|
+
if result
|
50
|
+
out.puts "=> #{desc} in #{(stop - start).round(4)}s"
|
51
|
+
else
|
52
|
+
out.puts "!!! => #{desc.inspect} FAILED"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def database
|
57
|
+
@database ||= Commands::DB::Utils::Database[app]
|
58
|
+
end
|
59
|
+
|
60
|
+
def database_config
|
61
|
+
database.config
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -2,14 +2,14 @@
|
|
2
2
|
|
3
3
|
require "hanami/console/context"
|
4
4
|
|
5
|
-
require_relative "../
|
5
|
+
require_relative "../app/command"
|
6
6
|
|
7
7
|
module Hanami
|
8
8
|
module CLI
|
9
9
|
module Commands
|
10
|
-
module
|
10
|
+
module App
|
11
11
|
# @api public
|
12
|
-
class Console <
|
12
|
+
class Console < App::Command
|
13
13
|
REPLS = {
|
14
14
|
"pry" => -> (*args) {
|
15
15
|
begin
|
@@ -23,8 +23,9 @@ module Hanami
|
|
23
23
|
},
|
24
24
|
}.freeze
|
25
25
|
|
26
|
-
desc "
|
26
|
+
desc "App REPL"
|
27
27
|
|
28
|
+
option :env, required: false, desc: "Application environment"
|
28
29
|
option :repl, required: false, desc: "REPL gem that should be used ('pry' or 'irb')"
|
29
30
|
|
30
31
|
# @api private
|
@@ -37,9 +38,9 @@ module Hanami
|
|
37
38
|
|
38
39
|
def resolve_engine(repl, opts)
|
39
40
|
if repl
|
40
|
-
REPLS.fetch(repl).(
|
41
|
+
REPLS.fetch(repl).(app, opts)
|
41
42
|
else
|
42
|
-
REPLS.map { |(_, loader)| loader.(
|
43
|
+
REPLS.map { |(_, loader)| loader.(app, opts) }.compact.first
|
43
44
|
end
|
44
45
|
end
|
45
46
|
end
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
|
5
5
|
module Hanami
|
6
6
|
module CLI
|
7
7
|
module Commands
|
8
|
-
module
|
8
|
+
module App
|
9
9
|
module DB
|
10
|
-
class Create <
|
10
|
+
class Create < App::Command
|
11
11
|
desc "Create database"
|
12
12
|
|
13
13
|
def call(**)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "structure/dump"
|
5
5
|
|
6
6
|
module Hanami
|
7
7
|
module CLI
|
8
8
|
module Commands
|
9
|
-
module
|
9
|
+
module App
|
10
10
|
module DB
|
11
|
-
class CreateMigration <
|
11
|
+
class CreateMigration < App::Command
|
12
12
|
desc "Create new migration file"
|
13
13
|
|
14
14
|
argument :name, desc: "Migration file name"
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
|
5
5
|
module Hanami
|
6
6
|
module CLI
|
7
7
|
module Commands
|
8
|
-
module
|
8
|
+
module App
|
9
9
|
module DB
|
10
|
-
class Drop <
|
10
|
+
class Drop < App::Command
|
11
11
|
desc "Delete database"
|
12
12
|
|
13
13
|
def call(**)
|
@@ -1,20 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "structure/dump"
|
5
5
|
|
6
6
|
module Hanami
|
7
7
|
module CLI
|
8
8
|
module Commands
|
9
|
-
module
|
9
|
+
module App
|
10
10
|
module DB
|
11
|
-
class Migrate <
|
11
|
+
class Migrate < App::Command
|
12
12
|
desc "Migrates database"
|
13
13
|
|
14
14
|
option :target, desc: "Target migration number", aliases: ["-t"]
|
15
15
|
|
16
16
|
def call(target: nil, **)
|
17
|
-
return true if Dir[File.join(
|
17
|
+
return true if Dir[File.join(app.root, "db/migrate/*.rb")].empty?
|
18
18
|
|
19
19
|
measure "database #{database.name} migrated" do
|
20
20
|
if target
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "create"
|
5
5
|
require_relative "drop"
|
6
6
|
require_relative "migrate"
|
@@ -8,9 +8,9 @@ require_relative "migrate"
|
|
8
8
|
module Hanami
|
9
9
|
module CLI
|
10
10
|
module Commands
|
11
|
-
module
|
11
|
+
module App
|
12
12
|
module DB
|
13
|
-
class Reset <
|
13
|
+
class Reset < App::Command
|
14
14
|
desc "Drop, create, and migrate database"
|
15
15
|
|
16
16
|
def call(**)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "structure/dump"
|
5
5
|
|
6
6
|
module Hanami
|
7
7
|
module CLI
|
8
8
|
module Commands
|
9
|
-
module
|
9
|
+
module App
|
10
10
|
module DB
|
11
|
-
class Rollback <
|
11
|
+
class Rollback < App::Command
|
12
12
|
desc "Rollback database to a previous migration"
|
13
13
|
|
14
14
|
option :target, desc: "Target migration number", aliases: ["-t"]
|
@@ -32,7 +32,7 @@ module Hanami
|
|
32
32
|
private
|
33
33
|
|
34
34
|
def find_migration(code)
|
35
|
-
migration = database.applied_migrations.
|
35
|
+
migration = database.applied_migrations.then { |migrations|
|
36
36
|
if code
|
37
37
|
migrations.detect { |m| m.split("_").first == code }
|
38
38
|
else
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "structure/dump"
|
5
5
|
|
6
6
|
module Hanami
|
7
7
|
module CLI
|
8
8
|
module Commands
|
9
|
-
module
|
9
|
+
module App
|
10
10
|
module DB
|
11
|
-
class SampleData <
|
11
|
+
class SampleData < App::Command
|
12
12
|
FILE_PATH = "db/sample_data.rb"
|
13
13
|
|
14
14
|
desc "Load sample data"
|
@@ -26,7 +26,7 @@ module Hanami
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def full_file_path
|
29
|
-
File.join(
|
29
|
+
File.join(app.root, FILE_PATH)
|
30
30
|
end
|
31
31
|
|
32
32
|
def has_file?
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "structure/dump"
|
5
5
|
|
6
6
|
module Hanami
|
7
7
|
module CLI
|
8
8
|
module Commands
|
9
|
-
module
|
9
|
+
module App
|
10
10
|
module DB
|
11
|
-
class Seed <
|
11
|
+
class Seed < App::Command
|
12
12
|
FILE_PATH = "db/seeds.rb"
|
13
13
|
|
14
14
|
desc "Load seed data"
|
@@ -26,7 +26,7 @@ module Hanami
|
|
26
26
|
private
|
27
27
|
|
28
28
|
def full_file_path
|
29
|
-
File.join(
|
29
|
+
File.join(app.root, FILE_PATH)
|
30
30
|
end
|
31
31
|
|
32
32
|
def has_file?
|
@@ -1,15 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
require_relative "create"
|
5
5
|
require_relative "migrate"
|
6
6
|
|
7
7
|
module Hanami
|
8
8
|
module CLI
|
9
9
|
module Commands
|
10
|
-
module
|
10
|
+
module App
|
11
11
|
module DB
|
12
|
-
class Setup <
|
12
|
+
class Setup < App::Command
|
13
13
|
desc "Setup database"
|
14
14
|
|
15
15
|
def call(**)
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../../
|
3
|
+
require_relative "../../../app/command"
|
4
4
|
|
5
5
|
module Hanami
|
6
6
|
module CLI
|
7
7
|
module Commands
|
8
|
-
module
|
8
|
+
module App
|
9
9
|
module DB
|
10
10
|
module Structure
|
11
|
-
class Dump <
|
11
|
+
class Dump < App::Command
|
12
12
|
desc "Dumps database structure to db/structure.sql file"
|
13
13
|
|
14
14
|
def call(*)
|
@@ -1,13 +1,13 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "../../
|
3
|
+
require_relative "../../app/command"
|
4
4
|
|
5
5
|
module Hanami
|
6
6
|
module CLI
|
7
7
|
module Commands
|
8
|
-
module
|
8
|
+
module App
|
9
9
|
module DB
|
10
|
-
class Version <
|
10
|
+
class Version < App::Command
|
11
11
|
desc "Print schema version"
|
12
12
|
|
13
13
|
option :target, desc: "Target migration number", aliases: ["-t"]
|