hanami-cli 2.0.0.beta4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +0 -1
  3. data/.rubocop.yml +2 -0
  4. data/.yardopts +3 -0
  5. data/CHANGELOG.md +14 -0
  6. data/Gemfile +7 -4
  7. data/exe/hanami +6 -1
  8. data/hanami-cli.gemspec +4 -3
  9. data/lib/hanami/cli/bundler.rb +95 -5
  10. data/lib/hanami/cli/command.rb +41 -0
  11. data/lib/hanami/cli/commands/app/command.rb +63 -2
  12. data/lib/hanami/cli/commands/app/console.rb +7 -3
  13. data/lib/hanami/cli/commands/app/db/create.rb +2 -0
  14. data/lib/hanami/cli/commands/app/db/create_migration.rb +3 -0
  15. data/lib/hanami/cli/commands/app/db/drop.rb +2 -0
  16. data/lib/hanami/cli/commands/app/db/migrate.rb +2 -0
  17. data/lib/hanami/cli/commands/app/db/reset.rb +2 -0
  18. data/lib/hanami/cli/commands/app/db/rollback.rb +2 -0
  19. data/lib/hanami/cli/commands/app/db/sample_data.rb +2 -0
  20. data/lib/hanami/cli/commands/app/db/seed.rb +2 -0
  21. data/lib/hanami/cli/commands/app/db/setup.rb +2 -0
  22. data/lib/hanami/cli/commands/app/db/structure/dump.rb +3 -0
  23. data/lib/hanami/cli/commands/app/db/utils/database.rb +155 -0
  24. data/lib/hanami/cli/commands/app/db/utils/database_config.rb +60 -0
  25. data/lib/hanami/cli/commands/app/db/utils/mysql.rb +33 -0
  26. data/lib/hanami/cli/commands/app/db/utils/postgres.rb +64 -0
  27. data/lib/hanami/cli/commands/app/db/utils/sqlite.rb +45 -0
  28. data/lib/hanami/cli/commands/app/db/version.rb +2 -0
  29. data/lib/hanami/cli/commands/app/generate/action.rb +10 -3
  30. data/lib/hanami/cli/commands/app/generate/slice.rb +9 -6
  31. data/lib/hanami/cli/commands/app/generate.rb +2 -0
  32. data/lib/hanami/cli/commands/app/install.rb +13 -2
  33. data/lib/hanami/cli/commands/app/middleware.rb +7 -1
  34. data/lib/hanami/cli/commands/app/routes.rb +8 -0
  35. data/lib/hanami/cli/commands/app/server.rb +10 -0
  36. data/lib/hanami/cli/commands/app/version.rb +4 -2
  37. data/lib/hanami/cli/commands/app.rb +6 -19
  38. data/lib/hanami/cli/commands/gem/new.rb +12 -13
  39. data/lib/hanami/cli/commands/gem/version.rb +4 -2
  40. data/lib/hanami/cli/commands/gem.rb +8 -5
  41. data/lib/hanami/cli/commands.rb +19 -3
  42. data/lib/hanami/cli/errors.rb +65 -0
  43. data/lib/hanami/cli/files.rb +10 -0
  44. data/lib/hanami/cli/generators/app/action.rb +11 -5
  45. data/lib/hanami/cli/generators/app/action_context.rb +22 -0
  46. data/lib/hanami/cli/generators/app/slice.rb +6 -1
  47. data/lib/hanami/cli/generators/app/slice_context.rb +8 -0
  48. data/lib/hanami/cli/generators/context.rb +14 -0
  49. data/lib/hanami/cli/generators/gem/app.rb +9 -5
  50. data/lib/hanami/cli/generators/version.rb +8 -6
  51. data/lib/hanami/cli/middleware_stack_inspector.rb +5 -0
  52. data/lib/hanami/cli/rake_tasks.rb +0 -1
  53. data/lib/hanami/cli/repl/core.rb +12 -4
  54. data/lib/hanami/cli/repl/irb.rb +3 -2
  55. data/lib/hanami/cli/repl/pry.rb +1 -3
  56. data/lib/hanami/cli/server.rb +11 -0
  57. data/lib/hanami/cli/system_call.rb +65 -7
  58. data/lib/hanami/cli/url.rb +9 -2
  59. data/lib/hanami/cli/version.rb +5 -1
  60. data/lib/hanami/cli.rb +26 -3
  61. data/lib/hanami/console/context.rb +4 -2
  62. data/lib/hanami/console/plugins/slice_readers.rb +1 -0
  63. data/lib/hanami-cli.rb +3 -0
  64. metadata +60 -27
  65. data/lib/hanami/cli/command_line.rb +0 -17
  66. data/lib/hanami/cli/commands/db/utils/database.rb +0 -133
  67. data/lib/hanami/cli/commands/db/utils/database_config.rb +0 -48
  68. data/lib/hanami/cli/commands/db/utils/mysql.rb +0 -27
  69. data/lib/hanami/cli/commands/db/utils/postgres.rb +0 -54
  70. data/lib/hanami/cli/commands/db/utils/sqlite.rb +0 -37
  71. data/lib/hanami/cli/error.rb +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9e5786ce0557b00c863e145560473293d2d172f96c4bcdd10e7dcc32484a32a3
4
- data.tar.gz: 036fb11ad8f805173889beb755daa50d8de1da678d74e853f9f8ddf65fa3dde1
3
+ metadata.gz: a1351e33232b164c6e82ac6148e95eac2562e43dcd36f1a1d11aad61307f32da
4
+ data.tar.gz: 647213baac46e31addb957a6ce4d3f8b11e28e64ddb02d3cfe1569ce49015ed6
5
5
  SHA512:
6
- metadata.gz: 3bde684529fa1ae28f86bee5aa8b9fb42297a7e112ff272751c0a234f5cb22cb13ea6a3bf46d580a56d9804225fd2d0834e131eb53fd60184cb0d6096f8f2a08
7
- data.tar.gz: de2d099cfe069f4fd6c85aa23c5ce60f0133e9a6c1858c9f237f9c104ee5f2e56ab11965a7b979de754d6cdcefc8cbb9b5abfc9b0acc58cda2e2402cb570c546
6
+ metadata.gz: cb27cd6155cd93c1783402e32992104d32a41da98397ef57c0dc1b0b72edf0cb76c9203d48dc925c352f9742a16c274cf0679dc9e431c12d83ad69508478786d
7
+ data.tar.gz: 04cc7a076b6a66d30729ebaa28b9108cb41bd7515cd538d5a81a350b22850ff3fbefd27a0a9044130ed50bfa8dc34562ab6e32e57834924cc7c3e51a13468708
data/.rspec CHANGED
@@ -1,3 +1,2 @@
1
- --format documentation
2
1
  --color
3
2
  --require spec_helper
data/.rubocop.yml CHANGED
@@ -16,6 +16,8 @@ Naming/HeredocDelimiterNaming:
16
16
  Naming/MethodParameterName:
17
17
  AllowedNames:
18
18
  - fs
19
+ Naming/RescuedExceptionsVariableName:
20
+ Enabled: false
19
21
  Style/AccessorGrouping:
20
22
  Enabled: false
21
23
  Style/BlockDelimiters:
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --markup=markdown
2
+
3
+ --plugin junk
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  Hanami Command Line Interface
4
4
 
5
+ ## v2.0.0 - 2022-11-22
6
+
7
+ ### Added
8
+
9
+ - [Tim Riley] Use Zeitwerk to autoload the gem
10
+
11
+ ### Fixed
12
+
13
+ - [Luca Guidi] In case of internal exception, don't print the stack trace to stderr, print the error message, exit with 1.
14
+ - [Tim Riley] Ensure to be able to run `hanami` CLI in Hanami app subdirectories.
15
+ - [Sean Collins] Return an error when trying to run `hanami new` with an existing target path (file or directory)
16
+
17
+ ## v2.0.0.rc1 - 2022-11-08
18
+
5
19
  ## v2.0.0.beta4 - 2022-10-24
6
20
 
7
21
  ### Changed
data/Gemfile CHANGED
@@ -4,12 +4,15 @@ source "https://rubygems.org"
4
4
  gemspec
5
5
 
6
6
  unless ENV["CI"]
7
- gem "byebug", require: false, platforms: :mri
8
- gem "yard", require: false
7
+ gem "byebug", platforms: :mri
8
+ gem "yard"
9
+ gem "yard-junk"
9
10
  end
10
11
 
11
- gem "hanami", require: false, github: "hanami/hanami", branch: :main
12
- gem "hanami-router", github: "hanami/router", branch: :main
12
+ gem "hanami", github: "hanami/hanami", branch: "main"
13
+ gem "hanami-utils", github: "hanami/utils", branch: "main"
14
+ gem "hanami-router", github: "hanami/router", branch: "main"
15
+ gem "hanami-controller", github: "hanami/controller", branch: "main"
13
16
 
14
17
  gem "rack"
15
18
 
data/exe/hanami CHANGED
@@ -7,4 +7,9 @@ require "hanami/cli"
7
7
  cli = Dry::CLI.new(Hanami::CLI)
8
8
  Hanami::CLI::Bundler.require(:cli)
9
9
 
10
- cli.call
10
+ begin
11
+ cli.call
12
+ rescue Hanami::CLI::Error => exception
13
+ $stderr.puts(exception.message) # rubocop:disable Style/StderrPuts
14
+ exit(1)
15
+ end
data/hanami-cli.gemspec CHANGED
@@ -31,10 +31,11 @@ Gem::Specification.new do |spec|
31
31
  spec.required_ruby_version = ">= 3.0"
32
32
 
33
33
  spec.add_dependency "bundler", "~> 2.1"
34
+ spec.add_dependency "dry-cli", "~> 1.0", "< 2"
35
+ spec.add_dependency "dry-files", "~> 1.0", ">= 1.0.1", "< 2"
36
+ spec.add_dependency "dry-inflector", "~> 1.0", "< 2"
34
37
  spec.add_dependency "rake", "~> 13.0"
35
- spec.add_dependency "dry-cli", "~> 0.7"
36
- spec.add_dependency "dry-files", "~> 0.3", ">= 0.3.0"
37
- spec.add_dependency "dry-inflector", "~> 0.2"
38
+ spec.add_dependency "zeitwerk", "~> 2.6"
38
39
 
39
40
  spec.add_development_dependency "rspec", "~> 3.9"
40
41
  spec.add_development_dependency "rubocop", "~> 1.0"
@@ -5,58 +5,148 @@ require "open3"
5
5
  require "etc"
6
6
  require "dry/files"
7
7
  require_relative "./system_call"
8
+ require_relative "./errors"
8
9
 
9
10
  module Hanami
10
11
  module CLI
12
+ # Conveniences for running `bundler` from CLI commands.
13
+ #
14
+ # @since 2.0.0
15
+ # @api public
11
16
  class Bundler
17
+ # @since 2.0.0
18
+ # @api private
12
19
  BUNDLE_GEMFILE = "BUNDLE_GEMFILE"
13
20
  private_constant :BUNDLE_GEMFILE
14
21
 
22
+ # @since 2.0.0
23
+ # @api private
15
24
  DEFAULT_GEMFILE_PATH = "Gemfile"
16
25
  private_constant :DEFAULT_GEMFILE_PATH
17
26
 
27
+ # If a `Gemfile` exists, sets up the Bundler environment and loads all the gems from the given
28
+ # groups.
29
+ #
30
+ # This can be called multiple times with different groups.
31
+ #
32
+ # This is a convenience wrapper for `Bundler.require`.
33
+ #
34
+ # @see https://rubydoc.info/gems/bundler/Bundler#require-class_method
35
+ #
36
+ # @return [void]
37
+ #
38
+ # @since 2.0.0
39
+ # @api public
18
40
  def self.require(*groups)
19
41
  return unless File.exist?(ENV.fetch(BUNDLE_GEMFILE) { DEFAULT_GEMFILE_PATH })
20
42
 
21
43
  ::Bundler.require(*groups)
22
44
  end
23
45
 
46
+ # Returns a new bundler.
47
+ #
48
+ # @param fs [Dry::Files] the filesystem interaction object
49
+ # @param system_call [SystemCall] convenience object for making system calls
50
+ #
51
+ # @since 2.0.0
52
+ # @api public
24
53
  def initialize(fs: Dry::Files.new, system_call: SystemCall.new)
25
54
  @fs = fs
26
55
  @system_call = system_call
27
56
  end
28
57
 
58
+ # Runs `bundle install` for the Hanami app.
59
+ #
60
+ # @return [SystemCall::Result] the result of the `bundle` command execution
61
+ #
62
+ # @since 2.0.0
63
+ # @api public
29
64
  def install
30
65
  parallelism_level = Etc.nprocessors
31
66
  bundle "install --jobs=#{parallelism_level} --quiet --no-color"
32
67
  end
33
68
 
69
+ # Runs `bundle install` for the Hanami app and raises an error if the command does not execute
70
+ # successfully.
71
+ #
72
+ # @return [SystemCall::Result] the result of the `bundle` command execution
73
+ #
74
+ # @raise [StandardError] if the `bundle` command does not execute successfully
75
+ #
76
+ # @since 2.0.0
77
+ # @api public
34
78
  def install!
35
79
  install.tap do |result|
36
- raise "Bundle install failed\n\n\n#{result.err.inspect}" unless result.successful?
80
+ raise BundleInstallError.new(result.err) unless result.successful?
37
81
  end
38
82
  end
39
83
 
84
+ # Executes the given command prefixed by `bundle exec`.
85
+ #
86
+ # @return [SystemCall::Result] the result of the command execution
87
+ #
88
+ # @since 2.0.0
89
+ # @api public
40
90
  def exec(cmd, env: nil, &blk)
41
91
  bundle("exec #{cmd}", env: env, &blk)
42
92
  end
43
93
 
44
- def bundle(cmd, env: nil, &blk)
94
+ # Executes the given command prefixed by `bundle`.
95
+ #
96
+ # This is how you should execute all bundle subcommands.
97
+ #
98
+ # @param cmd [String] the commands to prefix with `bundle`
99
+ # @param env [Hash<String, String>] an optional hash of environment variables to set before
100
+ # executing the command
101
+ #
102
+ # @overload bundle(cmd, env: nil)
103
+ #
104
+ # @overload bundle(cmd, env: nil, &blk)
105
+ # Executes the command and passes the given block to the `Open3.popen3` method called
106
+ # internally.
107
+ #
108
+ # @example
109
+ # bundle("info") do |stdin, stdout, stderr, wait_thread|
110
+ # # ...
111
+ # end
112
+ #
113
+ # @see SystemCall#call
114
+ #
115
+ # @since 2.0.0
116
+ # @api public
117
+ def bundle(cmd, env: nil, &block)
45
118
  bundle_bin = which("bundle")
46
119
  hanami_env = "HANAMI_ENV=#{env} " unless env.nil?
47
120
 
48
- system_call.call("#{hanami_env}#{bundle_bin} #{cmd}",
49
- env: {BUNDLE_GEMFILE => fs.expand_path(DEFAULT_GEMFILE_PATH)}, &blk)
121
+ system_call.call(
122
+ "#{hanami_env}#{bundle_bin} #{cmd}",
123
+ env: {BUNDLE_GEMFILE => fs.expand_path(DEFAULT_GEMFILE_PATH)},
124
+ &block
125
+ )
50
126
  end
51
127
 
52
128
  private
53
129
 
130
+ # @return [Dry::Files]
131
+ #
132
+ # @since 2.0.0
133
+ # @api public
54
134
  attr_reader :fs
55
135
 
136
+ # @return [SystemCall]
137
+ #
138
+ # @since 2.0.0
139
+ # @api public
56
140
  attr_reader :system_call
57
141
 
58
- # Adapted from https://stackoverflow.com/a/5471032/498386
142
+ # Returns the full path to the given executable, or nil if not found in the path.
143
+ #
144
+ # @return [Pathname, nil]
145
+ #
146
+ # @since 2.0.0
147
+ # @api private
59
148
  def which(cmd)
149
+ # Adapted from https://stackoverflow.com/a/5471032/498386
60
150
  ENV["PATH"].split(File::PATH_SEPARATOR).each do |path|
61
151
  exe = fs.join(path, cmd)
62
152
  return exe if fs.executable?(exe) && !fs.directory?(exe)
@@ -6,7 +6,24 @@ require "dry/inflector"
6
6
 
7
7
  module Hanami
8
8
  module CLI
9
+ # Base class for `hanami` CLI commands.
10
+ #
11
+ # @api public
12
+ # @since 2.0.0
9
13
  class Command < Dry::CLI::Command
14
+ # Returns a new command.
15
+ #
16
+ # This method does not need to be called directly when creating comments for the CLI. Commands
17
+ # are registered as classes, and the CLI framework will initialize the command when needed.
18
+ # This means that all parameters for `#initialize` should also be given default arguments.
19
+ #
20
+ # @param out [IO] I/O stream for standard command output
21
+ # @param err [IO] I/O stream for comment errror output
22
+ # @param fs [Dry::Files] object for managing file system interactions
23
+ # @param inflector [Dry::Inflector] inflector for any command-level inflections
24
+ #
25
+ # @since 2.0.0
26
+ # @api public
10
27
  def initialize(out: $stdout, err: $stderr, fs: Dry::Files.new, inflector: Dry::Inflector.new)
11
28
  super()
12
29
  @out = out
@@ -17,12 +34,36 @@ module Hanami
17
34
 
18
35
  private
19
36
 
37
+ # Returns the I/O stream for standard command output.
38
+ #
39
+ # @return [IO]
40
+ #
41
+ # @since 2.0.0
42
+ # @api public
20
43
  attr_reader :out
21
44
 
45
+ # Returns the I/O stream for command error output.
46
+ #
47
+ # @return [IO]
48
+ #
49
+ # @since 2.0.0
50
+ # @api public
22
51
  attr_reader :err
23
52
 
53
+ # Returns the object for managing file system interactions.
54
+ #
55
+ # @return [Dry::Files]
56
+ #
57
+ # @since 2.0.0
58
+ # @api public
24
59
  attr_reader :fs
25
60
 
61
+ # Returns the inflector.
62
+ #
63
+ # @return [Dry::Inflector]
64
+ #
65
+ # @since 2.0.0
66
+ # @api public
26
67
  attr_reader :inflector
27
68
  end
28
69
  end
@@ -1,16 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "dry/files"
4
- require_relative "../db/utils/database"
4
+ require_relative "db/utils/database"
5
5
 
6
6
  module Hanami
7
7
  module CLI
8
8
  module Commands
9
9
  module App
10
+ # Base class for `hanami` CLI commands intended to be executed within an existing Hanami
11
+ # app.
12
+ #
13
+ # @since 2.0.0
14
+ # @api public
10
15
  class Command < Hanami::CLI::Command
11
- ACTION_SEPARATOR = "."
16
+ # @since 2.0.0
17
+ # @api private
18
+ ACTION_SEPARATOR = "." # TODO: rename to container key separator
12
19
 
20
+ # Overloads {Hanami::CLI::Commands::App::Command#call} to ensure an appropriate `HANAMI_ENV`
21
+ # environment variable is set.
22
+ #
23
+ # Uses an `--env` option if provided, then falls back to an already-set `HANAMI_ENV`
24
+ # environment variable, and defaults to "development" in the absence of both.
25
+ #
26
+ # @since 2.0.0
27
+ # @api private
13
28
  module Environment
29
+ # @since 2.0.0
30
+ # @api private
14
31
  def call(*args, **opts)
15
32
  env = opts[:env]
16
33
 
@@ -22,11 +39,21 @@ module Hanami
22
39
  end
23
40
  end
24
41
 
42
+ # @since 2.0.0
43
+ # @api private
25
44
  def self.inherited(klass)
26
45
  super
27
46
  klass.prepend(Environment)
28
47
  end
29
48
 
49
+ # Returns the Hanami app class.
50
+ #
51
+ # @return [Hanami::App] the Hanami app
52
+ #
53
+ # @raise [Hanami::AppLoadError] if the app has not been loaded
54
+ #
55
+ # @since 2.0.0
56
+ # @api public
30
57
  def app
31
58
  @app ||=
32
59
  begin
@@ -35,6 +62,13 @@ module Hanami
35
62
  end
36
63
  end
37
64
 
65
+ # Runs another CLI command via its command class.
66
+ #
67
+ # @param klass [Hanami::CLI::Command]
68
+ # @param args [Array] any additional arguments to pass to the command's `#call` method.
69
+ #
70
+ # @since 2.0.0
71
+ # @api public
38
72
  def run_command(klass, *args)
39
73
  klass.new(
40
74
  out: out,
@@ -43,6 +77,27 @@ module Hanami
43
77
  ).call(*args)
44
78
  end
45
79
 
80
+ # Executes a given block and prints string to the `out` stream with details of the time
81
+ # taken to execute.
82
+ #
83
+ # If the block returns a falsey value, then a failure message is printed.
84
+ #
85
+ # @example
86
+ # measure("Reverse the polarity of the neutron flow") do
87
+ # # reverses the polarity, returns a truthy value
88
+ # end
89
+ # # printed to `out`:
90
+ # # => Reverse the polarity of the neutron flow in 2s
91
+ #
92
+ # @example
93
+ # measure("Disable the time dilation device") do
94
+ # # attempts to disable the device, returns a falsey favlue
95
+ # end
96
+ # # printed to `out`:
97
+ # # !!! => Disable the time dilation device FAILED
98
+ #
99
+ # @since 2.0.0
100
+ # @api public
46
101
  def measure(desc)
47
102
  start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
48
103
  result = yield
@@ -55,10 +110,16 @@ module Hanami
55
110
  end
56
111
  end
57
112
 
113
+ # This is NOT AVAILABLE as of the 2.0.0 release.
114
+ #
115
+ # @api private
58
116
  def database
59
117
  @database ||= Commands::DB::Utils::Database[app]
60
118
  end
61
119
 
120
+ # This is NOT AVAILABLE as of the 2.0.0 release.
121
+ #
122
+ # @api private
62
123
  def database_config
63
124
  database.config
64
125
  end
@@ -8,23 +8,26 @@ module Hanami
8
8
  module CLI
9
9
  module Commands
10
10
  module App
11
- # @api public
11
+ # @since 2.0.0
12
+ # @api private
12
13
  class Console < App::Command
14
+ # @since 2.0.0
15
+ # @api private
13
16
  ENGINES = {
14
17
  "pry" => -> (*args) {
15
18
  begin
16
- require "hanami/cli/repl/pry"
17
19
  Repl::Pry.new(*args)
18
20
  rescue LoadError # rubocop:disable Lint/SuppressedException
19
21
  end
20
22
  },
21
23
  "irb" => -> (*args) {
22
- require "hanami/cli/repl/irb"
23
24
  Repl::Irb.new(*args)
24
25
  },
25
26
  }.freeze
26
27
  private_constant :ENGINES
27
28
 
29
+ # @since 2.0.0
30
+ # @api private
28
31
  DEFAULT_ENGINE = "irb"
29
32
  private_constant :DEFAULT_ENGINE
30
33
 
@@ -32,6 +35,7 @@ module Hanami
32
35
 
33
36
  option :engine, required: false, desc: "Console engine", values: ENGINES.keys
34
37
 
38
+ # @since 2.0.0
35
39
  # @api private
36
40
  def call(engine: nil, **opts)
37
41
  console_engine = resolve_engine(engine, opts)
@@ -7,9 +7,11 @@ module Hanami
7
7
  module Commands
8
8
  module App
9
9
  module DB
10
+ # @api private
10
11
  class Create < App::Command
11
12
  desc "Create database"
12
13
 
14
+ # @api private
13
15
  def call(**)
14
16
  if database.create_command
15
17
  out.puts "=> database #{database.name} created"
@@ -7,12 +7,15 @@ module Hanami
7
7
  module CLI
8
8
  module Commands
9
9
  module App
10
+ # @api private
10
11
  module DB
12
+ # @api private
11
13
  class CreateMigration < App::Command
12
14
  desc "Create new migration file"
13
15
 
14
16
  argument :name, desc: "Migration file name"
15
17
 
18
+ # @api private
16
19
  def call(name:, **)
17
20
  migrator = database.migrator
18
21
  version = migrator.generate_version
@@ -7,9 +7,11 @@ module Hanami
7
7
  module Commands
8
8
  module App
9
9
  module DB
10
+ # @api private
10
11
  class Drop < App::Command
11
12
  desc "Delete database"
12
13
 
14
+ # @api private
13
15
  def call(**)
14
16
  if database.drop_command
15
17
  out.puts "=> database #{database.name} dropped"
@@ -8,11 +8,13 @@ module Hanami
8
8
  module Commands
9
9
  module App
10
10
  module DB
11
+ # @api private
11
12
  class Migrate < App::Command
12
13
  desc "Migrates database"
13
14
 
14
15
  option :target, desc: "Target migration number", aliases: ["-t"]
15
16
 
17
+ # @api private
16
18
  def call(target: nil, **)
17
19
  return true if Dir[File.join(app.root, "db/migrate/*.rb")].empty?
18
20
 
@@ -10,9 +10,11 @@ module Hanami
10
10
  module Commands
11
11
  module App
12
12
  module DB
13
+ # @api private
13
14
  class Reset < App::Command
14
15
  desc "Drop, create, and migrate database"
15
16
 
17
+ # @api private
16
18
  def call(**)
17
19
  run_command Drop
18
20
  run_command Create
@@ -8,12 +8,14 @@ module Hanami
8
8
  module Commands
9
9
  module App
10
10
  module DB
11
+ # @api private
11
12
  class Rollback < App::Command
12
13
  desc "Rollback database to a previous migration"
13
14
 
14
15
  option :target, desc: "Target migration number", aliases: ["-t"]
15
16
  option :dump, desc: "Dump structure after rolling back"
16
17
 
18
+ # @api private
17
19
  def call(target: nil, dump: true, **)
18
20
  migration_code, migration_name = find_migration(target)
19
21
 
@@ -8,11 +8,13 @@ module Hanami
8
8
  module Commands
9
9
  module App
10
10
  module DB
11
+ # @api private
11
12
  class SampleData < App::Command
12
13
  FILE_PATH = "db/sample_data.rb"
13
14
 
14
15
  desc "Load sample data"
15
16
 
17
+ # @api private
16
18
  def call(**)
17
19
  if has_file?
18
20
  measure "sample data loaded from #{FILE_PATH}" do
@@ -8,11 +8,13 @@ module Hanami
8
8
  module Commands
9
9
  module App
10
10
  module DB
11
+ # @api private
11
12
  class Seed < App::Command
12
13
  FILE_PATH = "db/seeds.rb"
13
14
 
14
15
  desc "Load seed data"
15
16
 
17
+ # @api private
16
18
  def call(**)
17
19
  if has_file?
18
20
  measure "seed data loaded from #{FILE_PATH}" do
@@ -9,9 +9,11 @@ module Hanami
9
9
  module Commands
10
10
  module App
11
11
  module DB
12
+ # @api private
12
13
  class Setup < App::Command
13
14
  desc "Setup database"
14
15
 
16
+ # @api private
15
17
  def call(**)
16
18
  run_command Create
17
19
  run_command Migrate
@@ -7,10 +7,13 @@ module Hanami
7
7
  module Commands
8
8
  module App
9
9
  module DB
10
+ # @api private
10
11
  module Structure
12
+ # @api private
11
13
  class Dump < App::Command
12
14
  desc "Dumps database structure to db/structure.sql file"
13
15
 
16
+ # @api private
14
17
  def call(*)
15
18
  measure("#{database.name} structure dumped to db/structure.sql") do
16
19
  database.dump_command