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,197 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples "Inherited commands" do |cli|
4
+ let(:cli) { cli }
5
+
6
+ let(:cmd) { File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)) }
7
+
8
+ context "with help flag" do
9
+ it "shows subcommands " do
10
+ error = capture_error { cli.call(arguments: %w[i]) }
11
+ expected = <<~DESC
12
+ Commands:
13
+ rspec i addons APP # Lists your add-ons and attachments
14
+ rspec i logs APP # Display recent log output
15
+ rspec i run APP CMD # Run a one-off process inside your app
16
+ rspec i subrun APP CMD
17
+ DESC
18
+ expect(error).to eq(expected)
19
+ end
20
+
21
+ it "shows run's help" do
22
+ output = capture_output { cli.call(arguments: %w[i run --help]) }
23
+ expected = <<~DESC
24
+ Command:
25
+ #{cmd} i run
26
+
27
+ Usage:
28
+ #{cmd} i run APP CMD
29
+
30
+ Description:
31
+ Run a one-off process inside your app
32
+
33
+ Arguments:
34
+ APP # REQUIRED Application name
35
+ CMD # REQUIRED Command to execute
36
+
37
+ Options:
38
+ --verbosity=VALUE # Verbosity level, default: "INFO"
39
+ --help, -h # Print this help
40
+ DESC
41
+ expect(output).to eq(expected)
42
+ end
43
+
44
+ it "shows subrun's help" do
45
+ output = capture_output { cli.call(arguments: %w[i subrun --help]) }
46
+ expected = <<~DESC
47
+ Command:
48
+ #{cmd} i subrun
49
+
50
+ Usage:
51
+ #{cmd} i subrun APP CMD
52
+
53
+ Arguments:
54
+ APP # REQUIRED Application name
55
+ CMD # REQUIRED Command to execute
56
+
57
+ Options:
58
+ --verbosity=VALUE # Verbosity level, default: "INFO"
59
+ --help, -h # Print this help
60
+ DESC
61
+ expect(output).to eq(expected)
62
+ end
63
+
64
+ it "shows addon's help" do
65
+ output = capture_output { cli.call(arguments: %w[i addons --help]) }
66
+ expected = <<~DESC
67
+ Command:
68
+ #{cmd} i addons
69
+
70
+ Usage:
71
+ #{cmd} i addons APP
72
+
73
+ Description:
74
+ Lists your add-ons and attachments
75
+
76
+ Arguments:
77
+ APP # REQUIRED Application name
78
+
79
+ Options:
80
+ --verbosity=VALUE # Verbosity level, default: "INFO"
81
+ --[no-]json # return add-ons in json format, default: false
82
+ --help, -h # Print this help
83
+
84
+ Examples:
85
+ #{cmd} i addons APP_NAME
86
+ #{cmd} i addons APP_NAME --json
87
+ DESC
88
+ expect(output).to eq(expected)
89
+ end
90
+
91
+ it "shows log's help" do
92
+ output = capture_output { cli.call(arguments: %w[i logs --help]) }
93
+ expected = <<~DESC
94
+ Command:
95
+ #{cmd} i logs
96
+
97
+ Usage:
98
+ #{cmd} i logs APP
99
+
100
+ Description:
101
+ Display recent log output
102
+
103
+ Arguments:
104
+ APP # REQUIRED Application name
105
+
106
+ Options:
107
+ --verbosity=VALUE # Verbosity level, default: "INFO"
108
+ --num=VALUE # number of lines to display
109
+ --[no-]tail # continually stream log
110
+ --help, -h # Print this help
111
+
112
+ Examples:
113
+ #{cmd} i logs APP_NAME
114
+ #{cmd} i logs APP_NAME --num=50
115
+ #{cmd} i logs APP_NAME --tail
116
+ DESC
117
+ expect(output).to eq(expected)
118
+ end
119
+ end
120
+
121
+ context "with inherited arguments" do
122
+ it "run expects APP_NAME and CMD_NAME" do
123
+ output = capture_output { cli.call(arguments: %w[i run application_name command_name]) }
124
+ expect(output).to include("App: application_name - Command: command_name")
125
+ end
126
+
127
+ it "subrun expects APP_NAME and CMD_NAME" do
128
+ output = capture_output { cli.call(arguments: %w[i subrun application_name command_name]) }
129
+ expect(output).to include("App: application_name - Command: command_name")
130
+ end
131
+
132
+ it "addons expects APP_NAME" do
133
+ output = capture_output { cli.call(arguments: %w[i addons application_name]) }
134
+ expect(output).to include("App: application_name")
135
+ end
136
+
137
+ it "logs expects APP_NAME" do
138
+ output = capture_output { cli.call(arguments: %w[i logs application_name]) }
139
+ expect(output).to include("App: application_name")
140
+ end
141
+ end
142
+
143
+ context "with inherited options" do
144
+ it "run has default verbosity_level" do
145
+ output = capture_output { cli.call(arguments: %w[i run application_name command_name]) }
146
+ expect(output).to include('Options: {:verbosity=>"INFO"}')
147
+ end
148
+
149
+ it "subrun has default verbosity_level too" do
150
+ output = capture_output { cli.call(arguments: %w[i subrun application_name command_name]) }
151
+ expect(output).to include('Options: {:verbosity=>"INFO"}')
152
+ end
153
+
154
+ it "addons has verbosity_level set to debug" do
155
+ output = capture_output do
156
+ cli.call(arguments: %w[i addons application_name --verbosity=DEBUG])
157
+ end
158
+ expect(output).to include("Options: {:verbosity=>\"DEBUG\", :json=>false}")
159
+ end
160
+
161
+ it "logs has verbosity_level set to WARNING" do
162
+ output = capture_output do
163
+ cli.call(arguments: %w[i logs application_name --verbosity=WARNING])
164
+ end
165
+ expect(output).to include("Options: {:verbosity=>\"WARNING\"}")
166
+ end
167
+ end
168
+
169
+ context "with description" do
170
+ it "subclass does not inherit it" do
171
+ output = capture_output { cli.call(arguments: %w[i run --help]) }
172
+ expect(output).not_to include("Base description")
173
+ end
174
+
175
+ it "subclasses subclass does not inherit it" do
176
+ output = capture_output { cli.call(arguments: %w[i subrun --help]) }
177
+ expect(output).not_to include("Run a one-off process inside your app")
178
+ end
179
+ end
180
+
181
+ context "with example" do
182
+ it "subclass does not inherit it" do
183
+ output = capture_output { cli.call(arguments: %w[i logs --help]) }
184
+ expect(output).not_to include("Base example")
185
+ end
186
+ end
187
+
188
+ context "with multible subclasses of Dry::CLI::Command" do
189
+ it "subclasses do nod share options" do
190
+ output = capture_output { cli.call(arguments: %w[i logs application_name --tail --num=50]) }
191
+ expect(output).not_to include(":json=>false}")
192
+
193
+ output = capture_output { cli.call(arguments: %w[i addons application_name]) }
194
+ expect(output).not_to include(":tail=>false}")
195
+ end
196
+ end
197
+ end
@@ -0,0 +1,181 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples "Rendering" do |cli|
4
+ let(:cli) { cli }
5
+
6
+ let(:cmd) { File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)) }
7
+
8
+ it "prints required params" do
9
+ error = capture_error { cli.call }
10
+ expected = <<~DESC
11
+ Commands:
12
+ #{cmd} assets [SUBCOMMAND]
13
+ #{cmd} callbacks DIR # Command with callbacks
14
+ #{cmd} console # Starts Foo console
15
+ #{cmd} db [SUBCOMMAND]
16
+ #{cmd} destroy [SUBCOMMAND]
17
+ #{cmd} exec TASK [DIRS] # Execute a task
18
+ #{cmd} generate [SUBCOMMAND]
19
+ #{cmd} greeting [RESPONSE]
20
+ #{cmd} hello # Print a greeting
21
+ #{cmd} inherited [SUBCOMMAND]
22
+ #{cmd} new PROJECT # Generate a new Foo project
23
+ #{cmd} options-with-aliases # Accepts options with aliases
24
+ #{cmd} root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
25
+ #{cmd} routes # Print routes
26
+ #{cmd} server # Start Foo server (only for development)
27
+ #{cmd} sub [SUBCOMMAND]
28
+ #{cmd} variadic [SUBCOMMAND]
29
+ #{cmd} version # Print Foo version
30
+ #{cmd} with-initializer
31
+ DESC
32
+
33
+ expect(error).to eq(expected)
34
+ end
35
+
36
+ it "prints required params with labels" do
37
+ error = capture_error { cli.call(arguments: ["destroy"]) }
38
+
39
+ expected = <<~DESC
40
+ Commands:
41
+ #{cmd} destroy action APP ACTION # Destroy an action from app
42
+ #{cmd} destroy app APP # Destroy an app
43
+ #{cmd} destroy mailer MAILER # Destroy a mailer
44
+ #{cmd} destroy migration MIGRATION # Destroy a migration
45
+ #{cmd} destroy model MODEL # Destroy a model
46
+ DESC
47
+
48
+ expect(error).to eq(expected)
49
+ end
50
+
51
+ it "prints available commands for unknown subcommand" do
52
+ error = capture_error { cli.call(arguments: %w[generate unknown]) }
53
+
54
+ expected = <<~DESC
55
+ Commands:
56
+ #{cmd} generate action APP ACTION # Generate an action for app
57
+ #{cmd} generate app APP # Generate an app
58
+ #{cmd} generate mailer MAILER # Generate a mailer
59
+ #{cmd} generate migration MIGRATION # Generate a migration
60
+ #{cmd} generate model MODEL # Generate a model
61
+ #{cmd} generate secret [APP] # Generate session secret
62
+ #{cmd} generate webpack # Generate webpack configuration
63
+ DESC
64
+
65
+ expect(error).to eq(expected)
66
+ end
67
+
68
+ it "prints available commands for unknown command" do
69
+ error = capture_error { cli.call(arguments: ["unknown"]) }
70
+
71
+ expected = <<~DESC
72
+ Commands:
73
+ #{cmd} assets [SUBCOMMAND]
74
+ #{cmd} callbacks DIR # Command with callbacks
75
+ #{cmd} console # Starts Foo console
76
+ #{cmd} db [SUBCOMMAND]
77
+ #{cmd} destroy [SUBCOMMAND]
78
+ #{cmd} exec TASK [DIRS] # Execute a task
79
+ #{cmd} generate [SUBCOMMAND]
80
+ #{cmd} greeting [RESPONSE]
81
+ #{cmd} hello # Print a greeting
82
+ #{cmd} inherited [SUBCOMMAND]
83
+ #{cmd} new PROJECT # Generate a new Foo project
84
+ #{cmd} options-with-aliases # Accepts options with aliases
85
+ #{cmd} root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
86
+ #{cmd} routes # Print routes
87
+ #{cmd} server # Start Foo server (only for development)
88
+ #{cmd} sub [SUBCOMMAND]
89
+ #{cmd} variadic [SUBCOMMAND]
90
+ #{cmd} version # Print Foo version
91
+ #{cmd} with-initializer
92
+ DESC
93
+
94
+ expect(error).to eq(expected)
95
+ end
96
+
97
+ it "prints first level" do
98
+ error = capture_error { cli.call }
99
+
100
+ expected = <<~DESC
101
+ Commands:
102
+ #{cmd} assets [SUBCOMMAND]
103
+ #{cmd} callbacks DIR # Command with callbacks
104
+ #{cmd} console # Starts Foo console
105
+ #{cmd} db [SUBCOMMAND]
106
+ #{cmd} destroy [SUBCOMMAND]
107
+ #{cmd} exec TASK [DIRS] # Execute a task
108
+ #{cmd} generate [SUBCOMMAND]
109
+ #{cmd} greeting [RESPONSE]
110
+ #{cmd} hello # Print a greeting
111
+ #{cmd} inherited [SUBCOMMAND]
112
+ #{cmd} new PROJECT # Generate a new Foo project
113
+ #{cmd} options-with-aliases # Accepts options with aliases
114
+ #{cmd} root-command [ARGUMENT|SUBCOMMAND] # Root command with arguments and subcommands
115
+ #{cmd} routes # Print routes
116
+ #{cmd} server # Start Foo server (only for development)
117
+ #{cmd} sub [SUBCOMMAND]
118
+ #{cmd} variadic [SUBCOMMAND]
119
+ #{cmd} version # Print Foo version
120
+ #{cmd} with-initializer
121
+ DESC
122
+
123
+ expect(error).to eq(expected)
124
+ end
125
+
126
+ it "prints subcommand's commands" do
127
+ error = capture_error { cli.call(arguments: ["generate"]) }
128
+
129
+ expected = <<~DESC
130
+ Commands:
131
+ #{cmd} generate action APP ACTION # Generate an action for app
132
+ #{cmd} generate app APP # Generate an app
133
+ #{cmd} generate mailer MAILER # Generate a mailer
134
+ #{cmd} generate migration MIGRATION # Generate a migration
135
+ #{cmd} generate model MODEL # Generate a model
136
+ #{cmd} generate secret [APP] # Generate session secret
137
+ #{cmd} generate webpack # Generate webpack configuration
138
+ DESC
139
+
140
+ expect(error).to eq(expected)
141
+ end
142
+
143
+ it "prints subcommand's subcommand" do
144
+ error = capture_error { cli.call(arguments: %w[generate application]) }
145
+
146
+ expected = <<~DESC
147
+ Commands:
148
+ #{cmd} generate action APP ACTION # Generate an action for app
149
+ #{cmd} generate app APP # Generate an app
150
+ #{cmd} generate mailer MAILER # Generate a mailer
151
+ #{cmd} generate migration MIGRATION # Generate a migration
152
+ #{cmd} generate model MODEL # Generate a model
153
+ #{cmd} generate secret [APP] # Generate session secret
154
+ #{cmd} generate webpack # Generate webpack configuration
155
+ DESC
156
+ expect(error).to eq(expected)
157
+ end
158
+
159
+ it "prints list options when calling help" do
160
+ output = capture_output { cli.call(arguments: %w[options-with-aliases --help]) }
161
+
162
+ expected = <<~DESC
163
+ Command:
164
+ #{cmd} options-with-aliases
165
+
166
+ Usage:
167
+ #{cmd} options-with-aliases
168
+
169
+ Description:
170
+ Accepts options with aliases
171
+
172
+ Options:
173
+ --url=VALUE, -u VALUE # The action URL
174
+ --[no-]flag, -f # The flag
175
+ --[no-]opt, -o # The opt, default: false
176
+ --help, -h # Print this help
177
+ DESC
178
+
179
+ expect(output).to eq(expected)
180
+ end
181
+ end
@@ -0,0 +1,226 @@
1
+ # frozen_string_literal: true
2
+
3
+ RSpec.shared_examples "Subcommands" do |cli|
4
+ let(:cli) { cli }
5
+
6
+ let(:cmd) { File.basename($PROGRAM_NAME, File.extname($PROGRAM_NAME)) }
7
+
8
+ it "calls subcommand" do
9
+ error = capture_error { cli.call(arguments: %w[generate model]) }
10
+ expected = <<~DESC
11
+ ERROR: "#{cmd} generate model" was called with no arguments
12
+ Usage: "#{cmd} generate model MODEL"
13
+ DESC
14
+
15
+ expect(error).to eq(expected)
16
+ end
17
+
18
+ context "works with params" do
19
+ it "without params" do
20
+ error = capture_error { cli.call(arguments: %w[generate model]) }
21
+ expected = <<~DESC
22
+ ERROR: "#{cmd} generate model" was called with no arguments
23
+ Usage: "#{cmd} generate model MODEL"
24
+ DESC
25
+
26
+ expect(error).to eq(expected)
27
+ end
28
+
29
+ it "a param using space" do
30
+ output = capture_output { cli.call(arguments: %w[server --port 2306]) }
31
+ expect(output).to eq(
32
+ "server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :port=>\"2306\"}\n"
33
+ )
34
+ end
35
+
36
+ it "a param using equal sign" do
37
+ output = capture_output { cli.call(arguments: %w[server --port=2306]) }
38
+ expect(output).to eq(
39
+ "server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :port=>\"2306\"}\n"
40
+ )
41
+ end
42
+
43
+ it "a param using alias" do
44
+ output = capture_output { cli.call(arguments: %w[server -p 2306]) }
45
+ expect(output).to eq(
46
+ "server - {:code_reloading=>true, :deps=>[\"dep1\", \"dep2\"], :port=>\"2306\"}\n"
47
+ )
48
+ end
49
+
50
+ it "with help param" do
51
+ output = capture_output { cli.call(arguments: %w[generate model --help]) }
52
+
53
+ expected = <<~DESC
54
+ Command:
55
+ #{cmd} generate model
56
+
57
+ Usage:
58
+ #{cmd} generate model MODEL
59
+
60
+ Description:
61
+ Generate a model
62
+
63
+ Arguments:
64
+ MODEL # REQUIRED Model name (eg. `user`)
65
+
66
+ Options:
67
+ --[no-]skip-migration # Skip migration, default: false
68
+ --help, -h # Print this help
69
+
70
+ Examples:
71
+ #{cmd} generate model user # Generate `User` entity, `UserRepository` repository, and the migration
72
+ #{cmd} generate model user --skip-migration # Generate `User` entity and `UserRepository` repository
73
+ DESC
74
+
75
+ expect(output).to eq(expected)
76
+ end
77
+
78
+ context "with required params" do
79
+ it "only one param" do
80
+ output = capture_output { cli.call(arguments: %w[generate model user]) }
81
+ expect(output).to eq("generate model - model: user\n")
82
+ end
83
+
84
+ it "more than one param" do
85
+ output = capture_output { cli.call(arguments: %w[destroy action web users#index]) }
86
+ expect(output).to eq("destroy action - app: web, action: users#index\n")
87
+ end
88
+
89
+ it "more than one param and with optional params" do
90
+ output = capture_output { cli.call(arguments: %w[generate action web users#index --url=/signin]) } # rubocop:disable Metrics/LineLength
91
+ expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>false, :url=>\"/signin\"}\n") # rubocop:disable Metrics/LineLength
92
+ end
93
+
94
+ it "more than one param and with boolean params" do
95
+ output = capture_output { cli.call(arguments: %w[generate action web users#index --skip-view --url=/signin]) } # rubocop:disable Metrics/LineLength
96
+ expect(output).to eq("generate action - app: web, action: users#index, options: {:skip_view=>true, :url=>\"/signin\"}\n") # rubocop:disable Metrics/LineLength
97
+ end
98
+
99
+ it "more than required params" do
100
+ output = capture_output { cli.call(arguments: %w[destroy action web users#index unexpected_param]) } # rubocop:disable Metrics/LineLength
101
+ expect(output).to eq("destroy action - app: web, action: users#index\n")
102
+ end
103
+
104
+ it "an error is displayed if there aren't required params" do
105
+ error = capture_error { cli.call(arguments: %w[destroy action]) }
106
+ expected = <<~DESC
107
+ ERROR: "#{cmd} destroy action" was called with no arguments
108
+ Usage: "#{cmd} destroy action APP ACTION"
109
+ DESC
110
+
111
+ expect(error).to eq(expected)
112
+ end
113
+
114
+ it "an error is displayed if there are some required params" do
115
+ error = capture_error { cli.call(arguments: %w[destroy action web]) }
116
+ expected = <<~DESC
117
+ ERROR: "#{cmd} destroy action" was called with arguments [\"web\"]
118
+ Usage: "#{cmd} destroy action APP ACTION"
119
+ DESC
120
+
121
+ expect(error).to eq(expected)
122
+ end
123
+
124
+ context "and a default value" do
125
+ it "returns the default value if nothing is passed" do
126
+ output = capture_output { cli.call(arguments: %w[db rollback]) }
127
+
128
+ expect(output).to eq("1\n")
129
+ end
130
+
131
+ it "returns the passed value" do
132
+ output = capture_output { cli.call(arguments: %w[db rollback 3]) }
133
+
134
+ expect(output).to eq("3\n")
135
+ end
136
+ end
137
+ end
138
+ end
139
+
140
+ context "works with root command" do
141
+ it "shows help" do
142
+ output = capture_output { cli.call(arguments: %w[root-command sub-command -h]) }
143
+ expected = <<~DESC
144
+ Command:
145
+ rspec root-command sub-command
146
+
147
+ Usage:
148
+ rspec root-command sub-command ROOT_COMMAND_SUB_COMMAND_ARGUMENT
149
+
150
+ Description:
151
+ Root command sub command
152
+
153
+ Arguments:
154
+ ROOT_COMMAND_SUB_COMMAND_ARGUMENT # REQUIRED Root command sub command argument
155
+
156
+ Options:
157
+ --root-command-sub-command-option=VALUE # Root command sub command option
158
+ --help, -h # Print this help
159
+ DESC
160
+
161
+ expect(output).to eq(expected)
162
+
163
+ output = capture_output { cli.call(arguments: %w[root-command sub-command --help]) }
164
+ expect(output).to eq(expected)
165
+ end
166
+
167
+ context "works with params" do
168
+ it "without params" do
169
+ error = capture_error { cli.call(arguments: %w[root-command sub-command]) }
170
+ expected = <<~DESC
171
+ ERROR: "rspec root-command sub-command" was called with no arguments
172
+ Usage: "rspec root-command sub-command ROOT_COMMAND_SUB_COMMAND_ARGUMENT"
173
+ DESC
174
+
175
+ expect(error).to eq(expected)
176
+ end
177
+
178
+ it "with params" do
179
+ output = capture_output {
180
+ cli.call(arguments: ["root-command", "sub-command", '"hello world"'])
181
+ }
182
+ expected = <<~DESC
183
+ I'm a root-command sub-command argument:"hello world"
184
+ I'm a root-command sub-command option:
185
+ DESC
186
+
187
+ expect(output).to eq(expected)
188
+ end
189
+
190
+ it "with option using space" do
191
+ output = capture_output {
192
+ cli.call(arguments: [
193
+ "root-command",
194
+ "sub-command",
195
+ '"hello world"',
196
+ "--root-command-sub-command-option",
197
+ '"bye world"'
198
+ ])
199
+ }
200
+ expected = <<~DESC
201
+ I'm a root-command sub-command argument:"hello world"
202
+ I'm a root-command sub-command option:"bye world"
203
+ DESC
204
+
205
+ expect(output).to eq(expected)
206
+ end
207
+
208
+ it "with option using equal sign" do
209
+ output = capture_output {
210
+ cli.call(arguments: [
211
+ "root-command",
212
+ "sub-command",
213
+ '"hello world"',
214
+ '--root-command-sub-command-option="bye world"'
215
+ ])
216
+ }
217
+ expected = <<~DESC
218
+ I'm a root-command sub-command argument:"hello world"
219
+ I'm a root-command sub-command option:"bye world"
220
+ DESC
221
+
222
+ expect(output).to eq(expected)
223
+ end
224
+ end
225
+ end
226
+ end