hanami-cli 2.0.0.alpha7 → 2.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.action_hero.yml +11 -0
- data/.github/FUNDING.yml +1 -0
- data/CHANGELOG.md +58 -0
- data/Gemfile +2 -3
- data/LICENSE.md +22 -0
- data/README.md +14 -10
- data/hanami-cli.gemspec +3 -2
- data/lib/hanami/cli/bundler.rb +3 -7
- data/lib/hanami/cli/commands/app/command.rb +68 -0
- data/lib/hanami/cli/commands/{monolith → app}/console.rb +6 -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 +3 -3
- 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/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 +46 -0
- data/lib/hanami/cli/commands/db/utils/database.rb +14 -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 +9 -10
- data/lib/hanami/cli/generators/{monolith → app}/action/action.erb +0 -0
- 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 +2 -2
- data/lib/hanami/cli/generators/{monolith → app}/action_context.rb +1 -1
- data/lib/hanami/cli/generators/{monolith → app}/slice/action.erb +0 -0
- 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/{monolith → app}/slice/routes.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice/view.erb +0 -0
- data/lib/hanami/cli/generators/{monolith → app}/slice.rb +2 -2
- 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 +15 -0
- data/lib/hanami/cli/generators/{monolith/slice → gem/app}/keep.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/operation.erb +9 -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/relation.erb +7 -0
- data/lib/hanami/cli/generators/gem/app/repository.erb +9 -0
- data/lib/hanami/cli/generators/gem/app/routes.erb +11 -0
- data/lib/hanami/cli/generators/gem/app/settings.erb +9 -0
- data/lib/hanami/cli/generators/gem/{application/monolith/functions.erb → app/transformations.erb} +1 -1
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/types.erb +0 -0
- data/lib/hanami/cli/generators/gem/app/validator.erb +12 -0
- data/lib/hanami/cli/generators/gem/app/view.erb +9 -0
- data/lib/hanami/cli/generators/gem/{application/monolith → app}/view_context.erb +1 -6
- data/lib/hanami/cli/generators/gem/app/view_part.erb +10 -0
- data/lib/hanami/cli/generators/gem/app.rb +64 -0
- data/lib/hanami/cli/generators/version.rb +55 -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
- data/project.yml +2 -0
- metadata +88 -60
- data/LICENSE.txt +0 -21
- data/lib/hanami/cli/commands/application.rb +0 -63
- 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/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.rb +0 -83
- data/lib/hanami/cli/generators/gem/application.rb +0 -21
- 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: 8d2d0f04510c5ac3d7c729c2830997ec692f9d9be7161b199cf87fcfd1284cf3
|
4
|
+
data.tar.gz: 970de26f0dfdaba799141c24b72ea84ab94721d378f62c3bbbfe494e9a63c3bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5dab4fa87022146327320394b66cdd8efb18ca9c2f98eb743bc65f38017a5904a0f06db3d45aca5990e51fac27868f0e9c026feab80639bf97791353670a219b
|
7
|
+
data.tar.gz: 594c4c1f6fa03910543700dbcfa0ff16f5be462cc4f39b19c9918d66de3b071beeb9e8b187ae39d3f55285296126d1378a188cd87b08d575d00d9ef1a0b21ffd
|
data/.action_hero.yml
ADDED
data/.github/FUNDING.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
github: hanami
|
data/CHANGELOG.md
CHANGED
@@ -1,35 +1,71 @@
|
|
1
1
|
# Hanami::CLI
|
2
|
+
|
2
3
|
Hanami Command Line Interface
|
3
4
|
|
5
|
+
## v2.0.0.beta1 - 2022-07-20
|
6
|
+
|
7
|
+
### Added
|
8
|
+
|
9
|
+
- [Luca Guidi] Implemented `hanami new` to generate a new Hanami app
|
10
|
+
- [Piotr Solnica] Implemented `hanami console` to start an interactive console (REPL)
|
11
|
+
- [Marc Busque] Implemented `hanami server` to start a HTTP server based on Rack
|
12
|
+
- [Marc Busque] Implemented `hanami routes` to print app routes
|
13
|
+
- [Luca Guidi] Implemented `hanami version` to print app Hanami version
|
14
|
+
|
15
|
+
## v2.0.0.alpha8.1 - 2022-05-23
|
16
|
+
|
17
|
+
### Fixed
|
18
|
+
|
19
|
+
- [Tim Riley] Ensure CLI starts properly by fixing use of `Slice.slice_name`
|
20
|
+
|
21
|
+
## v2.0.0.alpha8 - 2022-05-19
|
22
|
+
|
23
|
+
### Fixed
|
24
|
+
|
25
|
+
- [Andrew Croome] Respect HANAMI_ENV env var to set Hanami env if no `--env` option is supplied
|
26
|
+
- [Lucas Mendelowski] Ensure Sequel migrations extension is loaded before related `db` commands are run
|
27
|
+
|
4
28
|
## v2.0.0.alpha7 - 2022-03-11
|
5
29
|
|
6
30
|
### Changed
|
31
|
+
|
7
32
|
- [Tim Riley] [Internal] Update console slice readers to work with new `Hanami::Application.slices` API
|
8
33
|
|
9
34
|
## v2.0.0.alpha6.1 - 2022-02-11
|
35
|
+
|
10
36
|
### Fixed
|
37
|
+
|
11
38
|
- [Viet Tran] Ensure `hanami db` commands to work with `hanami` `v2.0.0.alpha6`
|
12
39
|
|
13
40
|
## v2.0.0.alpha6 - 2022-02-10
|
41
|
+
|
14
42
|
### Added
|
43
|
+
|
15
44
|
- [Luca Guidi] Official support for Ruby: MRI 3.1
|
16
45
|
|
17
46
|
### Changed
|
47
|
+
|
18
48
|
- [Luca Guidi] Drop support for Ruby: MRI 2.6, and 2.7
|
19
49
|
|
20
50
|
## v2.0.0.alpha4 - 2021-12-07
|
51
|
+
|
21
52
|
### Added
|
53
|
+
|
22
54
|
- [Tim Riley] Display a custom prompt when using irb-based console (consistent with pry-based console)
|
23
55
|
- [Phil Arndt] Support `postgresql://` URL schemes (in addition to existing `postgres://` support) for `db` subcommands
|
24
56
|
|
25
57
|
### Fixed
|
58
|
+
|
26
59
|
- [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)
|
27
60
|
|
28
61
|
## v2.0.0.alpha3 - 2021-11-09
|
62
|
+
|
29
63
|
No changes.
|
30
64
|
|
31
65
|
## v2.0.0.alpha2 - 2021-05-04
|
66
|
+
|
32
67
|
### Added
|
68
|
+
|
33
69
|
- [Luca Guidi] Official support for Ruby: MRI 3.0
|
34
70
|
- [Luca Guidi] Dynamically change the set of available commands depending on the context (outside or inside an Hanami app)
|
35
71
|
- [Luca Guidi] Dynamically change the set of available commands depending on Hanami app architecture
|
@@ -38,32 +74,41 @@ No changes.
|
|
38
74
|
- [Piotr Solnica] Implemented `console` command with support for `IRB` and `Pry` (`pry` is auto-detected)
|
39
75
|
|
40
76
|
### Changed
|
77
|
+
|
41
78
|
- [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.
|
42
79
|
- [Luca Guidi] Drop support for Ruby: MRI 2.5.
|
43
80
|
|
44
81
|
## v1.0.0.alpha1 - 2019-01-30
|
82
|
+
|
45
83
|
### Added
|
84
|
+
|
46
85
|
- [Luca Guidi] Inheritng from subclasses of `Hanami::CLI::Command`, allows to inherit arguments, options, description, and examples.
|
47
86
|
- [Luca Guidi] Allow to use `super` from `#call`
|
48
87
|
|
49
88
|
### Changed
|
89
|
+
|
50
90
|
- [Luca Guidi] Drop support for Ruby: MRI 2.3, and 2.4.
|
51
91
|
|
52
92
|
## v0.3.1 - 2019-01-18
|
93
|
+
|
53
94
|
### Added
|
95
|
+
|
54
96
|
- [Luca Guidi] Official support for Ruby: MRI 2.6
|
55
97
|
- [Luca Guidi] Support `bundler` 2.0+
|
56
98
|
|
57
99
|
## v0.3.0 - 2018-10-24
|
58
100
|
|
59
101
|
## v0.3.0.beta1 - 2018-08-08
|
102
|
+
|
60
103
|
### Added
|
104
|
+
|
61
105
|
- [Anton Davydov & Alfonso Uceda] Introduce array type for arguments (`foo exec test spec/bookshelf/entities spec/bookshelf/repositories`)
|
62
106
|
- [Anton Davydov & Alfonso Uceda] Introduce array type for options (`foo generate config --apps=web,api`)
|
63
107
|
- [Alfonso Uceda] Introduce variadic arguments (`foo run ruby:latest -- ruby -v`)
|
64
108
|
- [Luca Guidi] Official support for JRuby 9.2.0.0
|
65
109
|
|
66
110
|
### Fixed
|
111
|
+
|
67
112
|
- [Anton Davydov] Print informative message when unknown or wrong option is passed (`"test" was called with arguments "--framework=unknown"`)
|
68
113
|
|
69
114
|
## v0.2.0 - 2018-04-11
|
@@ -73,21 +118,29 @@ No changes.
|
|
73
118
|
## v0.2.0.rc1 - 2018-03-30
|
74
119
|
|
75
120
|
## v0.2.0.beta2 - 2018-03-23
|
121
|
+
|
76
122
|
### Added
|
123
|
+
|
77
124
|
- [Anton Davydov & Luca Guidi] Support objects as callbacks
|
78
125
|
|
79
126
|
### Fixed
|
127
|
+
|
80
128
|
- [Anton Davydov & Luca Guidi] Ensure callbacks' context of execution (aka `self`) to be the command that is being executed
|
81
129
|
|
82
130
|
## v0.2.0.beta1 - 2018-02-28
|
131
|
+
|
83
132
|
### Added
|
133
|
+
|
84
134
|
- [Anton Davydov] Register `before`/`after` callbacks for commands
|
85
135
|
|
86
136
|
## v0.1.1 - 2018-02-27
|
137
|
+
|
87
138
|
### Added
|
139
|
+
|
88
140
|
- [Luca Guidi] Official support for Ruby: MRI 2.5
|
89
141
|
|
90
142
|
### Fixed
|
143
|
+
|
91
144
|
- [Alfonso Uceda] Ensure default values for arguments to be sent to commands
|
92
145
|
- [Alfonso Uceda] Ensure to fail when a missing required argument isn't provider, but an option is provided instead
|
93
146
|
|
@@ -98,13 +151,18 @@ No changes.
|
|
98
151
|
## v0.1.0.beta3 - 2017-10-04
|
99
152
|
|
100
153
|
## v0.1.0.beta2 - 2017-10-03
|
154
|
+
|
101
155
|
### Added
|
156
|
+
|
102
157
|
- [Alfonso Uceda] Allow default value for arguments
|
103
158
|
|
104
159
|
## v0.1.0.beta1 - 2017-08-11
|
160
|
+
|
105
161
|
### Added
|
162
|
+
|
106
163
|
- [Alfonso Uceda, Luca Guidi] Commands banner and usage
|
107
164
|
- [Alfonso Uceda] Added support for subcommands
|
165
|
+
|
108
166
|
- [Alfonso Uceda] Validations for arguments and options
|
109
167
|
- [Alfonso Uceda] Commands arguments and options
|
110
168
|
- [Alfonso Uceda] Commands description
|
data/Gemfile
CHANGED
@@ -8,9 +8,8 @@ unless ENV["CI"]
|
|
8
8
|
gem "yard", require: false
|
9
9
|
end
|
10
10
|
|
11
|
-
gem "hanami", require: false,
|
12
|
-
gem "hanami-router",
|
13
|
-
gem "hanami-view", require: false, git: "https://github.com/hanami/view.git", branch: "main"
|
11
|
+
gem "hanami", require: false, github: "hanami/hanami", branch: :main
|
12
|
+
gem "hanami-router", github: "hanami/router", branch: :main
|
14
13
|
|
15
14
|
gem "rack"
|
16
15
|
|
data/LICENSE.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright © 2014-2022 Luca Guidi
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,22 +1,26 @@
|
|
1
1
|
# Hanami::CLI
|
2
2
|
|
3
|
-
[Hanami](
|
3
|
+
CLI commands for [full-stack Hanami applications](`https://github.com/hanami/hanami`).
|
4
4
|
|
5
|
-
|
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
|
-
|
10
|
-
|
11
|
-
|
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)
|
12
12
|
|
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
|
-
|
23
|
+
**Hanami::RSpec** supports Ruby (MRI) 3.0+
|
20
24
|
|
21
25
|
## Usage
|
22
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,68 @@
|
|
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.option(:env, required: false, desc: "App's environment")
|
26
|
+
klass.prepend(Environment)
|
27
|
+
end
|
28
|
+
|
29
|
+
def app
|
30
|
+
@app ||=
|
31
|
+
begin
|
32
|
+
require "hanami/prepare"
|
33
|
+
Hanami.app
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def run_command(klass, *args)
|
38
|
+
klass.new(
|
39
|
+
out: out,
|
40
|
+
inflector: app.inflector,
|
41
|
+
fs: Dry::Files
|
42
|
+
).call(*args)
|
43
|
+
end
|
44
|
+
|
45
|
+
def measure(desc)
|
46
|
+
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
47
|
+
result = yield
|
48
|
+
stop = Process.clock_gettime(Process::CLOCK_MONOTONIC)
|
49
|
+
|
50
|
+
if result
|
51
|
+
out.puts "=> #{desc} in #{(stop - start).round(4)}s"
|
52
|
+
else
|
53
|
+
out.puts "!!! => #{desc.inspect} FAILED"
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def database
|
58
|
+
@database ||= Commands::DB::Utils::Database[app]
|
59
|
+
end
|
60
|
+
|
61
|
+
def database_config
|
62
|
+
database.config
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
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,7 +23,7 @@ module Hanami
|
|
23
23
|
},
|
24
24
|
}.freeze
|
25
25
|
|
26
|
-
desc "
|
26
|
+
desc "App REPL"
|
27
27
|
|
28
28
|
option :repl, required: false, desc: "REPL gem that should be used ('pry' or 'irb')"
|
29
29
|
|
@@ -37,9 +37,9 @@ module Hanami
|
|
37
37
|
|
38
38
|
def resolve_engine(repl, opts)
|
39
39
|
if repl
|
40
|
-
REPLS.fetch(repl).(
|
40
|
+
REPLS.fetch(repl).(app, opts)
|
41
41
|
else
|
42
|
-
REPLS.map { |(_, loader)| loader.(
|
42
|
+
REPLS.map { |(_, loader)| loader.(app, opts) }.compact.first
|
43
43
|
end
|
44
44
|
end
|
45
45
|
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"]
|