tty 0.7.0 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rspec +2 -2
  3. data/.travis.yml +15 -4
  4. data/CHANGELOG.md +22 -0
  5. data/Gemfile +4 -7
  6. data/README.md +648 -58
  7. data/appveyor.yml +3 -4
  8. data/exe/teletype +18 -0
  9. data/lib/tty.rb +7 -4
  10. data/lib/tty/cli.rb +140 -0
  11. data/lib/tty/cmd.rb +132 -0
  12. data/lib/tty/commands/add.rb +321 -0
  13. data/lib/tty/commands/new.rb +256 -0
  14. data/lib/tty/gemspec.rb +30 -0
  15. data/lib/tty/licenses.rb +34 -0
  16. data/lib/tty/path_helpers.rb +38 -0
  17. data/lib/tty/plugins.rb +20 -12
  18. data/lib/tty/templater.rb +54 -0
  19. data/lib/tty/templates/add/command.rb.tt +31 -0
  20. data/lib/tty/templates/add/gitkeep.tt +1 -0
  21. data/lib/tty/templates/add/namespace.rb.tt +17 -0
  22. data/lib/tty/templates/add/spec/integration/command_spec.rb.tt +20 -0
  23. data/lib/tty/templates/add/spec/integration/sub_command_spec.rb.tt +16 -0
  24. data/lib/tty/templates/add/spec/unit/command_spec.rb.tt +15 -0
  25. data/lib/tty/templates/add/spec/unit/sub_command_spec.rb.tt +15 -0
  26. data/lib/tty/templates/add/test/integration/command_test.rb.tt +23 -0
  27. data/lib/tty/templates/add/test/integration/sub_command_test.rb.tt +19 -0
  28. data/lib/tty/templates/add/test/unit/command_test.rb.tt +16 -0
  29. data/lib/tty/templates/add/test/unit/sub_command_test.rb.tt +16 -0
  30. data/lib/tty/templates/new/agplv3_LICENSE.txt.tt +555 -0
  31. data/lib/tty/templates/new/apache_LICENSE.txt.tt +157 -0
  32. data/lib/tty/templates/new/bsd2_LICENSE.txt.tt +22 -0
  33. data/lib/tty/templates/new/bsd3_LICENSE.txt.tt +26 -0
  34. data/lib/tty/templates/new/exe/newcli.tt +18 -0
  35. data/lib/tty/templates/new/gitkeep.tt +1 -0
  36. data/lib/tty/templates/new/gplv2_LICENSE.txt.tt +255 -0
  37. data/lib/tty/templates/new/gplv3_LICENSE.txt.tt +543 -0
  38. data/lib/tty/templates/new/lgplv3_LICENSE.txt.tt +143 -0
  39. data/lib/tty/templates/new/lib/newcli/cli.rb.tt +24 -0
  40. data/lib/tty/templates/new/lib/newcli/command.rb.tt +124 -0
  41. data/lib/tty/templates/new/mit_LICENSE.txt.tt +20 -0
  42. data/lib/tty/templates/new/mplv2_LICENSE.txt.tt +277 -0
  43. data/lib/tty/version.rb +1 -1
  44. data/spec/fixtures/foo-0.0.1.gemspec +4 -4
  45. data/spec/integration/add_desc_args_spec.rb +341 -0
  46. data/spec/integration/add_force_spec.rb +98 -0
  47. data/spec/integration/add_namespaced_spec.rb +291 -0
  48. data/spec/integration/add_spec.rb +535 -0
  49. data/spec/integration/add_subcommand_spec.rb +259 -0
  50. data/spec/integration/new_author_spec.rb +19 -0
  51. data/spec/integration/new_license_spec.rb +39 -0
  52. data/spec/integration/new_namespaced_spec.rb +228 -0
  53. data/spec/integration/new_spec.rb +354 -0
  54. data/spec/integration/new_test_spec.rb +21 -0
  55. data/spec/integration/start_spec.rb +21 -0
  56. data/spec/spec_helper.rb +47 -16
  57. data/spec/unit/gemspec_spec.rb +17 -0
  58. data/spec/{tty/plugins/load_spec.rb → unit/plugins/activate_spec.rb} +2 -4
  59. data/spec/unit/plugins/load_from_spec.rb +28 -0
  60. data/spec/{tty → unit}/plugins/plugin/load_spec.rb +1 -3
  61. data/spec/{tty → unit}/plugins/plugin/new_spec.rb +1 -3
  62. data/spec/{tty → unit}/tty_spec.rb +1 -3
  63. data/tty.gemspec +25 -15
  64. metadata +186 -49
  65. data/spec/tty/plugins/find_spec.rb +0 -20
  66. data/tasks/metrics/cane.rake +0 -14
  67. data/tasks/metrics/flog.rake +0 -17
  68. data/tasks/metrics/heckle.rake +0 -15
  69. data/tasks/metrics/reek.rake +0 -13
@@ -0,0 +1,291 @@
1
+ RSpec.describe "teletype add", type: :cli do
2
+ it "adds a command to namespaced application" do
3
+ app_name = tmp_path('cli-app')
4
+ silent_run("teletype new #{app_name} --test rspec")
5
+
6
+ output = <<-OUT
7
+ create spec/integration/server_spec.rb
8
+ create spec/unit/server_spec.rb
9
+ create lib/cli/app/commands/server.rb
10
+ create lib/cli/app/templates/server/.gitkeep
11
+ inject lib/cli/app/cli.rb
12
+ OUT
13
+
14
+ within_dir(app_name) do
15
+ command = "teletype add server --no-color"
16
+
17
+ out, err, status = Open3.capture3(command)
18
+
19
+ expect(err).to eq('')
20
+ expect(out).to eq(output)
21
+ expect(status.exitstatus).to eq(0)
22
+
23
+ # lib/cli/app/commands/server.rb
24
+ #
25
+ expect(::File.read('lib/cli/app/commands/server.rb')).to eq <<-EOS
26
+ # frozen_string_literal: true
27
+
28
+ require_relative '../command'
29
+
30
+ module Cli
31
+ module App
32
+ module Commands
33
+ class Server < Cli::App::Command
34
+ def initialize(options)
35
+ @options = options
36
+ end
37
+
38
+ def execute(input: $stdin, output: $stdout)
39
+ # Command logic goes here ...
40
+ output.puts "OK"
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ EOS
47
+
48
+ # lib/cli/app/cli.rb
49
+ #
50
+ expect(::File.read('lib/cli/app/cli.rb')).to eq <<-EOS
51
+ # frozen_string_literal: true
52
+
53
+ require 'thor'
54
+
55
+ module Cli
56
+ module App
57
+ # Handle the application command line parsing
58
+ # and the dispatch to various command objects
59
+ #
60
+ # @api public
61
+ class CLI < Thor
62
+ # Error raised by this runner
63
+ Error = Class.new(StandardError)
64
+
65
+ desc 'version', 'cli-app version'
66
+ def version
67
+ require_relative 'version'
68
+ puts \"v\#{Cli::App::VERSION}\"
69
+ end
70
+ map %w(--version -v) => :version
71
+
72
+ desc 'server', 'Command description...'
73
+ method_option :help, aliases: '-h', type: :boolean,
74
+ desc: 'Display usage information'
75
+ def server(*)
76
+ if options[:help]
77
+ invoke :help, ['server']
78
+ else
79
+ require_relative 'commands/server'
80
+ Cli::App::Commands::Server.new(options).execute
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ EOS
87
+
88
+ # test setup
89
+ #
90
+ expect(::File.read('spec/integration/server_spec.rb')).to eq <<-EOS
91
+ RSpec.describe "`cli-app server` command", type: :cli do
92
+ it "executes `cli-app help server` command successfully" do
93
+ output = `cli-app help server`
94
+ expected_output = <<-OUT
95
+ Usage:
96
+ cli-app server
97
+
98
+ Options:
99
+ -h, [--help], [--no-help] # Display usage information
100
+
101
+ Command description...
102
+ OUT
103
+
104
+ expect(output).to eq(expected_output)
105
+ end
106
+ end
107
+ EOS
108
+
109
+ expect(::File.read('spec/unit/server_spec.rb')).to eq <<-EOS
110
+ require 'cli/app/commands/server'
111
+
112
+ RSpec.describe Cli::App::Commands::Server do
113
+ it "executes `server` command successfully" do
114
+ output = StringIO.new
115
+ options = {}
116
+ command = Cli::App::Commands::Server.new(options)
117
+
118
+ command.execute(output: output)
119
+
120
+ expect(output.string).to eq("OK\\n")
121
+ end
122
+ end
123
+ EOS
124
+ end
125
+ end
126
+
127
+ it "adds a subcommand to namespaced application" do
128
+ app_name = tmp_path('cli-app')
129
+ silent_run("teletype new #{app_name} --test rspec")
130
+
131
+ output = <<-OUT
132
+ create spec/integration/config_spec.rb
133
+ create spec/integration/config/set_spec.rb
134
+ create spec/unit/config/set_spec.rb
135
+ create lib/cli/app/commands/config.rb
136
+ create lib/cli/app/commands/config/set.rb
137
+ create lib/cli/app/templates/config/set/.gitkeep
138
+ inject lib/cli/app/cli.rb
139
+ inject lib/cli/app/commands/config.rb
140
+ OUT
141
+
142
+ within_dir(app_name) do
143
+ command_set = "teletype add config set --no-color"
144
+
145
+ out, err, status = Open3.capture3(command_set)
146
+
147
+ expect(err).to eq('')
148
+ expect(out).to eq(output)
149
+ expect(status.exitstatus).to eq(0)
150
+
151
+ # lib/cli/app/cli.rb
152
+ #
153
+ expect(::File.read('lib/cli/app/cli.rb')).to eq <<-EOS
154
+ # frozen_string_literal: true
155
+
156
+ require 'thor'
157
+
158
+ module Cli
159
+ module App
160
+ # Handle the application command line parsing
161
+ # and the dispatch to various command objects
162
+ #
163
+ # @api public
164
+ class CLI < Thor
165
+ # Error raised by this runner
166
+ Error = Class.new(StandardError)
167
+
168
+ desc 'version', 'cli-app version'
169
+ def version
170
+ require_relative 'version'
171
+ puts \"v\#{Cli::App::VERSION}\"
172
+ end
173
+ map %w(--version -v) => :version
174
+
175
+ require_relative 'commands/config'
176
+ register Cli::App::Commands::Config, 'config', 'config [SUBCOMMAND]', 'Command description...'
177
+ end
178
+ end
179
+ end
180
+ EOS
181
+
182
+ # lib/cli/app/commands/config.rb
183
+ #
184
+ expect(::File.read('lib/cli/app/commands/config.rb')).to eq <<-EOS
185
+ # frozen_string_literal: true
186
+
187
+ require 'thor'
188
+
189
+ module Cli
190
+ module App
191
+ module Commands
192
+ class Config < Thor
193
+
194
+ namespace :config
195
+
196
+ desc 'set', 'Command description...'
197
+ method_option :help, aliases: '-h', type: :boolean,
198
+ desc: 'Display usage information'
199
+ def set(*)
200
+ if options[:help]
201
+ invoke :help, ['set']
202
+ else
203
+ require_relative 'config/set'
204
+ Cli::App::Commands::Config::Set.new(options).execute
205
+ end
206
+ end
207
+ end
208
+ end
209
+ end
210
+ end
211
+ EOS
212
+
213
+ # Subcommand `set`
214
+ #
215
+ expect(::File.read('lib/cli/app/commands/config/set.rb')).to eq <<-EOS
216
+ # frozen_string_literal: true
217
+
218
+ require_relative '../../command'
219
+
220
+ module Cli
221
+ module App
222
+ module Commands
223
+ class Config
224
+ class Set < Cli::App::Command
225
+ def initialize(options)
226
+ @options = options
227
+ end
228
+
229
+ def execute(input: $stdin, output: $stdout)
230
+ # Command logic goes here ...
231
+ output.puts "OK"
232
+ end
233
+ end
234
+ end
235
+ end
236
+ end
237
+ end
238
+ EOS
239
+
240
+ # test setup
241
+ #
242
+ expect(::File.read('spec/integration/config_spec.rb')).to eq <<-EOS
243
+ RSpec.describe "`cli-app config` command", type: :cli do
244
+ it "executes `cli-app help config` command successfully" do
245
+ output = `cli-app help config`
246
+ expected_output = <<-OUT
247
+ Commands:
248
+ OUT
249
+
250
+ expect(output).to eq(expected_output)
251
+ end
252
+ end
253
+ EOS
254
+
255
+ expect(::File.read('spec/integration/config/set_spec.rb')).to eq <<-EOS
256
+ RSpec.describe "`cli-app config set` command", type: :cli do
257
+ it "executes `cli-app config help set` command successfully" do
258
+ output = `cli-app config help set`
259
+ expected_output = <<-OUT
260
+ Usage:
261
+ cli-app set
262
+
263
+ Options:
264
+ -h, [--help], [--no-help] # Display usage information
265
+
266
+ Command description...
267
+ OUT
268
+
269
+ expect(output).to eq(expected_output)
270
+ end
271
+ end
272
+ EOS
273
+
274
+ expect(::File.read('spec/unit/config/set_spec.rb')).to eq <<-EOS
275
+ require 'cli/app/commands/config/set'
276
+
277
+ RSpec.describe Cli::App::Commands::Config::Set do
278
+ it "executes `config set` command successfully" do
279
+ output = StringIO.new
280
+ options = {}
281
+ command = Cli::App::Commands::Config::Set.new(options)
282
+
283
+ command.execute(output: output)
284
+
285
+ expect(output.string).to eq("OK\\n")
286
+ end
287
+ end
288
+ EOS
289
+ end
290
+ end
291
+ end
@@ -0,0 +1,535 @@
1
+ RSpec.describe "`teletype add` command", type: :cli do
2
+ it "adds a command" do
3
+ app_name = tmp_path('newcli')
4
+ silent_run("teletype new #{app_name} --test rspec")
5
+
6
+ output = <<-OUT
7
+ create spec/integration/server_spec.rb
8
+ create spec/unit/server_spec.rb
9
+ create lib/newcli/commands/server.rb
10
+ create lib/newcli/templates/server/.gitkeep
11
+ inject lib/newcli/cli.rb
12
+ OUT
13
+
14
+ within_dir(app_name) do
15
+ command = "teletype add server --no-color"
16
+
17
+ out, err, status = Open3.capture3(command)
18
+
19
+ expect(out).to match(output)
20
+ expect(err).to eq('')
21
+ expect(status.exitstatus).to eq(0)
22
+
23
+ # lib/newcli/commands/server.rb
24
+ #
25
+ expect(::File.read('lib/newcli/commands/server.rb')).to eq <<-EOS
26
+ # frozen_string_literal: true
27
+
28
+ require_relative '../command'
29
+
30
+ module Newcli
31
+ module Commands
32
+ class Server < Newcli::Command
33
+ def initialize(options)
34
+ @options = options
35
+ end
36
+
37
+ def execute(input: $stdin, output: $stdout)
38
+ # Command logic goes here ...
39
+ output.puts "OK"
40
+ end
41
+ end
42
+ end
43
+ end
44
+ EOS
45
+
46
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
47
+ # frozen_string_literal: true
48
+
49
+ require 'thor'
50
+
51
+ module Newcli
52
+ # Handle the application command line parsing
53
+ # and the dispatch to various command objects
54
+ #
55
+ # @api public
56
+ class CLI < Thor
57
+ # Error raised by this runner
58
+ Error = Class.new(StandardError)
59
+
60
+ desc 'version', 'newcli version'
61
+ def version
62
+ require_relative 'version'
63
+ puts \"v\#{Newcli::VERSION}\"
64
+ end
65
+ map %w(--version -v) => :version
66
+
67
+ desc 'server', 'Command description...'
68
+ method_option :help, aliases: '-h', type: :boolean,
69
+ desc: 'Display usage information'
70
+ def server(*)
71
+ if options[:help]
72
+ invoke :help, ['server']
73
+ else
74
+ require_relative 'commands/server'
75
+ Newcli::Commands::Server.new(options).execute
76
+ end
77
+ end
78
+ end
79
+ end
80
+ EOS
81
+
82
+ # test setup
83
+ #
84
+ expect(::File.read('spec/integration/server_spec.rb')).to eq <<-EOS
85
+ RSpec.describe "`newcli server` command", type: :cli do
86
+ it "executes `newcli help server` command successfully" do
87
+ output = `newcli help server`
88
+ expected_output = <<-OUT
89
+ Usage:
90
+ newcli server
91
+
92
+ Options:
93
+ -h, [--help], [--no-help] # Display usage information
94
+
95
+ Command description...
96
+ OUT
97
+
98
+ expect(output).to eq(expected_output)
99
+ end
100
+ end
101
+ EOS
102
+
103
+ expect(::File.read('spec/unit/server_spec.rb')).to eq <<-EOS
104
+ require 'newcli/commands/server'
105
+
106
+ RSpec.describe Newcli::Commands::Server do
107
+ it "executes `server` command successfully" do
108
+ output = StringIO.new
109
+ options = {}
110
+ command = Newcli::Commands::Server.new(options)
111
+
112
+ command.execute(output: output)
113
+
114
+ expect(output.string).to eq("OK\\n")
115
+ end
116
+ end
117
+ EOS
118
+
119
+ end
120
+ end
121
+
122
+ it "adds a command with minitests" do
123
+ app_name = tmp_path('newcli')
124
+ silent_run("teletype new #{app_name} --test minitest")
125
+
126
+ output = <<-OUT
127
+ create test/integration/server_test.rb
128
+ create test/unit/server_test.rb
129
+ create lib/newcli/commands/server.rb
130
+ create lib/newcli/templates/server/.gitkeep
131
+ inject lib/newcli/cli.rb
132
+ OUT
133
+
134
+ within_dir(app_name) do
135
+ command = "teletype add server --no-color"
136
+
137
+ out, err, status = Open3.capture3(command)
138
+
139
+ expect(out).to match(output)
140
+ expect(err).to eq('')
141
+ expect(status.exitstatus).to eq(0)
142
+
143
+ # test setup
144
+ #
145
+ expect(::File.read('test/integration/server_test.rb')).to eq <<-EOS
146
+ require 'test_helper'
147
+ require 'newcli/commands/server'
148
+
149
+ class Newcli::Commands::ServerTest < Minitest::Test
150
+ def test_executes_newcli_help_server_command_successfully
151
+ output = `newcli help server`
152
+ expected_output = <<-OUT
153
+ Usage:
154
+ newcli server
155
+
156
+ Options:
157
+ -h, [--help], [--no-help] # Display usage information
158
+
159
+ Command description...
160
+ OUT
161
+
162
+ assert_equal expected_output, output
163
+ end
164
+ end
165
+ EOS
166
+
167
+ expect(::File.read('test/unit/server_test.rb')).to eq <<-EOS
168
+ require 'test_helper'
169
+ require 'newcli/commands/server'
170
+
171
+ class Newcli::Commands::ServerTest < Minitest::Test
172
+ def test_executes_server_command_successfully
173
+ output = StringIO.new
174
+ options = {}
175
+ command = Newcli::Commands::Server.new(options)
176
+
177
+ command.execute(output: output)
178
+
179
+ assert_equal "OK\\n", output.string
180
+ end
181
+ end
182
+ EOS
183
+ end
184
+ end
185
+
186
+ it "adds command in cli without any commands" do
187
+ app_path = tmp_path('newcli')
188
+ cli_template = <<-EOS
189
+ require 'thor'
190
+
191
+ module Newcli
192
+ class CLI < Thor
193
+ end
194
+ end
195
+ EOS
196
+ dir = {
197
+ app_path => [
198
+ 'lib' => [
199
+ 'newcli' => [
200
+ ['cli.rb', cli_template]
201
+ ]
202
+ ]
203
+ ]
204
+ }
205
+
206
+ ::TTY::File.create_dir(dir, verbose: false)
207
+ within_dir(app_path) do
208
+ command = "teletype add server --no-color"
209
+
210
+ _, err, status = Open3.capture3(command)
211
+
212
+ expect(err).to eq('')
213
+ expect(status.exitstatus).to eq(0)
214
+
215
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
216
+ require 'thor'
217
+
218
+ module Newcli
219
+ class CLI < Thor
220
+
221
+ desc 'server', 'Command description...'
222
+ method_option :help, aliases: '-h', type: :boolean,
223
+ desc: 'Display usage information'
224
+ def server(*)
225
+ if options[:help]
226
+ invoke :help, ['server']
227
+ else
228
+ require_relative 'commands/server'
229
+ Newcli::Commands::Server.new(options).execute
230
+ end
231
+ end
232
+ end
233
+ end
234
+ EOS
235
+ end
236
+ end
237
+
238
+ it "adds more than one command to cli file" do
239
+ app_path = tmp_path('newcli')
240
+ cli_template = <<-EOS
241
+ require 'thor'
242
+
243
+ module Newcli
244
+ class CLI < Thor
245
+ end
246
+ end
247
+ EOS
248
+ dir = {
249
+ app_path => [
250
+ 'lib' => [
251
+ 'newcli' => [
252
+ ['cli.rb', cli_template]
253
+ ]
254
+ ]
255
+ ]
256
+ }
257
+
258
+ ::TTY::File.create_dir(dir, verbose: false)
259
+ within_dir(app_path) do
260
+ command_init = "teletype add init --no-color"
261
+
262
+ out, err, status = Open3.capture3(command_init)
263
+
264
+ expect(out).to eq <<-OUT
265
+ create test/integration/init_test.rb
266
+ create test/unit/init_test.rb
267
+ create lib/newcli/commands/init.rb
268
+ create lib/newcli/templates/init/.gitkeep
269
+ inject lib/newcli/cli.rb
270
+ OUT
271
+ expect(err).to eq('')
272
+ expect(status.exitstatus).to eq(0)
273
+
274
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
275
+ require 'thor'
276
+
277
+ module Newcli
278
+ class CLI < Thor
279
+
280
+ desc 'init', 'Command description...'
281
+ method_option :help, aliases: '-h', type: :boolean,
282
+ desc: 'Display usage information'
283
+ def init(*)
284
+ if options[:help]
285
+ invoke :help, ['init']
286
+ else
287
+ require_relative 'commands/init'
288
+ Newcli::Commands::Init.new(options).execute
289
+ end
290
+ end
291
+ end
292
+ end
293
+ EOS
294
+
295
+ command_clone = "teletype add clone --no-color"
296
+ out, err, status = Open3.capture3(command_clone)
297
+
298
+ expect(out).to eq <<-OUT
299
+ create test/integration/clone_test.rb
300
+ create test/unit/clone_test.rb
301
+ create lib/newcli/commands/clone.rb
302
+ create lib/newcli/templates/clone/.gitkeep
303
+ inject lib/newcli/cli.rb
304
+ OUT
305
+ expect(err).to eq('')
306
+ expect(status.exitstatus).to eq(0)
307
+
308
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
309
+ require 'thor'
310
+
311
+ module Newcli
312
+ class CLI < Thor
313
+
314
+ desc 'clone', 'Command description...'
315
+ method_option :help, aliases: '-h', type: :boolean,
316
+ desc: 'Display usage information'
317
+ def clone(*)
318
+ if options[:help]
319
+ invoke :help, ['clone']
320
+ else
321
+ require_relative 'commands/clone'
322
+ Newcli::Commands::Clone.new(options).execute
323
+ end
324
+ end
325
+
326
+ desc 'init', 'Command description...'
327
+ method_option :help, aliases: '-h', type: :boolean,
328
+ desc: 'Display usage information'
329
+ def init(*)
330
+ if options[:help]
331
+ invoke :help, ['init']
332
+ else
333
+ require_relative 'commands/init'
334
+ Newcli::Commands::Init.new(options).execute
335
+ end
336
+ end
337
+ end
338
+ end
339
+ EOS
340
+ end
341
+ end
342
+
343
+ it "adds complex command name as camel case" do
344
+ app_path = tmp_path('newcli')
345
+ cli_template = <<-EOS
346
+ require 'thor'
347
+
348
+ module Newcli
349
+ class CLI < Thor
350
+ end
351
+ end
352
+ EOS
353
+ dir = {
354
+ app_path => [
355
+ 'lib' => [
356
+ 'newcli' => [
357
+ ['cli.rb', cli_template]
358
+ ]
359
+ ]
360
+ ]
361
+ }
362
+ ::TTY::File.create_dir(dir, verbose: false)
363
+ within_dir(app_path) do
364
+ command = "teletype add newServerCommand --no-color"
365
+
366
+ _, err, status = Open3.capture3(command)
367
+
368
+ expect(err).to eq('')
369
+ expect(status.exitstatus).to eq(0)
370
+
371
+ expect(::File.read('lib/newcli/commands/new_server_command.rb')).to eq <<-EOS
372
+ # frozen_string_literal: true
373
+
374
+ require_relative '../command'
375
+
376
+ module Newcli
377
+ module Commands
378
+ class NewServerCommand < Newcli::Command
379
+ def initialize(options)
380
+ @options = options
381
+ end
382
+
383
+ def execute(input: $stdin, output: $stdout)
384
+ # Command logic goes here ...
385
+ output.puts "OK"
386
+ end
387
+ end
388
+ end
389
+ end
390
+ EOS
391
+
392
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
393
+ require 'thor'
394
+
395
+ module Newcli
396
+ class CLI < Thor
397
+
398
+ desc 'new_server_command', 'Command description...'
399
+ method_option :help, aliases: '-h', type: :boolean,
400
+ desc: 'Display usage information'
401
+ def new_server_command(*)
402
+ if options[:help]
403
+ invoke :help, ['new_server_command']
404
+ else
405
+ require_relative 'commands/new_server_command'
406
+ Newcli::Commands::NewServerCommand.new(options).execute
407
+ end
408
+ end
409
+ end
410
+ end
411
+ EOS
412
+ end
413
+ end
414
+
415
+ it "adds complex command name as snake case" do
416
+ app_path = tmp_path('newcli')
417
+ cli_template = <<-EOS
418
+ require 'thor'
419
+
420
+ module Newcli
421
+ class CLI < Thor
422
+ end
423
+ end
424
+ EOS
425
+ dir = {
426
+ app_path => [
427
+ 'lib' => [
428
+ 'newcli' => [
429
+ ['cli.rb', cli_template]
430
+ ]
431
+ ]
432
+ ]
433
+ }
434
+ ::TTY::File.create_dir(dir, verbose: false)
435
+
436
+ within_dir(app_path) do
437
+ command = "teletype add new_server_command --no-color"
438
+
439
+ _, err, status = Open3.capture3(command)
440
+
441
+ expect(err).to eq('')
442
+ expect(status.exitstatus).to eq(0)
443
+
444
+ expect(::File.read('lib/newcli/commands/new_server_command.rb')).to eq <<-EOS
445
+ # frozen_string_literal: true
446
+
447
+ require_relative '../command'
448
+
449
+ module Newcli
450
+ module Commands
451
+ class NewServerCommand < Newcli::Command
452
+ def initialize(options)
453
+ @options = options
454
+ end
455
+
456
+ def execute(input: $stdin, output: $stdout)
457
+ # Command logic goes here ...
458
+ output.puts "OK"
459
+ end
460
+ end
461
+ end
462
+ end
463
+ EOS
464
+
465
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
466
+ require 'thor'
467
+
468
+ module Newcli
469
+ class CLI < Thor
470
+
471
+ desc 'new_server_command', 'Command description...'
472
+ method_option :help, aliases: '-h', type: :boolean,
473
+ desc: 'Display usage information'
474
+ def new_server_command(*)
475
+ if options[:help]
476
+ invoke :help, ['new_server_command']
477
+ else
478
+ require_relative 'commands/new_server_command'
479
+ Newcli::Commands::NewServerCommand.new(options).execute
480
+ end
481
+ end
482
+ end
483
+ end
484
+ EOS
485
+ end
486
+ end
487
+
488
+ it "fails without command name" do
489
+ output = <<-OUT.unindent
490
+ ERROR: 'teletype add' was called with no arguments
491
+ Usage: 'teletype add COMMAND_NAME'\n
492
+ OUT
493
+ command = "teletype add"
494
+ out, err, status = Open3.capture3(command)
495
+ expect([out, err, status.exitstatus]).to match_array([output, '', 1])
496
+ end
497
+
498
+ it "displays help" do
499
+ output = <<-OUT
500
+ Usage:
501
+ teletype add COMMAND [SUBCOMMAND] [OPTIONS]
502
+
503
+ Options:
504
+ -a, [--args=arg1 arg2] # List command argument names
505
+ -d, [--desc=DESC] # Describe command's purpose
506
+ -f, [--force] # Overwrite existing command
507
+ -h, [--help], [--no-help] # Display usage information
508
+ -t, [--test=rspec] # Generate a test setup
509
+ # Possible values: rspec, minitest
510
+ [--no-color] # Disable colorization in output
511
+ -r, [--dry-run], [--no-dry-run] # Run but do not make any changes
512
+ [--debug], [--no-debug] # Run in debug mode
513
+
514
+ Description:
515
+ The `teletype add` will create a new command and place it into appropriate
516
+ structure in the cli app.
517
+
518
+ Example: teletype add config --desc 'Set and get configuration options'
519
+
520
+ This generates a command in app/commands/config.rb
521
+
522
+ You can also add subcommands
523
+
524
+ Example: teletype add config server
525
+
526
+ This generates a command in app/commands/config/server.rb
527
+ OUT
528
+
529
+ command = "teletype add --help"
530
+ out, err, status = Open3.capture3(command)
531
+ expect(out).to eq(output)
532
+ expect(err).to eq('')
533
+ expect(status.exitstatus).to eq(0)
534
+ end
535
+ end