hanami-cli 1.0.0.alpha1 → 2.0.0.alpha2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yml +42 -0
- data/.gitignore +4 -2
- data/.rspec +1 -0
- data/.rubocop.yml +24 -0
- data/CHANGELOG.md +14 -1
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +8 -2
- data/LICENSE.txt +21 -0
- data/README.md +12 -605
- data/Rakefile +5 -10
- data/exe/hanami +10 -0
- data/hanami-cli.gemspec +21 -17
- data/lib/hanami/cli.rb +9 -122
- data/lib/hanami/cli/bundler.rb +73 -0
- data/lib/hanami/cli/command.rb +14 -386
- data/lib/hanami/cli/command_line.rb +17 -0
- data/lib/hanami/cli/commands.rb +26 -0
- data/lib/hanami/cli/commands/application.rb +63 -0
- data/lib/hanami/cli/commands/db/utils/database.rb +122 -0
- data/lib/hanami/cli/commands/db/utils/database_config.rb +48 -0
- data/lib/hanami/cli/commands/db/utils/mysql.rb +27 -0
- data/lib/hanami/cli/commands/db/utils/postgres.rb +49 -0
- data/lib/hanami/cli/commands/db/utils/sqlite.rb +37 -0
- data/lib/hanami/cli/commands/gem.rb +21 -0
- data/lib/hanami/cli/commands/gem/new.rb +77 -0
- data/lib/hanami/cli/commands/gem/version.rb +18 -0
- data/lib/hanami/cli/commands/monolith.rb +55 -0
- data/lib/hanami/cli/commands/monolith/console.rb +50 -0
- data/lib/hanami/cli/commands/monolith/db/create.rb +25 -0
- data/lib/hanami/cli/commands/monolith/db/create_migration.rb +29 -0
- data/lib/hanami/cli/commands/monolith/db/drop.rb +25 -0
- data/lib/hanami/cli/commands/monolith/db/migrate.rb +40 -0
- data/lib/hanami/cli/commands/monolith/db/reset.rb +26 -0
- data/lib/hanami/cli/commands/monolith/db/rollback.rb +55 -0
- data/lib/hanami/cli/commands/monolith/db/sample_data.rb +40 -0
- data/lib/hanami/cli/commands/monolith/db/seed.rb +40 -0
- data/lib/hanami/cli/commands/monolith/db/setup.rb +24 -0
- data/lib/hanami/cli/commands/monolith/db/structure/dump.rb +25 -0
- data/lib/hanami/cli/commands/monolith/db/version.rb +26 -0
- data/lib/hanami/cli/commands/monolith/generate.rb +14 -0
- data/lib/hanami/cli/commands/monolith/generate/action.rb +62 -0
- data/lib/hanami/cli/commands/monolith/generate/slice.rb +62 -0
- data/lib/hanami/cli/commands/monolith/install.rb +16 -0
- data/lib/hanami/cli/commands/monolith/version.rb +18 -0
- data/lib/hanami/cli/error.rb +8 -0
- data/lib/hanami/cli/generators/context.rb +38 -0
- data/lib/hanami/cli/generators/gem/application.rb +21 -0
- data/lib/hanami/cli/generators/gem/application/monolith.rb +83 -0
- data/lib/hanami/cli/generators/gem/application/monolith/action.erb +21 -0
- data/lib/hanami/cli/generators/gem/application/monolith/application.erb +8 -0
- data/lib/hanami/cli/generators/gem/application/monolith/config_ru.erb +5 -0
- data/lib/hanami/cli/generators/gem/application/monolith/entities.erb +9 -0
- data/lib/hanami/cli/generators/gem/application/monolith/env.erb +0 -0
- data/lib/hanami/cli/generators/gem/application/monolith/functions.erb +13 -0
- data/lib/hanami/cli/generators/gem/application/monolith/gemfile.erb +19 -0
- data/lib/hanami/cli/generators/gem/application/monolith/keep.erb +0 -0
- data/lib/hanami/cli/generators/gem/application/monolith/operation.erb +18 -0
- data/lib/hanami/cli/generators/gem/application/monolith/rakefile.erb +3 -0
- data/lib/hanami/cli/generators/gem/application/monolith/readme.erb +1 -0
- data/lib/hanami/cli/generators/gem/application/monolith/repository.erb +13 -0
- data/lib/hanami/cli/generators/gem/application/monolith/routes.erb +4 -0
- data/lib/hanami/cli/generators/gem/application/monolith/settings.erb +6 -0
- data/lib/hanami/cli/generators/gem/application/monolith/types.erb +10 -0
- data/lib/hanami/cli/generators/gem/application/monolith/validation_contract.erb +14 -0
- data/lib/hanami/cli/generators/gem/application/monolith/view_context.erb +15 -0
- data/lib/hanami/cli/generators/monolith/action.rb +123 -0
- data/lib/hanami/cli/generators/monolith/action/action.erb +13 -0
- data/lib/hanami/cli/generators/monolith/action/template.erb +0 -0
- data/lib/hanami/cli/generators/monolith/action/template.html.erb +2 -0
- data/lib/hanami/cli/generators/monolith/action/view.erb +13 -0
- data/lib/hanami/cli/generators/monolith/action_context.rb +76 -0
- data/lib/hanami/cli/generators/monolith/slice.rb +56 -0
- data/lib/hanami/cli/generators/monolith/slice/action.erb +9 -0
- data/lib/hanami/cli/generators/monolith/slice/entities.erb +9 -0
- data/lib/hanami/cli/generators/monolith/slice/keep.erb +0 -0
- data/lib/hanami/cli/generators/monolith/slice/repository.erb +10 -0
- data/lib/hanami/cli/generators/monolith/slice/routes.erb +2 -0
- data/lib/hanami/cli/generators/monolith/slice/view.erb +9 -0
- data/lib/hanami/cli/generators/monolith/slice_context.rb +33 -0
- data/lib/hanami/cli/repl/core.rb +55 -0
- data/lib/hanami/cli/repl/irb.rb +41 -0
- data/lib/hanami/cli/repl/pry.rb +29 -0
- data/lib/hanami/cli/system_call.rb +51 -0
- data/lib/hanami/cli/url.rb +34 -0
- data/lib/hanami/cli/version.rb +2 -3
- data/lib/hanami/console/context.rb +39 -0
- data/lib/hanami/console/plugins/slice_readers.rb +42 -0
- data/lib/hanami/rake_tasks.rb +52 -0
- metadata +134 -43
- data/.circleci/config.yml +0 -63
- data/.travis.yml +0 -22
- data/lib/hanami/cli/banner.rb +0 -129
- data/lib/hanami/cli/command_registry.rb +0 -215
- data/lib/hanami/cli/errors.rb +0 -46
- data/lib/hanami/cli/option.rb +0 -134
- data/lib/hanami/cli/parser.rb +0 -144
- data/lib/hanami/cli/program_name.rb +0 -21
- data/lib/hanami/cli/registry.rb +0 -330
- data/lib/hanami/cli/usage.rb +0 -91
- data/script/ci +0 -61
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/cli/command"
|
4
|
+
|
5
|
+
module Hanami
|
6
|
+
module CLI
|
7
|
+
module Commands
|
8
|
+
module Gem
|
9
|
+
class Version < Command
|
10
|
+
def call(*)
|
11
|
+
require "hanami/version"
|
12
|
+
out.puts "v#{Hanami::VERSION}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Hanami
|
4
|
+
module CLI
|
5
|
+
module Commands
|
6
|
+
module Monolith
|
7
|
+
require_relative "monolith/version"
|
8
|
+
# require_relative "monolith/install"
|
9
|
+
# require_relative "monolith/generate"
|
10
|
+
require_relative "monolith/install"
|
11
|
+
require_relative "monolith/generate"
|
12
|
+
require_relative "monolith/console"
|
13
|
+
require_relative "monolith/db/create"
|
14
|
+
require_relative "monolith/db/create_migration"
|
15
|
+
require_relative "monolith/db/drop"
|
16
|
+
require_relative "monolith/db/migrate"
|
17
|
+
require_relative "monolith/db/setup"
|
18
|
+
require_relative "monolith/db/reset"
|
19
|
+
require_relative "monolith/db/rollback"
|
20
|
+
require_relative "monolith/db/sample_data"
|
21
|
+
require_relative "monolith/db/seed"
|
22
|
+
require_relative "monolith/db/structure/dump"
|
23
|
+
require_relative "monolith/db/version"
|
24
|
+
|
25
|
+
def self.extended(base)
|
26
|
+
base.module_eval do
|
27
|
+
register "version", Version, aliases: ["v", "-v", "--version"]
|
28
|
+
# FIXME: temporary disabled for Hanami v2.0.0.alpha2
|
29
|
+
# register "install", Install
|
30
|
+
|
31
|
+
# FIXME: temporary disabled for Hanami v2.0.0.alpha2
|
32
|
+
# register "generate", aliases: ["g"] do |prefix|
|
33
|
+
# prefix.register "slice", Generate::Slice
|
34
|
+
# prefix.register "action", Generate::Action
|
35
|
+
# end
|
36
|
+
|
37
|
+
register "console", Commands::Monolith::Console
|
38
|
+
|
39
|
+
register "db create", Commands::Monolith::DB::Create
|
40
|
+
register "db create_migration", Commands::Monolith::DB::CreateMigration
|
41
|
+
register "db drop", Commands::Monolith::DB::Drop
|
42
|
+
register "db migrate", Commands::Monolith::DB::Migrate
|
43
|
+
register "db setup", Commands::Monolith::DB::Setup
|
44
|
+
register "db reset", Commands::Monolith::DB::Reset
|
45
|
+
register "db rollback", Commands::Monolith::DB::Rollback
|
46
|
+
register "db sample_data", Commands::Monolith::DB::SampleData
|
47
|
+
register "db seed", Commands::Monolith::DB::Seed
|
48
|
+
register "db structure dump", Commands::Monolith::DB::Structure::Dump
|
49
|
+
register "db version", Commands::Monolith::DB::Version
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "hanami/console/context"
|
4
|
+
|
5
|
+
require_relative "../application"
|
6
|
+
|
7
|
+
module Hanami
|
8
|
+
module CLI
|
9
|
+
module Commands
|
10
|
+
module Monolith
|
11
|
+
# @api public
|
12
|
+
class Console < Application
|
13
|
+
REPLS = {
|
14
|
+
"pry" => -> *args {
|
15
|
+
begin
|
16
|
+
require "hanami/cli/repl/pry"
|
17
|
+
Repl::Pry.new(*args)
|
18
|
+
rescue LoadError; end
|
19
|
+
},
|
20
|
+
"irb" => -> *args {
|
21
|
+
require "hanami/cli/repl/irb"
|
22
|
+
Repl::Irb.new(*args)
|
23
|
+
},
|
24
|
+
}.freeze
|
25
|
+
|
26
|
+
desc "Application REPL"
|
27
|
+
|
28
|
+
option :repl, required: false, desc: "REPL gem that should be used"
|
29
|
+
|
30
|
+
# @api private
|
31
|
+
def call(repl: nil, **opts)
|
32
|
+
engine = resolve_engine(repl, opts)
|
33
|
+
engine.start
|
34
|
+
end
|
35
|
+
|
36
|
+
private
|
37
|
+
|
38
|
+
# @api private
|
39
|
+
def resolve_engine(repl, opts)
|
40
|
+
if repl
|
41
|
+
REPLS.fetch(repl).(application, opts)
|
42
|
+
else
|
43
|
+
REPLS.map { |(_, loader)| loader.(application, opts) }.compact.first
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
|
5
|
+
module Hanami
|
6
|
+
module CLI
|
7
|
+
module Commands
|
8
|
+
module Monolith
|
9
|
+
module DB
|
10
|
+
class Create < Application
|
11
|
+
desc "Create database"
|
12
|
+
|
13
|
+
def call(**)
|
14
|
+
if database.create_command
|
15
|
+
out.puts "=> database #{database.name} created"
|
16
|
+
else
|
17
|
+
out.puts "=> failed to create database #{database.name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "structure/dump"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module Monolith
|
10
|
+
module DB
|
11
|
+
class CreateMigration < Application
|
12
|
+
desc "Create new migration file"
|
13
|
+
|
14
|
+
argument :name, desc: "Migration file name"
|
15
|
+
|
16
|
+
def call(name:, **)
|
17
|
+
migrator = database.migrator
|
18
|
+
version = migrator.generate_version
|
19
|
+
|
20
|
+
measure "migration #{version}_#{name} created" do
|
21
|
+
migrator.create_file(name, version)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
|
5
|
+
module Hanami
|
6
|
+
module CLI
|
7
|
+
module Commands
|
8
|
+
module Monolith
|
9
|
+
module DB
|
10
|
+
class Drop < Application
|
11
|
+
desc "Delete database"
|
12
|
+
|
13
|
+
def call(**)
|
14
|
+
if database.drop_command
|
15
|
+
out.puts "=> database #{database.name} dropped"
|
16
|
+
else
|
17
|
+
out.puts "=> failed to drop #{database.name}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "structure/dump"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module Monolith
|
10
|
+
module DB
|
11
|
+
class Migrate < Application
|
12
|
+
desc "Migrates database"
|
13
|
+
|
14
|
+
option :target, desc: "Target migration number", aliases: ["-t"]
|
15
|
+
|
16
|
+
def call(target: nil, **)
|
17
|
+
return true if Dir[File.join(application.root, "db/migrate/*.rb")].empty?
|
18
|
+
|
19
|
+
measure "database #{database.name} migrated" do
|
20
|
+
if target
|
21
|
+
run_migrations(target: Integer(target))
|
22
|
+
else
|
23
|
+
run_migrations
|
24
|
+
end
|
25
|
+
|
26
|
+
true
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def run_migrations(**options)
|
33
|
+
database.run_migrations(**options)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "create"
|
5
|
+
require_relative "drop"
|
6
|
+
require_relative "migrate"
|
7
|
+
|
8
|
+
module Hanami
|
9
|
+
module CLI
|
10
|
+
module Commands
|
11
|
+
module Monolith
|
12
|
+
module DB
|
13
|
+
class Reset < Application
|
14
|
+
desc "Drop, create, and migrate database"
|
15
|
+
|
16
|
+
def call(**)
|
17
|
+
run_command Drop
|
18
|
+
run_command Create
|
19
|
+
run_command Migrate
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "structure/dump"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module Monolith
|
10
|
+
module DB
|
11
|
+
class Rollback < Application
|
12
|
+
desc "Rollback database to a previous migration"
|
13
|
+
|
14
|
+
option :target, desc: "Target migration number", aliases: ["-t"]
|
15
|
+
option :dump, desc: "Dump structure after rolling back"
|
16
|
+
|
17
|
+
def call(target: nil, dump: true, **)
|
18
|
+
migration_code, migration_name = find_migration(target)
|
19
|
+
|
20
|
+
if migration_name.nil?
|
21
|
+
out.puts "==> migration file for target #{target} was not found"
|
22
|
+
return
|
23
|
+
end
|
24
|
+
|
25
|
+
measure "database #{database.name} rolled back to #{migration_name}" do
|
26
|
+
database.run_migrations(target: Integer(migration_code))
|
27
|
+
end
|
28
|
+
|
29
|
+
run_command Structure::Dump if dump
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def find_migration(code)
|
35
|
+
migration = database.applied_migrations.yield_self { |migrations|
|
36
|
+
if code
|
37
|
+
migrations.detect { |m| m.split("_").first == code }
|
38
|
+
else
|
39
|
+
migrations.last
|
40
|
+
end
|
41
|
+
}
|
42
|
+
|
43
|
+
return unless migration
|
44
|
+
|
45
|
+
migration_code = code || migration.split("_").first
|
46
|
+
migration_name = File.basename(migration, ".*")
|
47
|
+
|
48
|
+
[migration_code, migration_name]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "structure/dump"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module Monolith
|
10
|
+
module DB
|
11
|
+
class SampleData < Application
|
12
|
+
FILE_PATH = "db/sample_data.rb"
|
13
|
+
|
14
|
+
desc "Load sample data"
|
15
|
+
|
16
|
+
def call(**)
|
17
|
+
if has_file?
|
18
|
+
measure "sample data loaded from #{FILE_PATH}" do
|
19
|
+
load full_file_path
|
20
|
+
end
|
21
|
+
else
|
22
|
+
out.puts "=> #{FILE_PATH} not found"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def full_file_path
|
29
|
+
File.join(application.root, FILE_PATH)
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_file?
|
33
|
+
File.exist?(full_file_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "structure/dump"
|
5
|
+
|
6
|
+
module Hanami
|
7
|
+
module CLI
|
8
|
+
module Commands
|
9
|
+
module Monolith
|
10
|
+
module DB
|
11
|
+
class Seed < Application
|
12
|
+
FILE_PATH = "db/seeds.rb"
|
13
|
+
|
14
|
+
desc "Load seed data"
|
15
|
+
|
16
|
+
def call(**)
|
17
|
+
if has_file?
|
18
|
+
measure "seed data loaded from #{FILE_PATH}" do
|
19
|
+
load full_file_path
|
20
|
+
end
|
21
|
+
else
|
22
|
+
out.puts "=> #{FILE_PATH} not found"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def full_file_path
|
29
|
+
File.join(application.root, FILE_PATH)
|
30
|
+
end
|
31
|
+
|
32
|
+
def has_file?
|
33
|
+
File.exist?(full_file_path)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "../../application"
|
4
|
+
require_relative "create"
|
5
|
+
require_relative "migrate"
|
6
|
+
|
7
|
+
module Hanami
|
8
|
+
module CLI
|
9
|
+
module Commands
|
10
|
+
module Monolith
|
11
|
+
module DB
|
12
|
+
class Setup < Application
|
13
|
+
desc "Setup database"
|
14
|
+
|
15
|
+
def call(**)
|
16
|
+
run_command Create
|
17
|
+
run_command Migrate
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|