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.
Files changed (101) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +42 -0
  3. data/.gitignore +4 -2
  4. data/.rspec +1 -0
  5. data/.rubocop.yml +24 -0
  6. data/CHANGELOG.md +14 -1
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +8 -2
  9. data/LICENSE.txt +21 -0
  10. data/README.md +12 -605
  11. data/Rakefile +5 -10
  12. data/exe/hanami +10 -0
  13. data/hanami-cli.gemspec +21 -17
  14. data/lib/hanami/cli.rb +9 -122
  15. data/lib/hanami/cli/bundler.rb +73 -0
  16. data/lib/hanami/cli/command.rb +14 -386
  17. data/lib/hanami/cli/command_line.rb +17 -0
  18. data/lib/hanami/cli/commands.rb +26 -0
  19. data/lib/hanami/cli/commands/application.rb +63 -0
  20. data/lib/hanami/cli/commands/db/utils/database.rb +122 -0
  21. data/lib/hanami/cli/commands/db/utils/database_config.rb +48 -0
  22. data/lib/hanami/cli/commands/db/utils/mysql.rb +27 -0
  23. data/lib/hanami/cli/commands/db/utils/postgres.rb +49 -0
  24. data/lib/hanami/cli/commands/db/utils/sqlite.rb +37 -0
  25. data/lib/hanami/cli/commands/gem.rb +21 -0
  26. data/lib/hanami/cli/commands/gem/new.rb +77 -0
  27. data/lib/hanami/cli/commands/gem/version.rb +18 -0
  28. data/lib/hanami/cli/commands/monolith.rb +55 -0
  29. data/lib/hanami/cli/commands/monolith/console.rb +50 -0
  30. data/lib/hanami/cli/commands/monolith/db/create.rb +25 -0
  31. data/lib/hanami/cli/commands/monolith/db/create_migration.rb +29 -0
  32. data/lib/hanami/cli/commands/monolith/db/drop.rb +25 -0
  33. data/lib/hanami/cli/commands/monolith/db/migrate.rb +40 -0
  34. data/lib/hanami/cli/commands/monolith/db/reset.rb +26 -0
  35. data/lib/hanami/cli/commands/monolith/db/rollback.rb +55 -0
  36. data/lib/hanami/cli/commands/monolith/db/sample_data.rb +40 -0
  37. data/lib/hanami/cli/commands/monolith/db/seed.rb +40 -0
  38. data/lib/hanami/cli/commands/monolith/db/setup.rb +24 -0
  39. data/lib/hanami/cli/commands/monolith/db/structure/dump.rb +25 -0
  40. data/lib/hanami/cli/commands/monolith/db/version.rb +26 -0
  41. data/lib/hanami/cli/commands/monolith/generate.rb +14 -0
  42. data/lib/hanami/cli/commands/monolith/generate/action.rb +62 -0
  43. data/lib/hanami/cli/commands/monolith/generate/slice.rb +62 -0
  44. data/lib/hanami/cli/commands/monolith/install.rb +16 -0
  45. data/lib/hanami/cli/commands/monolith/version.rb +18 -0
  46. data/lib/hanami/cli/error.rb +8 -0
  47. data/lib/hanami/cli/generators/context.rb +38 -0
  48. data/lib/hanami/cli/generators/gem/application.rb +21 -0
  49. data/lib/hanami/cli/generators/gem/application/monolith.rb +83 -0
  50. data/lib/hanami/cli/generators/gem/application/monolith/action.erb +21 -0
  51. data/lib/hanami/cli/generators/gem/application/monolith/application.erb +8 -0
  52. data/lib/hanami/cli/generators/gem/application/monolith/config_ru.erb +5 -0
  53. data/lib/hanami/cli/generators/gem/application/monolith/entities.erb +9 -0
  54. data/lib/hanami/cli/generators/gem/application/monolith/env.erb +0 -0
  55. data/lib/hanami/cli/generators/gem/application/monolith/functions.erb +13 -0
  56. data/lib/hanami/cli/generators/gem/application/monolith/gemfile.erb +19 -0
  57. data/lib/hanami/cli/generators/gem/application/monolith/keep.erb +0 -0
  58. data/lib/hanami/cli/generators/gem/application/monolith/operation.erb +18 -0
  59. data/lib/hanami/cli/generators/gem/application/monolith/rakefile.erb +3 -0
  60. data/lib/hanami/cli/generators/gem/application/monolith/readme.erb +1 -0
  61. data/lib/hanami/cli/generators/gem/application/monolith/repository.erb +13 -0
  62. data/lib/hanami/cli/generators/gem/application/monolith/routes.erb +4 -0
  63. data/lib/hanami/cli/generators/gem/application/monolith/settings.erb +6 -0
  64. data/lib/hanami/cli/generators/gem/application/monolith/types.erb +10 -0
  65. data/lib/hanami/cli/generators/gem/application/monolith/validation_contract.erb +14 -0
  66. data/lib/hanami/cli/generators/gem/application/monolith/view_context.erb +15 -0
  67. data/lib/hanami/cli/generators/monolith/action.rb +123 -0
  68. data/lib/hanami/cli/generators/monolith/action/action.erb +13 -0
  69. data/lib/hanami/cli/generators/monolith/action/template.erb +0 -0
  70. data/lib/hanami/cli/generators/monolith/action/template.html.erb +2 -0
  71. data/lib/hanami/cli/generators/monolith/action/view.erb +13 -0
  72. data/lib/hanami/cli/generators/monolith/action_context.rb +76 -0
  73. data/lib/hanami/cli/generators/monolith/slice.rb +56 -0
  74. data/lib/hanami/cli/generators/monolith/slice/action.erb +9 -0
  75. data/lib/hanami/cli/generators/monolith/slice/entities.erb +9 -0
  76. data/lib/hanami/cli/generators/monolith/slice/keep.erb +0 -0
  77. data/lib/hanami/cli/generators/monolith/slice/repository.erb +10 -0
  78. data/lib/hanami/cli/generators/monolith/slice/routes.erb +2 -0
  79. data/lib/hanami/cli/generators/monolith/slice/view.erb +9 -0
  80. data/lib/hanami/cli/generators/monolith/slice_context.rb +33 -0
  81. data/lib/hanami/cli/repl/core.rb +55 -0
  82. data/lib/hanami/cli/repl/irb.rb +41 -0
  83. data/lib/hanami/cli/repl/pry.rb +29 -0
  84. data/lib/hanami/cli/system_call.rb +51 -0
  85. data/lib/hanami/cli/url.rb +34 -0
  86. data/lib/hanami/cli/version.rb +2 -3
  87. data/lib/hanami/console/context.rb +39 -0
  88. data/lib/hanami/console/plugins/slice_readers.rb +42 -0
  89. data/lib/hanami/rake_tasks.rb +52 -0
  90. metadata +134 -43
  91. data/.circleci/config.yml +0 -63
  92. data/.travis.yml +0 -22
  93. data/lib/hanami/cli/banner.rb +0 -129
  94. data/lib/hanami/cli/command_registry.rb +0 -215
  95. data/lib/hanami/cli/errors.rb +0 -46
  96. data/lib/hanami/cli/option.rb +0 -134
  97. data/lib/hanami/cli/parser.rb +0 -144
  98. data/lib/hanami/cli/program_name.rb +0 -21
  99. data/lib/hanami/cli/registry.rb +0 -330
  100. data/lib/hanami/cli/usage.rb +0 -91
  101. data/script/ci +0 -61
@@ -1,91 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "hanami/cli/program_name"
4
-
5
- module Hanami
6
- class CLI
7
- # Command(s) usage
8
- #
9
- # @since 0.1.0
10
- # @api private
11
- module Usage
12
- # @since 0.1.0
13
- # @api private
14
- SUBCOMMAND_BANNER = " [SUBCOMMAND]"
15
-
16
- # @since 0.1.0
17
- # @api private
18
- def self.call(result, out)
19
- out.puts "Commands:"
20
- max_length, commands = commands_and_arguments(result)
21
-
22
- commands.each do |banner, node|
23
- usage = description(node.command) if node.leaf?
24
- out.puts "#{justify(banner, max_length, usage)}#{usage}"
25
- end
26
- end
27
-
28
- # @since 0.1.0
29
- # @api private
30
- def self.commands_and_arguments(result) # rubocop:disable Metrics/MethodLength
31
- max_length = 0
32
- ret = commands(result).each_with_object({}) do |(name, node), memo|
33
- args = if node.leaf?
34
- arguments(node.command)
35
- else
36
- SUBCOMMAND_BANNER
37
- end
38
-
39
- partial = " #{command_name(result, name)}#{args}"
40
- max_length = partial.bytesize if max_length < partial.bytesize
41
- memo[partial] = node
42
- end
43
-
44
- [max_length, ret]
45
- end
46
-
47
- # @since 0.1.0
48
- # @api private
49
- def self.arguments(command) # rubocop:disable Metrics/AbcSize
50
- return unless CLI.command?(command)
51
-
52
- required_arguments = command.required_arguments
53
- optional_arguments = command.optional_arguments
54
-
55
- required = required_arguments.map { |arg| arg.name.upcase }.join(" ") if required_arguments.any?
56
- optional = optional_arguments.map { |arg| "[#{arg.name.upcase}]" }.join(" ") if optional_arguments.any?
57
- result = [required, optional].compact
58
-
59
- " #{result.join(' ')}" unless result.empty?
60
- end
61
-
62
- # @since 0.1.0
63
- # @api private
64
- def self.description(command)
65
- return unless CLI.command?(command)
66
-
67
- " # #{command.description}" unless command.description.nil?
68
- end
69
-
70
- # @since 0.1.0
71
- # @api private
72
- def self.justify(string, padding, usage)
73
- return string.chomp(" ") if usage.nil?
74
-
75
- string.ljust(padding + padding / 2)
76
- end
77
-
78
- # @since 0.1.0
79
- # @api private
80
- def self.commands(result)
81
- result.children.sort_by { |name, _| name }
82
- end
83
-
84
- # @since 0.1.0
85
- # @api private
86
- def self.command_name(result, name)
87
- ProgramName.call([result.names, name])
88
- end
89
- end
90
- end
91
- end
data/script/ci DELETED
@@ -1,61 +0,0 @@
1
- #!/bin/bash
2
- set -euo pipefail
3
- IFS=$'\n\t'
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
-
16
- run_code_quality_checks() {
17
- bundle exec rubocop .
18
- }
19
-
20
- run_unit_tests() {
21
- bundle exec rake spec:unit
22
- }
23
-
24
- run_integration_tests() {
25
- local pwd=$PWD
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
38
- }
39
-
40
- run_test() {
41
- local test=$1
42
- local hash="$(shasum "$test" | cut -b 1-40)"
43
-
44
- printf "\n\n\nRunning: $test\n"
45
- SIMPLECOV_COMMAND_NAME=$hash bundle exec rspec $test
46
- }
47
-
48
- upload_code_coverage() {
49
- bundle exec rake codecov:upload
50
- }
51
-
52
- main() {
53
- prepare_build &&
54
- print_ruby_version &&
55
- run_code_quality_checks &&
56
- run_unit_tests &&
57
- run_integration_tests &&
58
- upload_code_coverage
59
- }
60
-
61
- main