rfix 1.4.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (219) hide show
  1. checksums.yaml +4 -4
  2. data/exe/rfix +78 -34
  3. data/lib/rfix.rb +17 -28
  4. data/lib/rfix/branch.rb +3 -25
  5. data/lib/rfix/branch/base.rb +27 -0
  6. data/lib/rfix/branch/head.rb +15 -0
  7. data/lib/rfix/branch/main.rb +33 -0
  8. data/lib/rfix/branch/name.rb +21 -0
  9. data/lib/rfix/branch/reference.rb +15 -0
  10. data/lib/rfix/branch/upstream.rb +17 -0
  11. data/lib/rfix/cli/command.rb +19 -0
  12. data/lib/rfix/cli/command/base.rb +61 -0
  13. data/lib/rfix/cli/command/branch.rb +13 -0
  14. data/lib/rfix/cli/command/config.rb +22 -0
  15. data/lib/rfix/cli/command/extension.rb +25 -0
  16. data/lib/rfix/cli/command/help.rb +11 -0
  17. data/lib/rfix/cli/command/info.rb +11 -0
  18. data/lib/rfix/cli/command/lint.rb +17 -0
  19. data/lib/rfix/cli/command/local.rb +11 -0
  20. data/lib/rfix/cli/command/origin.rb +11 -0
  21. data/lib/rfix/cli/command/setup.rb +11 -0
  22. data/lib/rfix/error.rb +5 -1
  23. data/lib/rfix/extension/offense.rb +79 -0
  24. data/lib/rfix/extension/pastel.rb +11 -0
  25. data/lib/rfix/extension/string.rb +12 -0
  26. data/lib/rfix/extension/strings.rb +9 -0
  27. data/lib/rfix/file.rb +6 -41
  28. data/lib/rfix/file/base.rb +73 -0
  29. data/lib/rfix/file/deleted.rb +17 -0
  30. data/lib/rfix/file/ignored.rb +17 -0
  31. data/lib/rfix/file/tracked.rb +42 -0
  32. data/lib/rfix/file/untracked.rb +20 -0
  33. data/lib/rfix/formatter.rb +125 -86
  34. data/lib/rfix/highlighter.rb +118 -0
  35. data/lib/rfix/indicator.rb +19 -0
  36. data/lib/rfix/log.rb +12 -121
  37. data/lib/rfix/rake/gemfile.rb +111 -0
  38. data/lib/rfix/rake/paths.rb +25 -23
  39. data/lib/rfix/rake/support.rb +72 -57
  40. data/lib/rfix/repository.rb +114 -164
  41. data/lib/rfix/types.rb +52 -0
  42. data/lib/rfix/version.rb +1 -1
  43. data/rfix.gemspec +28 -38
  44. data/vendor/dry-cli/CHANGELOG.md +191 -0
  45. data/vendor/dry-cli/CODEOWNERS +1 -0
  46. data/vendor/dry-cli/CODE_OF_CONDUCT.md +13 -0
  47. data/vendor/dry-cli/CONTRIBUTING.md +29 -0
  48. data/vendor/dry-cli/Gemfile +14 -0
  49. data/vendor/dry-cli/Gemfile.devtools +18 -0
  50. data/vendor/dry-cli/LICENSE +20 -0
  51. data/vendor/dry-cli/README.md +29 -0
  52. data/vendor/dry-cli/Rakefile +13 -0
  53. data/vendor/dry-cli/bin/console +15 -0
  54. data/vendor/dry-cli/bin/setup +8 -0
  55. data/vendor/dry-cli/changelog.yml +97 -0
  56. data/vendor/dry-cli/docsite/source/arguments.html.md +57 -0
  57. data/vendor/dry-cli/docsite/source/callbacks.html.md +51 -0
  58. data/vendor/dry-cli/docsite/source/commands-with-subcommands-and-params.md +86 -0
  59. data/vendor/dry-cli/docsite/source/commands.html.md +41 -0
  60. data/vendor/dry-cli/docsite/source/index.html.md +302 -0
  61. data/vendor/dry-cli/docsite/source/options.html.md +51 -0
  62. data/vendor/dry-cli/docsite/source/subcommands.html.md +38 -0
  63. data/vendor/dry-cli/docsite/source/variadic-arguments.html.md +45 -0
  64. data/vendor/dry-cli/dry-cli.gemspec +36 -0
  65. data/vendor/dry-cli/lib/dry/cli.rb +224 -0
  66. data/vendor/dry-cli/lib/dry/cli/banner.rb +135 -0
  67. data/vendor/dry-cli/lib/dry/cli/command.rb +387 -0
  68. data/vendor/dry-cli/lib/dry/cli/command_registry.rb +253 -0
  69. data/vendor/dry-cli/lib/dry/cli/errors.rb +37 -0
  70. data/vendor/dry-cli/lib/dry/cli/inflector.rb +17 -0
  71. data/vendor/dry-cli/lib/dry/cli/inline.rb +75 -0
  72. data/vendor/dry-cli/lib/dry/cli/option.rb +131 -0
  73. data/vendor/dry-cli/lib/dry/cli/parser.rb +138 -0
  74. data/vendor/dry-cli/lib/dry/cli/program_name.rb +21 -0
  75. data/vendor/dry-cli/lib/dry/cli/registry.rb +338 -0
  76. data/vendor/dry-cli/lib/dry/cli/usage.rb +94 -0
  77. data/vendor/dry-cli/lib/dry/cli/version.rb +8 -0
  78. data/vendor/dry-cli/project.yml +13 -0
  79. data/vendor/dry-cli/spec/integration/commands_spec.rb +14 -0
  80. data/vendor/dry-cli/spec/integration/inherited_commands_spec.rb +24 -0
  81. data/vendor/dry-cli/spec/integration/inline_spec.rb +43 -0
  82. data/vendor/dry-cli/spec/integration/processes_errors_spec.rb +29 -0
  83. data/vendor/dry-cli/spec/integration/rendering_spec.rb +31 -0
  84. data/vendor/dry-cli/spec/integration/single_command_spec.rb +81 -0
  85. data/vendor/dry-cli/spec/integration/subcommands_spec.rb +60 -0
  86. data/vendor/dry-cli/spec/integration/third_party_gems_spec.rb +18 -0
  87. data/vendor/dry-cli/spec/spec_helper.rb +15 -0
  88. data/vendor/dry-cli/spec/support/coverage.rb +15 -0
  89. data/vendor/dry-cli/spec/support/files.rb +13 -0
  90. data/vendor/dry-cli/spec/support/fixtures/based +65 -0
  91. data/vendor/dry-cli/spec/support/fixtures/baz +9 -0
  92. data/vendor/dry-cli/spec/support/fixtures/baz_command.rb +19 -0
  93. data/vendor/dry-cli/spec/support/fixtures/foo +588 -0
  94. data/vendor/dry-cli/spec/support/fixtures/infinites +31 -0
  95. data/vendor/dry-cli/spec/support/fixtures/inline +20 -0
  96. data/vendor/dry-cli/spec/support/fixtures/registry.rb +15 -0
  97. data/vendor/dry-cli/spec/support/fixtures/shared_commands.rb +596 -0
  98. data/vendor/dry-cli/spec/support/fixtures/with_block.rb +86 -0
  99. data/vendor/dry-cli/spec/support/fixtures/with_registry.rb +90 -0
  100. data/vendor/dry-cli/spec/support/fixtures/with_zero_arity_block.rb +87 -0
  101. data/vendor/dry-cli/spec/support/helpers.rb +37 -0
  102. data/vendor/dry-cli/spec/support/path.rb +24 -0
  103. data/vendor/dry-cli/spec/support/rspec.rb +26 -0
  104. data/vendor/dry-cli/spec/support/rspec_options.rb +16 -0
  105. data/vendor/dry-cli/spec/support/shared_examples/commands.rb +300 -0
  106. data/vendor/dry-cli/spec/support/shared_examples/inherited_commands.rb +197 -0
  107. data/vendor/dry-cli/spec/support/shared_examples/rendering.rb +181 -0
  108. data/vendor/dry-cli/spec/support/shared_examples/subcommands.rb +226 -0
  109. data/vendor/dry-cli/spec/support/shared_examples/third_party_gems.rb +49 -0
  110. data/vendor/dry-cli/spec/support/warnings.rb +10 -0
  111. data/vendor/dry-cli/spec/unit/dry/cli/cli_spec.rb +123 -0
  112. data/vendor/dry-cli/spec/unit/dry/cli/inflector_spec.rb +26 -0
  113. data/vendor/dry-cli/spec/unit/dry/cli/registry_spec.rb +78 -0
  114. data/vendor/dry-cli/spec/unit/dry/cli/version_spec.rb +7 -0
  115. data/vendor/strings-ansi/CHANGELOG.md +24 -0
  116. data/vendor/strings-ansi/CODE_OF_CONDUCT.md +74 -0
  117. data/vendor/strings-ansi/Gemfile +11 -0
  118. data/{LICENSE.txt → vendor/strings-ansi/LICENSE.txt} +1 -1
  119. data/vendor/strings-ansi/README.md +155 -0
  120. data/vendor/strings-ansi/Rakefile +8 -0
  121. data/vendor/strings-ansi/appveyor.yml +32 -0
  122. data/vendor/strings-ansi/bin/console +14 -0
  123. data/vendor/strings-ansi/bin/setup +8 -0
  124. data/vendor/strings-ansi/lib/strings-ansi.rb +1 -0
  125. data/vendor/strings-ansi/lib/strings/ansi.rb +84 -0
  126. data/vendor/strings-ansi/lib/strings/ansi/extensions.rb +23 -0
  127. data/vendor/strings-ansi/lib/strings/ansi/version.rb +7 -0
  128. data/vendor/strings-ansi/spec/fixtures/ansi_codes.yaml +194 -0
  129. data/vendor/strings-ansi/spec/spec_helper.rb +51 -0
  130. data/vendor/strings-ansi/spec/unit/ansi_spec.rb +15 -0
  131. data/vendor/strings-ansi/spec/unit/extensions_spec.rb +19 -0
  132. data/vendor/strings-ansi/spec/unit/only_ansi_spec.rb +36 -0
  133. data/vendor/strings-ansi/spec/unit/sanitize_spec.rb +53 -0
  134. data/vendor/strings-ansi/strings-ansi.gemspec +34 -0
  135. data/vendor/strings-ansi/tasks/console.rake +11 -0
  136. data/vendor/strings-ansi/tasks/coverage.rake +11 -0
  137. data/vendor/strings-ansi/tasks/spec.rake +29 -0
  138. metadata +274 -188
  139. data/.github/workflows/main.yml +0 -26
  140. data/.gitignore +0 -43
  141. data/.rspec +0 -2
  142. data/.rubocop.yml +0 -87
  143. data/.travis.yml +0 -35
  144. data/Gemfile +0 -2
  145. data/Gemfile.base +0 -14
  146. data/Gemfile.base.lock +0 -172
  147. data/Gemfile.lock +0 -188
  148. data/Guardfile +0 -16
  149. data/Makefile +0 -12
  150. data/README.md +0 -85
  151. data/Rakefile +0 -31
  152. data/bin/bundle +0 -114
  153. data/bin/console +0 -29
  154. data/bin/guard +0 -29
  155. data/bin/rake +0 -29
  156. data/bin/rfix +0 -29
  157. data/bin/rspec +0 -29
  158. data/bin/setup +0 -29
  159. data/ci/Gemfile.rubocop-0.80 +0 -2
  160. data/ci/Gemfile.rubocop-0.80.lock +0 -170
  161. data/ci/Gemfile.rubocop-0.81 +0 -2
  162. data/ci/Gemfile.rubocop-0.81.lock +0 -170
  163. data/ci/Gemfile.rubocop-0.82 +0 -2
  164. data/ci/Gemfile.rubocop-0.82.lock +0 -170
  165. data/ci/Gemfile.rubocop-0.83 +0 -2
  166. data/ci/Gemfile.rubocop-0.83.lock +0 -168
  167. data/ci/Gemfile.rubocop-0.84 +0 -2
  168. data/ci/Gemfile.rubocop-0.84.lock +0 -171
  169. data/ci/Gemfile.rubocop-0.85 +0 -2
  170. data/ci/Gemfile.rubocop-0.85.1 +0 -2
  171. data/ci/Gemfile.rubocop-0.85.1.lock +0 -173
  172. data/ci/Gemfile.rubocop-0.85.lock +0 -173
  173. data/lib/rfix/box.rb +0 -112
  174. data/lib/rfix/branches/base.rb +0 -15
  175. data/lib/rfix/branches/head.rb +0 -13
  176. data/lib/rfix/branches/main.rb +0 -28
  177. data/lib/rfix/branches/name.rb +0 -23
  178. data/lib/rfix/branches/reference.rb +0 -21
  179. data/lib/rfix/branches/upstream.rb +0 -13
  180. data/lib/rfix/cmd.rb +0 -39
  181. data/lib/rfix/commands/branch.rb +0 -15
  182. data/lib/rfix/commands/extensions/options.rb +0 -8
  183. data/lib/rfix/commands/help.rb +0 -7
  184. data/lib/rfix/commands/helper/args.rb +0 -141
  185. data/lib/rfix/commands/helper/help.rb +0 -6
  186. data/lib/rfix/commands/helper/loader.rb +0 -6
  187. data/lib/rfix/commands/helper/option.rb +0 -0
  188. data/lib/rfix/commands/helper/params.rb +0 -0
  189. data/lib/rfix/commands/helper/rubocop.rb +0 -17
  190. data/lib/rfix/commands/info.rb +0 -30
  191. data/lib/rfix/commands/lint.rb +0 -22
  192. data/lib/rfix/commands/local.rb +0 -12
  193. data/lib/rfix/commands/origin.rb +0 -19
  194. data/lib/rfix/commands/setup.rb +0 -29
  195. data/lib/rfix/commands/welcome.rb +0 -24
  196. data/lib/rfix/deleted.rb +0 -13
  197. data/lib/rfix/extensions/extensions.rb +0 -18
  198. data/lib/rfix/extensions/offense.rb +0 -78
  199. data/lib/rfix/extensions/string.rb +0 -8
  200. data/lib/rfix/file_cache.rb +0 -59
  201. data/lib/rfix/git_helper.rb +0 -59
  202. data/lib/rfix/indentation.rb +0 -39
  203. data/lib/rfix/loader/bundler.rb +0 -37
  204. data/lib/rfix/loader/env.rb +0 -33
  205. data/lib/rfix/loader/spec.rb +0 -41
  206. data/lib/rfix/no_file.rb +0 -13
  207. data/lib/rfix/rfix.rb +0 -34
  208. data/lib/rfix/tracked.rb +0 -72
  209. data/lib/rfix/tracked_file.rb +0 -16
  210. data/lib/rfix/untracked.rb +0 -13
  211. data/resources/ps.png +0 -0
  212. data/tasks/bump.rake +0 -11
  213. data/tasks/bundle.rake +0 -17
  214. data/tasks/complex.rake +0 -54
  215. data/tasks/execute.rake +0 -38
  216. data/tasks/libgit2.rake +0 -33
  217. data/tasks/simple.rake +0 -62
  218. data/tasks/travis.rake +0 -74
  219. data/tasks/vendor.rake +0 -34
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # this file is managed by dry-rb/devtools
4
+
5
+ if ENV["COVERAGE"] == "true"
6
+ require "simplecov"
7
+ require "simplecov-cobertura"
8
+
9
+ SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
10
+
11
+ SimpleCov.start do
12
+ add_filter "/spec/"
13
+ enable_coverage :branch
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rspec/expectations"
4
+
5
+ RSpec::Matchers.define :have_content do |expected|
6
+ match do |actual|
7
+ File.read(actual) == expected
8
+ end
9
+
10
+ failure_message do |actual|
11
+ "expected that `#{actual}' would be have content '#{expected}', but it has '#{File.read(actual)}'" # rubocop:disable Metrics/LineLength
12
+ end
13
+ end
@@ -0,0 +1,65 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift __dir__ + "/../../lib"
5
+ require "dry/cli"
6
+ require_relative "../../../lib/dry/cli/command"
7
+
8
+ module Based
9
+ extend Dry::CLI::Registry
10
+
11
+ class Base < Dry::CLI::Command
12
+ desc "Base description"
13
+ argument :app, desc: "Application name", type: :string, required: true
14
+ option :verbosity, desc: "Verbosity level", type: :string, default: "INFO"
15
+
16
+ example "Base example"
17
+
18
+ def call(app:, **options)
19
+ puts "#{self.class} - App: #{app} - Options: #{options.inspect}"
20
+ end
21
+ end
22
+
23
+ class Run < Base
24
+ desc "Run a one-off process inside your app"
25
+ argument :cmd, desc: "Command to execute", required: true
26
+
27
+ def call(app:, cmd:, **options)
28
+ puts "Run - App: #{app} - Command: #{cmd} - Options: #{options.inspect}"
29
+ end
30
+ end
31
+
32
+ class SubRun < Run
33
+ end
34
+
35
+ class Logs < Base
36
+ desc "Display recent log output"
37
+
38
+ option :num, desc: "number of lines to display"
39
+ option :tail, desc: "continually stream log", type: :boolean
40
+
41
+ example [
42
+ "APP_NAME",
43
+ "APP_NAME --num=50",
44
+ "APP_NAME --tail"
45
+ ]
46
+ end
47
+
48
+ class Addons < Base
49
+ desc "Lists your add-ons and attachments"
50
+
51
+ option :json, desc: "return add-ons in json format", type: :boolean, default: false
52
+
53
+ example [
54
+ "APP_NAME",
55
+ "APP_NAME --json"
56
+ ]
57
+ end
58
+
59
+ register "run", Run
60
+ register "subrun", SubRun
61
+ register "logs", Logs
62
+ register "addons", Addons
63
+ end
64
+
65
+ Dry.CLI(Based).call
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift __dir__ + "/../../lib"
5
+ require "dry/cli"
6
+
7
+ require_relative "baz_command"
8
+
9
+ Dry.CLI(Baz::CLI).call
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Baz
4
+ class CLI < Dry::CLI::Command
5
+ desc "Baz command line interface"
6
+ argument :mandatory_arg, required: true, aliases: %w[m], desc: "Mandatory argument"
7
+ argument :optional_arg, aliases: %w[o],
8
+ desc: "Optional argument (has to have default value in call method)"
9
+ option :option_one, aliases: %w[1], desc: "Option one"
10
+ option :boolean_option, aliases: %w[b], desc: "Option boolean", type: :boolean
11
+ option :option_with_default, aliases: %w[d], desc: "Option default", default: "test"
12
+
13
+ def call(mandatory_arg:, optional_arg: "optional_arg", **options)
14
+ puts "mandatory_arg: #{mandatory_arg}. " \
15
+ "optional_arg: #{optional_arg}. " \
16
+ "Options: #{options.inspect}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,588 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # rubocop:disable Layout/LineLength
5
+ $LOAD_PATH.unshift __dir__ + "/../../../lib"
6
+ require "dry/cli"
7
+
8
+ module Foo
9
+ module CLI
10
+ module Commands
11
+ extend Dry::CLI::Registry
12
+
13
+ class Command < Dry::CLI::Command
14
+ end
15
+
16
+ module Assets
17
+ class Precompile < Dry::CLI::Command
18
+ desc "Precompile assets for deployment"
19
+
20
+ example [
21
+ "FOO_ENV=production # Precompile assets for production environment"
22
+ ]
23
+
24
+ def call(*); end
25
+ end
26
+ end
27
+
28
+ class Console < Dry::CLI::Command
29
+ desc "Starts Foo console"
30
+ option :engine, desc: "Force a console engine", values: %w[irb pry ripl]
31
+
32
+ example [
33
+ " # Uses the bundled engine",
34
+ "--engine=pry # Force to use Pry"
35
+ ]
36
+
37
+ def call(engine: nil, **)
38
+ puts "console - engine: #{engine}"
39
+ end
40
+ end
41
+
42
+ module DB
43
+ class Apply < Dry::CLI::Command
44
+ desc "Migrate, dump the SQL schema, and delete the migrations (experimental)"
45
+
46
+ def call(*); end
47
+ end
48
+
49
+ class Console < Dry::CLI::Command
50
+ desc "Starts a database console"
51
+
52
+ def call(*); end
53
+ end
54
+
55
+ class Create < Dry::CLI::Command
56
+ desc "Create the database (only for development/test)"
57
+
58
+ def call(*); end
59
+ end
60
+
61
+ class Drop < Dry::CLI::Command
62
+ desc "Drop the database (only for development/test)"
63
+
64
+ def call(*); end
65
+ end
66
+
67
+ class Migrate < Dry::CLI::Command
68
+ desc "Migrate the database"
69
+ argument :version, desc: "The target version of the migration (see `foo db version`)"
70
+
71
+ example [
72
+ " # Migrate to the last version",
73
+ "20170721120747 # Migrate to a specific version"
74
+ ]
75
+
76
+ def call(*); end
77
+ end
78
+
79
+ class Prepare < Dry::CLI::Command
80
+ desc "Drop, create, and migrate the database (only for development/test)"
81
+
82
+ def call(*); end
83
+ end
84
+
85
+ class Version < Dry::CLI::Command
86
+ desc "Print the current migrated version"
87
+
88
+ def call(*); end
89
+ end
90
+
91
+ class Rollback < Dry::CLI::Command
92
+ desc "Rollback the database"
93
+
94
+ argument :steps, desc: "Number of versions to rollback", default: 1
95
+
96
+ def call(steps:, **)
97
+ puts steps
98
+ end
99
+ end
100
+ end
101
+
102
+ module Destroy
103
+ class Action < Dry::CLI::Command
104
+ desc "Destroy an action from app"
105
+
106
+ example [
107
+ "web home#index # Basic usage",
108
+ "admin users#index # Destroy from `admin` app"
109
+ ]
110
+
111
+ argument :app, required: true, desc: "The application name (eg. `web`)"
112
+ argument :action, required: true, desc: "The action name (eg. `home#index`)"
113
+
114
+ def call(app:, action:, **)
115
+ puts "destroy action - app: #{app}, action: #{action}"
116
+ end
117
+ end
118
+
119
+ class App < Dry::CLI::Command
120
+ desc "Destroy an app"
121
+
122
+ argument :app, required: true, desc: "The application name (eg. `web`)"
123
+
124
+ example [
125
+ "admin # Destroy `admin` app"
126
+ ]
127
+
128
+ def call(*); end
129
+ end
130
+
131
+ class Mailer < Dry::CLI::Command
132
+ desc "Destroy a mailer"
133
+
134
+ argument :mailer, required: true, desc: "The mailer name (eg. `welcome`)"
135
+
136
+ example [
137
+ "welcome # Destroy `WelcomeMailer` mailer"
138
+ ]
139
+
140
+ def call(*); end
141
+ end
142
+
143
+ class Migration < Dry::CLI::Command
144
+ desc "Destroy a migration"
145
+
146
+ argument :migration, required: true, desc: "The migration name (eg. `create_users`)"
147
+
148
+ example [
149
+ "create_users # Destroy `db/migrations/20170721120747_create_users.rb`"
150
+ ]
151
+
152
+ def call(*); end
153
+ end
154
+
155
+ class Model < Dry::CLI::Command
156
+ desc "Destroy a model"
157
+
158
+ argument :model, required: true, desc: "The model name (eg. `user`)"
159
+
160
+ example [
161
+ "user # Destroy `User` entity and `UserRepository` repository"
162
+ ]
163
+
164
+ def call(*); end
165
+ end
166
+ end
167
+
168
+ module Generate
169
+ class Action < Dry::CLI::Command
170
+ desc "Generate an action for app"
171
+
172
+ example [
173
+ "web home#index # Basic usage",
174
+ "admin home#index # Generate for `admin` app",
175
+ "web home#index --url=/ # Specify URL",
176
+ "web sessions#destroy --method=GET # Specify HTTP method",
177
+ "web books#create --skip-view # Skip view and template"
178
+ ]
179
+
180
+ argument :app, required: true, desc: "The application name (eg. `web`)"
181
+ argument :action, required: true, desc: "The action name (eg. `home#index`)"
182
+
183
+ option :url, desc: "The action URL"
184
+ option :method, desc: "The action HTTP method"
185
+ option :skip_view, type: :boolean, default: false, desc: "Skip view and template"
186
+
187
+ def call(app:, action:, **options)
188
+ puts "generate action - app: #{app}, action: #{action}, options: #{options.inspect}"
189
+ end
190
+ end
191
+
192
+ class App < Dry::CLI::Command
193
+ desc "Generate an app"
194
+
195
+ argument :app, required: true, desc: "The application name (eg. `web`)"
196
+ option :application_base_url, desc: "The app base URL (eg. `/api/v1`)"
197
+
198
+ example [
199
+ "admin # Generate `admin` app",
200
+ "api --application-base-url=/api/v1 # Generate `api` app and mount at `/api/v1`"
201
+ ]
202
+
203
+ def call(*)
204
+ loop { sleep(0.1) }
205
+ end
206
+ end
207
+
208
+ class Mailer < Dry::CLI::Command
209
+ desc "Generate a mailer"
210
+
211
+ argument :mailer, required: true, desc: "The mailer name (eg. `welcome`)"
212
+
213
+ option :from, desc: "The default `from` field of the mail"
214
+ option :to, desc: "The default `to` field of the mail"
215
+ option :subject, desc: "The mail subject"
216
+
217
+ example [
218
+ "welcome # Basic usage",
219
+ 'welcome --from="noreply@example.com" # Generate with default `from` value',
220
+ 'announcement --to="users@example.com" # Generate with default `to` value',
221
+ 'forgot_password --subject="Your password reset" # Generate with default `subject`'
222
+ ]
223
+
224
+ def call(*); end
225
+ end
226
+
227
+ class Migration < Dry::CLI::Command
228
+ desc "Generate a migration"
229
+
230
+ argument :migration, required: true, desc: "The migration name (eg. `create_users`)"
231
+
232
+ example [
233
+ "create_users # Generate `db/migrations/20170721120747_create_users.rb`"
234
+ ]
235
+
236
+ def call(*); end
237
+ end
238
+
239
+ class Model < Dry::CLI::Command
240
+ desc "Generate a model"
241
+
242
+ argument :model, required: true, desc: "Model name (eg. `user`)"
243
+ option :skip_migration, type: :boolean, default: false, desc: "Skip migration"
244
+
245
+ example [
246
+ "user # Generate `User` entity, `UserRepository` repository, and the migration",
247
+ "user --skip-migration # Generate `User` entity and `UserRepository` repository"
248
+ ]
249
+
250
+ def call(model:, **)
251
+ puts "generate model - model: #{model}"
252
+ end
253
+ end
254
+
255
+ class Secret < Dry::CLI::Command
256
+ desc "Generate session secret"
257
+
258
+ argument :app, desc: "The application name (eg. `web`)"
259
+
260
+ example [
261
+ " # Prints secret (eg. `6fad60e21f3f6bfcaf8e56cdb0f835d644b4892c3badc58328126812429bf073`)",
262
+ "web # Prints session secret (eg. `WEB_SESSIONS_SECRET=6fad60e21f3f6bfcaf8e56cdb0f835d644b4892c3badc58328126812429bf073`)"
263
+ ]
264
+
265
+ def call(app: nil, **)
266
+ puts "generate secret - app: #{app}"
267
+ end
268
+ end
269
+ end
270
+
271
+ class New < Dry::CLI::Command
272
+ desc "Generate a new Foo project"
273
+ argument :project, required: true
274
+
275
+ option :database, desc: "Database (sqlite/postgres/mysql)", default: "sqlite", aliases: ["-d", "--db"]
276
+ option :application_name, desc: "App name", default: "web"
277
+ option :application_base_url, desc: "App base URL", default: "/"
278
+ option :template, desc: "Template engine (erb/haml/slim)", default: "erb"
279
+ option :test, desc: "Project testing framework (minitest/rspec)", default: "minitest"
280
+ option :foo_head, desc: "Use Foo HEAD (true/false)", type: :boolean, default: false
281
+
282
+ example [
283
+ "bookshelf # Basic usage",
284
+ "bookshelf --test=rspec # Setup RSpec testing framework",
285
+ "bookshelf --database=postgres # Setup Postgres database",
286
+ "bookshelf --template=slim # Setup Slim template engine",
287
+ "bookshelf --foo-head # Use Foo HEAD"
288
+ ]
289
+
290
+ def call(project:, **)
291
+ puts "new - project: #{project}"
292
+ end
293
+ end
294
+
295
+ class Routes < Dry::CLI::Command
296
+ desc "Print routes"
297
+
298
+ def call(*); end
299
+ end
300
+
301
+ class Server < Dry::CLI::Command
302
+ desc "Start Foo server (only for development)"
303
+
304
+ option :server, desc: "Force a server engine (eg, webrick, puma, thin, etc..)"
305
+ option :host, desc: "The host address to bind to"
306
+ option :port, desc: "The port to run the server on", aliases: ["-p"]
307
+ option :debug, desc: "Turn on debug output"
308
+ option :warn, desc: "Turn on warnings"
309
+ option :daemonize, desc: "Daemonize the server"
310
+ option :pid, desc: "Path to write a pid file after daemonize"
311
+ option :code_reloading, desc: "Code reloading", type: :boolean, default: true
312
+
313
+ example [
314
+ " # Basic usage (it uses the bundled server engine)",
315
+ "--server=webrick # Force `webrick` server engine",
316
+ "--host=0.0.0.0 # Bind to a host",
317
+ "--port=2306 # Bind to a port",
318
+ "--no-code-reloading # Disable code reloading"
319
+ ]
320
+
321
+ def call(options)
322
+ puts "server - #{options.inspect}"
323
+ end
324
+ end
325
+
326
+ class Version < Dry::CLI::Command
327
+ desc "Print Foo version"
328
+
329
+ def call(*)
330
+ puts "v1.0.0"
331
+ end
332
+ end
333
+
334
+ class Exec < Dry::CLI::Command
335
+ desc "Execute a task"
336
+
337
+ argument :task, desc: "Task to execute", type: :string, required: true
338
+ argument :dirs, desc: "Directories", type: :array, required: false
339
+
340
+ def call(task:, dirs: [], **)
341
+ puts "exec - Task: #{task} - Directories: #{dirs.inspect}"
342
+ end
343
+ end
344
+
345
+ class Hello < Dry::CLI::Command
346
+ def call(*)
347
+ raise NotImplementedError
348
+ end
349
+ end
350
+
351
+ class Greeting < Dry::CLI::Command
352
+ argument :response, default: "Hello World"
353
+
354
+ option :person
355
+
356
+ def call(response:, **options)
357
+ puts "response: #{response}, person: #{options[:person]}"
358
+ end
359
+ end
360
+
361
+ class VariadicArguments < Dry::CLI::Command
362
+ desc "accept multiple arguments at the end of the command"
363
+
364
+ def call(**options)
365
+ puts "Unused Arguments: #{options[:args].join(", ")}"
366
+ end
367
+ end
368
+
369
+ class MandatoryAndVariadicArguments < Dry::CLI::Command
370
+ desc "require one command and accept multiple unused arguments"
371
+
372
+ argument :first, desc: "mandatory first argument", required: true
373
+
374
+ def call(first:, **options)
375
+ puts "first: #{first}"
376
+ puts "Unused Arguments: #{options[:args].join(", ")}"
377
+ end
378
+ end
379
+
380
+ class MandatoryOptionsAndVariadicArguments < Dry::CLI::Command
381
+ desc "require one command, accept options and multiple unused arguments"
382
+
383
+ argument :first, desc: "mandatory first argument", required: true
384
+ option :url, desc: "The action URL"
385
+ option :method, desc: "The action HTTP method"
386
+
387
+ def call(first:, **options)
388
+ puts "first: #{first}"
389
+ puts "url: #{options[:url]}"
390
+ puts "method: #{options[:method]}"
391
+ puts "Unused Arguments: #{options[:args].join(", ")}"
392
+ end
393
+ end
394
+
395
+ module Sub
396
+ class Command < Dry::CLI::Command
397
+ def call(*)
398
+ raise NotImplementedError
399
+ end
400
+ end
401
+ end
402
+
403
+ class RootCommand < Dry::CLI::Command
404
+ desc "Root command with arguments and subcommands"
405
+ argument :root_command_argument, desc: "Root command argument", required: true
406
+ option :root_command_option, desc: "Root command option"
407
+
408
+ def call(**params)
409
+ puts "I'm a root-command argument:#{params[:root_command_argument]}"
410
+ puts "I'm a root-command option:#{params[:root_command_option]}"
411
+ end
412
+ end
413
+
414
+ module RootCommands
415
+ class SubCommand < Dry::CLI::Command
416
+ desc "Root command sub command"
417
+ argument :root_command_sub_command_argument, desc: "Root command sub command argument", required: true
418
+ option :root_command_sub_command_option, desc: "Root command sub command option"
419
+
420
+ def call(**params)
421
+ puts "I'm a root-command sub-command argument:#{params[:root_command_sub_command_argument]}"
422
+ puts "I'm a root-command sub-command option:#{params[:root_command_sub_command_option]}"
423
+ end
424
+ end
425
+ end
426
+ end
427
+ end
428
+ end
429
+
430
+ Foo::CLI::Commands.register "assets precompile", Foo::CLI::Commands::Assets::Precompile
431
+ Foo::CLI::Commands.register "console", Foo::CLI::Commands::Console
432
+ Foo::CLI::Commands.register "db" do |prefix|
433
+ prefix.register "apply", Foo::CLI::Commands::DB::Apply
434
+ prefix.register "console", Foo::CLI::Commands::DB::Console
435
+ prefix.register "create", Foo::CLI::Commands::DB::Create
436
+ prefix.register "drop", Foo::CLI::Commands::DB::Drop
437
+ prefix.register "migrate", Foo::CLI::Commands::DB::Migrate
438
+ prefix.register "prepare", Foo::CLI::Commands::DB::Prepare
439
+ prefix.register "version", Foo::CLI::Commands::DB::Version
440
+ prefix.register "rollback", Foo::CLI::Commands::DB::Rollback
441
+ end
442
+ Foo::CLI::Commands.register "destroy", aliases: ["d"] do |prefix|
443
+ prefix.register "action", Foo::CLI::Commands::Destroy::Action
444
+ prefix.register "app", Foo::CLI::Commands::Destroy::App
445
+ prefix.register "mailer", Foo::CLI::Commands::Destroy::Mailer
446
+ prefix.register "migration", Foo::CLI::Commands::Destroy::Migration
447
+ prefix.register "model", Foo::CLI::Commands::Destroy::Model
448
+ end
449
+ Foo::CLI::Commands.register "generate", aliases: ["g"] do |prefix|
450
+ prefix.register "action", Foo::CLI::Commands::Generate::Action
451
+ prefix.register "app", Foo::CLI::Commands::Generate::App
452
+ prefix.register "mailer", Foo::CLI::Commands::Generate::Mailer
453
+ prefix.register "migration", Foo::CLI::Commands::Generate::Migration
454
+ prefix.register "model", Foo::CLI::Commands::Generate::Model
455
+ prefix.register "secret", Foo::CLI::Commands::Generate::Secret
456
+ end
457
+ Foo::CLI::Commands.register "new", Foo::CLI::Commands::New
458
+ Foo::CLI::Commands.register "routes", Foo::CLI::Commands::Routes
459
+ Foo::CLI::Commands.register "server", Foo::CLI::Commands::Server, aliases: ["s"]
460
+ Foo::CLI::Commands.register "version", Foo::CLI::Commands::Version, aliases: ["v", "-v", "--version"]
461
+ Foo::CLI::Commands.register "exec", Foo::CLI::Commands::Exec
462
+
463
+ Foo::CLI::Commands.register "hello", Foo::CLI::Commands::Hello
464
+ Foo::CLI::Commands.register "greeting", Foo::CLI::Commands::Greeting
465
+ Foo::CLI::Commands.register "sub command", Foo::CLI::Commands::Sub::Command
466
+ Foo::CLI::Commands.register "root-command", Foo::CLI::Commands::RootCommand
467
+ Foo::CLI::Commands.register "root-command sub-command", Foo::CLI::Commands::RootCommands::SubCommand
468
+
469
+ Foo::CLI::Commands.register "variadic default", Foo::CLI::Commands::VariadicArguments
470
+ Foo::CLI::Commands.register "variadic with-mandatory", Foo::CLI::Commands::MandatoryAndVariadicArguments
471
+ Foo::CLI::Commands.register "variadic with-mandatory-and-options", Foo::CLI::Commands::MandatoryOptionsAndVariadicArguments
472
+
473
+ module Foo
474
+ module Webpack
475
+ module CLI
476
+ class Generate < Dry::CLI::Command
477
+ desc "Generate webpack configuration"
478
+
479
+ option :apps, desc: "Generate webpack apps", type: :array
480
+
481
+ def call(apps: [], **)
482
+ puts "generate webpack. Apps: #{apps}"
483
+ end
484
+ end
485
+
486
+ class Hello < Dry::CLI::Command
487
+ desc "Print a greeting"
488
+
489
+ def call(*)
490
+ puts "hello from webpack"
491
+ end
492
+ end
493
+
494
+ class SubCommand < Dry::CLI::Command
495
+ desc "Override a subcommand"
496
+
497
+ def call(**)
498
+ puts "override from webpack"
499
+ end
500
+ end
501
+
502
+ class CallbacksCommand < Dry::CLI::Command
503
+ desc "Command with callbacks"
504
+ argument :dir, required: true
505
+ option :url
506
+
507
+ def call(dir:, url: nil, **)
508
+ puts "dir: #{dir}, url: #{url.inspect}"
509
+ end
510
+ end
511
+ end
512
+ end
513
+ end
514
+
515
+ Foo::CLI::Commands.register "generate webpack", Foo::Webpack::CLI::Generate
516
+ Foo::CLI::Commands.register "hello", Foo::Webpack::CLI::Hello
517
+ Foo::CLI::Commands.register "sub command", Foo::Webpack::CLI::SubCommand
518
+ Foo::CLI::Commands.register "callbacks", Foo::Webpack::CLI::CallbacksCommand
519
+
520
+ # we need to be sure that command will not override with nil command
521
+ Foo::CLI::Commands.register "generate webpack", nil
522
+
523
+ Foo::CLI::Commands.before("callbacks") do |args|
524
+ puts "before command callback #{self.class.name} #{args.inspect}"
525
+ end
526
+
527
+ Foo::CLI::Commands.after("callbacks") do |args|
528
+ puts "after command callback #{self.class.name} #{args.inspect}"
529
+ end
530
+
531
+ module Callbacks
532
+ class BeforeClass
533
+ def call(args)
534
+ puts "before callback (class), #{count(args)} arg(s): #{args.inspect}"
535
+ end
536
+
537
+ private
538
+
539
+ def count(args)
540
+ args.count
541
+ end
542
+ end
543
+
544
+ class AfterClass
545
+ def call(args)
546
+ puts "after callback (class), #{count(args)} arg(s): #{args.inspect}"
547
+ end
548
+
549
+ private
550
+
551
+ def count(args)
552
+ args.count
553
+ end
554
+ end
555
+
556
+ class Before
557
+ def call(args)
558
+ puts "before callback (object), #{count(args)} arg(s): #{args.inspect}"
559
+ end
560
+
561
+ private
562
+
563
+ def count(args)
564
+ args.count
565
+ end
566
+ end
567
+
568
+ class After
569
+ def call(args)
570
+ puts "after callback (object), #{count(args)} arg(s): #{args.inspect}"
571
+ end
572
+
573
+ private
574
+
575
+ def count(args)
576
+ args.count
577
+ end
578
+ end
579
+ end
580
+ # rubocop:enable Layout/LineLength
581
+
582
+ Foo::CLI::Commands.before("callbacks", Callbacks::BeforeClass)
583
+ Foo::CLI::Commands.after("callbacks", Callbacks::AfterClass)
584
+ Foo::CLI::Commands.before("callbacks", Callbacks::Before.new)
585
+ Foo::CLI::Commands.after("callbacks", Callbacks::After.new)
586
+
587
+ cli = Dry::CLI.new(Foo::CLI::Commands)
588
+ cli.call