tty 0.7.0 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
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,259 @@
1
+ RSpec.describe "`teletype add` subcommad", type: :cli do
2
+ it "adds a new subcommand" do
3
+ app_name = tmp_path('newcli')
4
+ silent_run("teletype new #{app_name} --test rspec")
5
+
6
+ output = <<-OUT
7
+ create spec/integration/config_spec.rb
8
+ create spec/integration/config/set_spec.rb
9
+ create spec/unit/config/set_spec.rb
10
+ create lib/newcli/commands/config.rb
11
+ create lib/newcli/commands/config/set.rb
12
+ create lib/newcli/templates/config/set/.gitkeep
13
+ inject lib/newcli/cli.rb
14
+ inject lib/newcli/commands/config.rb
15
+ OUT
16
+
17
+ within_dir(app_name) do
18
+ command_set = "teletype add config set --no-color"
19
+
20
+ out, err, status = Open3.capture3(command_set)
21
+
22
+ expect(err).to eq('')
23
+ expect(out).to eq(output)
24
+ expect(status.exitstatus).to eq(0)
25
+
26
+ expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
27
+ # frozen_string_literal: true
28
+
29
+ require 'thor'
30
+
31
+ module Newcli
32
+ # Handle the application command line parsing
33
+ # and the dispatch to various command objects
34
+ #
35
+ # @api public
36
+ class CLI < Thor
37
+ # Error raised by this runner
38
+ Error = Class.new(StandardError)
39
+
40
+ desc 'version', 'newcli version'
41
+ def version
42
+ require_relative 'version'
43
+ puts \"v\#{Newcli::VERSION}\"
44
+ end
45
+ map %w(--version -v) => :version
46
+
47
+ require_relative 'commands/config'
48
+ register Newcli::Commands::Config, 'config', 'config [SUBCOMMAND]', 'Command description...'
49
+ end
50
+ end
51
+ EOS
52
+
53
+ expect(::File.read('lib/newcli/commands/config.rb')).to eq <<-EOS
54
+ # frozen_string_literal: true
55
+
56
+ require 'thor'
57
+
58
+ module Newcli
59
+ module Commands
60
+ class Config < Thor
61
+
62
+ namespace :config
63
+
64
+ desc 'set', 'Command description...'
65
+ method_option :help, aliases: '-h', type: :boolean,
66
+ desc: 'Display usage information'
67
+ def set(*)
68
+ if options[:help]
69
+ invoke :help, ['set']
70
+ else
71
+ require_relative 'config/set'
72
+ Newcli::Commands::Config::Set.new(options).execute
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
78
+ EOS
79
+
80
+ # Subcommand `set`
81
+ #
82
+ expect(::File.read('lib/newcli/commands/config/set.rb')).to eq <<-EOS
83
+ # frozen_string_literal: true
84
+
85
+ require_relative '../../command'
86
+
87
+ module Newcli
88
+ module Commands
89
+ class Config
90
+ class Set < Newcli::Command
91
+ def initialize(options)
92
+ @options = options
93
+ end
94
+
95
+ def execute(input: $stdin, output: $stdout)
96
+ # Command logic goes here ...
97
+ output.puts "OK"
98
+ end
99
+ end
100
+ end
101
+ end
102
+ end
103
+ EOS
104
+
105
+ # spec/integration/config_spec.rb
106
+ #
107
+ expect(::File.read('spec/integration/config_spec.rb')).to eq <<-EOS
108
+ RSpec.describe "`newcli config` command", type: :cli do
109
+ it "executes `newcli help config` command successfully" do
110
+ output = `newcli help config`
111
+ expected_output = <<-OUT
112
+ Commands:
113
+ OUT
114
+
115
+ expect(output).to eq(expected_output)
116
+ end
117
+ end
118
+ EOS
119
+
120
+ # spec/integration/config/set_spec.rb
121
+ #
122
+ expect(::File.read('spec/integration/config/set_spec.rb')).to eq <<-EOS
123
+ RSpec.describe "`newcli config set` command", type: :cli do
124
+ it "executes `newcli config help set` command successfully" do
125
+ output = `newcli config help set`
126
+ expected_output = <<-OUT
127
+ Usage:
128
+ newcli set
129
+
130
+ Options:
131
+ -h, [--help], [--no-help] # Display usage information
132
+
133
+ Command description...
134
+ OUT
135
+
136
+ expect(output).to eq(expected_output)
137
+ end
138
+ end
139
+ EOS
140
+
141
+ # spec/unit/config/set_spec.rb
142
+ #
143
+ expect(::File.read('spec/unit/config/set_spec.rb')).to eq <<-EOS
144
+ require 'newcli/commands/config/set'
145
+
146
+ RSpec.describe Newcli::Commands::Config::Set do
147
+ it "executes `config set` command successfully" do
148
+ output = StringIO.new
149
+ options = {}
150
+ command = Newcli::Commands::Config::Set.new(options)
151
+
152
+ command.execute(output: output)
153
+
154
+ expect(output.string).to eq("OK\\n")
155
+ end
156
+ end
157
+ EOS
158
+
159
+ command_get = "teletype add config get --no-color"
160
+
161
+ out, err, status = Open3.capture3(command_get)
162
+
163
+ expect(out).to include <<-OUT
164
+ create spec/integration/config/get_spec.rb
165
+ create spec/unit/config/get_spec.rb
166
+ create lib/newcli/commands/config/get.rb
167
+ create lib/newcli/templates/config/get/.gitkeep
168
+ inject lib/newcli/commands/config.rb
169
+ OUT
170
+ expect(err).to eq('')
171
+ expect(status.exitstatus).to eq(0)
172
+ end
173
+ end
174
+
175
+ it "adds a new subcommand with minitest" do
176
+ app_name = tmp_path('newcli')
177
+ silent_run("teletype new #{app_name} --test minitest")
178
+
179
+ output = <<-OUT
180
+ create test/integration/config_test.rb
181
+ create test/integration/config/set_test.rb
182
+ create test/unit/config/set_test.rb
183
+ create lib/newcli/commands/config.rb
184
+ create lib/newcli/commands/config/set.rb
185
+ create lib/newcli/templates/config/set/.gitkeep
186
+ inject lib/newcli/cli.rb
187
+ inject lib/newcli/commands/config.rb
188
+ OUT
189
+
190
+ within_dir(app_name) do
191
+ command_set = "teletype add config set --no-color"
192
+
193
+ out, err, status = Open3.capture3(command_set)
194
+
195
+ expect(err).to eq('')
196
+ expect(out).to eq(output)
197
+ expect(status.exitstatus).to eq(0)
198
+
199
+ # test setup
200
+ #
201
+ expect(::File.read('test/integration/config_test.rb')).to eq <<-EOS
202
+ require 'test_helper'
203
+ require 'newcli/commands/config'
204
+
205
+ class Newcli::Commands::ConfigTest < Minitest::Test
206
+ def test_executes_newcli_help_config_command_successfully
207
+ output = `newcli help config`
208
+ expected_output = <<-OUT
209
+ Commands:
210
+ OUT
211
+
212
+ assert_equal expected_output, output
213
+ end
214
+ end
215
+ EOS
216
+
217
+ expect(::File.read('test/integration/config/set_test.rb')).to eq <<-EOS
218
+ require 'test_helper'
219
+ require 'newcli/commands/config/set'
220
+
221
+ class Newcli::Commands::Config::SetTest < Minitest::Test
222
+ def test_executes_newcli_config_help_set_command_successfully
223
+ output = `newcli config help set`
224
+ expect_output = <<-OUT
225
+ Usage:
226
+ newcli set
227
+
228
+ Options:
229
+ -h, [--help], [--no-help] # Display usage information
230
+
231
+ Command description...
232
+ OUT
233
+
234
+ assert_equal expected_output, output
235
+ end
236
+ end
237
+ EOS
238
+
239
+ # test/unit/config/set_test.rb
240
+ #
241
+ expect(::File.read('test/unit/config/set_test.rb')).to eq <<-EOS
242
+ require 'test_helper'
243
+ require 'newcli/commands/config/set'
244
+
245
+ class Newcli::Commands::Config::SetTest < Minitest::Test
246
+ def test_executes_config_set_command_successfully
247
+ output = StringIO.new
248
+ options = {}
249
+ command = Newcli::Commands::Config::Set.new(options)
250
+
251
+ command.execute(output: output)
252
+
253
+ assert_equal "OK\\n", output.string
254
+ end
255
+ end
256
+ EOS
257
+ end
258
+ end
259
+ end
@@ -0,0 +1,19 @@
1
+ RSpec.describe "`teletype new --author` command", type: :cli do
2
+ it "sets an author" do
3
+ app_name = tmp_path('newcli')
4
+ command = "teletype new #{app_name} --author 'Author A'"
5
+ `#{command}`
6
+
7
+ license = ::File.binread(tmp_path('newcli/LICENSE.txt'))
8
+ expect(license).to include('Author A')
9
+ end
10
+
11
+ it "sets multiple authors" do
12
+ app_name = tmp_path('newcli')
13
+ command = "teletype new #{app_name} --author 'Author A' 'Author B'"
14
+ `#{command}`
15
+
16
+ license = ::File.binread(tmp_path('newcli/LICENSE.txt'))
17
+ expect(license).to include('Author A, Author B')
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ RSpec.describe 'teletype new --license', type: :cli do
2
+ it "generates a MIT license file" do
3
+ app_name = tmp_path('newcli')
4
+ command = "teletype new #{app_name} --license mit --author 'Piotr Murach'"
5
+ `#{command}`
6
+
7
+ license = File.binread(tmp_path('newcli/LICENSE.txt'))
8
+ gemspec = File.binread(tmp_path('newcli/newcli.gemspec'))
9
+ readme = File.binread(tmp_path('newcli/README.md'))
10
+
11
+ expect(license.lines[0]).to eq("The MIT License (MIT)\n")
12
+ expect(gemspec).to match(/spec.license\s{7}= "MIT"/)
13
+ expect(readme).to include "Copyright (c) #{Time.now.year} Piotr Murach. See [MIT License](LICENSE.txt) for further details."
14
+ end
15
+
16
+ it "generates a GPL-3.0 license file" do
17
+ app_name = tmp_path('newcli')
18
+ command = "teletype new #{app_name} -l gplv3 -a 'Piotr Murach'"
19
+ `#{command}`
20
+
21
+ license = File.binread(tmp_path('newcli/LICENSE.txt'))
22
+ gemspec = File.binread(tmp_path('newcli/newcli.gemspec'))
23
+ readme = File.binread(tmp_path('newcli/README.md'))
24
+
25
+ expect(license.lines[0]).to eq("GNU GENERAL PUBLIC LICENSE\n")
26
+ expect(gemspec).to match(/spec.license\s{7}= "GPL-3.0"/)
27
+ expect(readme).to include "Copyright (c) #{Time.now.year} Piotr Murach. See [GNU General Public License v3.0](LICENSE.txt) for further details."
28
+ end
29
+
30
+ it "fails to recognise the license type" do
31
+ app_name = tmp_path('newcli')
32
+ command = "teletype new #{app_name} --license unknown"
33
+ out, err, process = Open3.capture3(command)
34
+
35
+ expect(out).to eq('')
36
+ expect(err).to eq("Expected '--license' to be one of agplv3, apache, bsd2, bsd3, gplv2, gplv3, lgplv3, mit, mplv2, custom; got unknown\n")
37
+ expect(process.exitstatus).to eq(0) # FIXME: wrong status
38
+ end
39
+ end
@@ -0,0 +1,228 @@
1
+ RSpec.describe 'teletype new', type: :cli do
2
+ it "generates cli application namespaced" do
3
+ app_name = tmp_path('cli-app')
4
+
5
+ output = <<-OUT
6
+ Creating gem 'cli-app'...
7
+ create tmp/cli-app/Gemfile
8
+ create tmp/cli-app/lib/cli/app.rb
9
+ create tmp/cli-app/lib/cli/app/version.rb
10
+ create tmp/cli-app/cli-app.gemspec
11
+ create tmp/cli-app/Rakefile
12
+ create tmp/cli-app/README.md
13
+ create tmp/cli-app/bin/console
14
+ create tmp/cli-app/bin/setup
15
+ create tmp/cli-app/.gitignore
16
+ create tmp/cli-app/.travis.yml
17
+ create tmp/cli-app/.rspec
18
+ create tmp/cli-app/spec/spec_helper.rb
19
+ create tmp/cli-app/spec/cli/app_spec.rb
20
+ append tmp/cli-app/README.md
21
+ inject tmp/cli-app/cli-app.gemspec
22
+ create tmp/cli-app/lib/cli/app/cli.rb
23
+ create tmp/cli-app/lib/cli/app/command.rb
24
+ create tmp/cli-app/exe/cli-app
25
+ create tmp/cli-app/LICENSE.txt
26
+ create tmp/cli-app/lib/cli/app/commands/.gitkeep
27
+ create tmp/cli-app/lib/cli/app/templates/.gitkeep
28
+ create tmp/cli-app/spec/integration/.gitkeep
29
+ create tmp/cli-app/spec/support/.gitkeep
30
+ create tmp/cli-app/spec/unit/.gitkeep
31
+ Initializing git repo in #{app_name}
32
+
33
+ Your teletype project has been created successfully.
34
+
35
+ Run "teletype help" for more commands.
36
+ OUT
37
+
38
+ command = "teletype new #{app_name} --no-coc --no-color --license mit"
39
+
40
+ out, err, status = Open3.capture3(command)
41
+
42
+ expect(out).to include(output)
43
+ expect(err).to eq('')
44
+ expect(status.exitstatus).to eq(0)
45
+
46
+ within_dir(app_name) do
47
+
48
+ # exe/cli-app
49
+ #
50
+ expect(::File.read('exe/cli-app')).to eq(<<-EOS)
51
+ #!/usr/bin/env ruby
52
+ # frozen_string_literal: true
53
+
54
+ lib_path = File.expand_path('../lib', __dir__)
55
+ $:.unshift(lib_path) if !$:.include?(lib_path)
56
+ require 'cli/app/cli'
57
+
58
+ Signal.trap('INT') do
59
+ warn(\"\\n\#{caller.join(\"\\n\")}: interrupted\")
60
+ exit(1)
61
+ end
62
+
63
+ begin
64
+ Cli::App::CLI.start
65
+ rescue Cli::App::CLI::Error => err
66
+ puts \"ERROR: \#{err.message}\"
67
+ exit 1
68
+ end
69
+ EOS
70
+
71
+ # lib/cli/app/cli.rb
72
+ #
73
+ expect(::File.read('lib/cli/app/cli.rb')).to eq(<<-EOS)
74
+ # frozen_string_literal: true
75
+
76
+ require 'thor'
77
+
78
+ module Cli
79
+ module App
80
+ # Handle the application command line parsing
81
+ # and the dispatch to various command objects
82
+ #
83
+ # @api public
84
+ class CLI < Thor
85
+ # Error raised by this runner
86
+ Error = Class.new(StandardError)
87
+
88
+ desc 'version', 'cli-app version'
89
+ def version
90
+ require_relative 'version'
91
+ puts \"v\#{Cli::App::VERSION}\"
92
+ end
93
+ map %w(--version -v) => :version
94
+ end
95
+ end
96
+ end
97
+ EOS
98
+
99
+ # lib/newcli/cmd.rb
100
+ #
101
+ expect(::File.read('lib/cli/app/command.rb')).to eq(<<-EOS)
102
+ # frozen_string_literal: true
103
+
104
+ require 'forwardable'
105
+
106
+ module Cli
107
+ module App
108
+ class Command
109
+ extend Forwardable
110
+
111
+ def_delegators :command, :run
112
+
113
+ # Execute this command
114
+ #
115
+ # @api public
116
+ def execute(*)
117
+ raise(
118
+ NotImplementedError,
119
+ "\#{self.class}#\#{__method__} must be implemented"
120
+ )
121
+ end
122
+
123
+ # The external commands runner
124
+ #
125
+ # @see http://www.rubydoc.info/gems/tty-command
126
+ #
127
+ # @api public
128
+ def command(**options)
129
+ require 'tty-command'
130
+ TTY::Command.new(options)
131
+ end
132
+
133
+ # The cursor movement
134
+ #
135
+ # @see http://www.rubydoc.info/gems/tty-cursor
136
+ #
137
+ # @api public
138
+ def cursor
139
+ require 'tty-cursor'
140
+ TTY::Cursor
141
+ end
142
+
143
+ # Open a file or text in the user's preferred editor
144
+ #
145
+ # @see http://www.rubydoc.info/gems/tty-editor
146
+ #
147
+ # @api public
148
+ def editor
149
+ require 'tty-editor'
150
+ TTY::Editor
151
+ end
152
+
153
+ # File manipulation utility methods
154
+ #
155
+ # @see http://www.rubydoc.info/gems/tty-file
156
+ #
157
+ # @api public
158
+ def generator
159
+ require 'tty-file'
160
+ TTY::File
161
+ end
162
+
163
+ # Terminal output paging
164
+ #
165
+ # @see http://www.rubydoc.info/gems/tty-pager
166
+ #
167
+ # @api public
168
+ def pager(**options)
169
+ require 'tty-pager'
170
+ TTY::Pager.new(options)
171
+ end
172
+
173
+ # Terminal platform and OS properties
174
+ #
175
+ # @see http://www.rubydoc.info/gems/tty-pager
176
+ #
177
+ # @api public
178
+ def platform
179
+ require 'tty-platform'
180
+ TTY::Platform.new
181
+ end
182
+
183
+ # The interactive prompt
184
+ #
185
+ # @see http://www.rubydoc.info/gems/tty-prompt
186
+ #
187
+ # @api public
188
+ def prompt(**options)
189
+ require 'tty-prompt'
190
+ TTY::Prompt.new(options)
191
+ end
192
+
193
+ # Get terminal screen properties
194
+ #
195
+ # @see http://www.rubydoc.info/gems/tty-screen
196
+ #
197
+ # @api public
198
+ def screen
199
+ require 'tty-screen'
200
+ TTY::Screen
201
+ end
202
+
203
+ # The unix which utility
204
+ #
205
+ # @see http://www.rubydoc.info/gems/tty-which
206
+ #
207
+ # @api public
208
+ def which(*args)
209
+ require 'tty-which'
210
+ TTY::Which.which(*args)
211
+ end
212
+
213
+ # Check if executable exists
214
+ #
215
+ # @see http://www.rubydoc.info/gems/tty-which
216
+ #
217
+ # @api public
218
+ def exec_exist?(*args)
219
+ require 'tty-which'
220
+ TTY::Which.exist?(*args)
221
+ end
222
+ end
223
+ end
224
+ end
225
+ EOS
226
+ end
227
+ end
228
+ end