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.
- checksums.yaml +4 -4
- data/.rspec +2 -2
- data/.travis.yml +15 -4
- data/CHANGELOG.md +22 -0
- data/Gemfile +4 -7
- data/README.md +648 -58
- data/appveyor.yml +3 -4
- data/exe/teletype +18 -0
- data/lib/tty.rb +7 -4
- data/lib/tty/cli.rb +140 -0
- data/lib/tty/cmd.rb +132 -0
- data/lib/tty/commands/add.rb +321 -0
- data/lib/tty/commands/new.rb +256 -0
- data/lib/tty/gemspec.rb +30 -0
- data/lib/tty/licenses.rb +34 -0
- data/lib/tty/path_helpers.rb +38 -0
- data/lib/tty/plugins.rb +20 -12
- data/lib/tty/templater.rb +54 -0
- data/lib/tty/templates/add/command.rb.tt +31 -0
- data/lib/tty/templates/add/gitkeep.tt +1 -0
- data/lib/tty/templates/add/namespace.rb.tt +17 -0
- data/lib/tty/templates/add/spec/integration/command_spec.rb.tt +20 -0
- data/lib/tty/templates/add/spec/integration/sub_command_spec.rb.tt +16 -0
- data/lib/tty/templates/add/spec/unit/command_spec.rb.tt +15 -0
- data/lib/tty/templates/add/spec/unit/sub_command_spec.rb.tt +15 -0
- data/lib/tty/templates/add/test/integration/command_test.rb.tt +23 -0
- data/lib/tty/templates/add/test/integration/sub_command_test.rb.tt +19 -0
- data/lib/tty/templates/add/test/unit/command_test.rb.tt +16 -0
- data/lib/tty/templates/add/test/unit/sub_command_test.rb.tt +16 -0
- data/lib/tty/templates/new/agplv3_LICENSE.txt.tt +555 -0
- data/lib/tty/templates/new/apache_LICENSE.txt.tt +157 -0
- data/lib/tty/templates/new/bsd2_LICENSE.txt.tt +22 -0
- data/lib/tty/templates/new/bsd3_LICENSE.txt.tt +26 -0
- data/lib/tty/templates/new/exe/newcli.tt +18 -0
- data/lib/tty/templates/new/gitkeep.tt +1 -0
- data/lib/tty/templates/new/gplv2_LICENSE.txt.tt +255 -0
- data/lib/tty/templates/new/gplv3_LICENSE.txt.tt +543 -0
- data/lib/tty/templates/new/lgplv3_LICENSE.txt.tt +143 -0
- data/lib/tty/templates/new/lib/newcli/cli.rb.tt +24 -0
- data/lib/tty/templates/new/lib/newcli/command.rb.tt +124 -0
- data/lib/tty/templates/new/mit_LICENSE.txt.tt +20 -0
- data/lib/tty/templates/new/mplv2_LICENSE.txt.tt +277 -0
- data/lib/tty/version.rb +1 -1
- data/spec/fixtures/foo-0.0.1.gemspec +4 -4
- data/spec/integration/add_desc_args_spec.rb +341 -0
- data/spec/integration/add_force_spec.rb +98 -0
- data/spec/integration/add_namespaced_spec.rb +291 -0
- data/spec/integration/add_spec.rb +535 -0
- data/spec/integration/add_subcommand_spec.rb +259 -0
- data/spec/integration/new_author_spec.rb +19 -0
- data/spec/integration/new_license_spec.rb +39 -0
- data/spec/integration/new_namespaced_spec.rb +228 -0
- data/spec/integration/new_spec.rb +354 -0
- data/spec/integration/new_test_spec.rb +21 -0
- data/spec/integration/start_spec.rb +21 -0
- data/spec/spec_helper.rb +47 -16
- data/spec/unit/gemspec_spec.rb +17 -0
- data/spec/{tty/plugins/load_spec.rb → unit/plugins/activate_spec.rb} +2 -4
- data/spec/unit/plugins/load_from_spec.rb +28 -0
- data/spec/{tty → unit}/plugins/plugin/load_spec.rb +1 -3
- data/spec/{tty → unit}/plugins/plugin/new_spec.rb +1 -3
- data/spec/{tty → unit}/tty_spec.rb +1 -3
- data/tty.gemspec +25 -15
- metadata +186 -49
- data/spec/tty/plugins/find_spec.rb +0 -20
- data/tasks/metrics/cane.rake +0 -14
- data/tasks/metrics/flog.rake +0 -17
- data/tasks/metrics/heckle.rake +0 -15
- data/tasks/metrics/reek.rake +0 -13
    
        data/lib/tty/version.rb
    CHANGED
    
    
| @@ -1,11 +1,11 @@ | |
| 1 1 | 
             
            # encoding: utf-8
         | 
| 2 2 |  | 
| 3 3 | 
             
            Gem::Specification.new do |spec|
         | 
| 4 | 
            -
              spec.name | 
| 5 | 
            -
              spec.version | 
| 6 | 
            -
              spec.platform | 
| 4 | 
            +
              spec.name          = 'foo'
         | 
| 5 | 
            +
              spec.version       = '0.0.1'
         | 
| 6 | 
            +
              spec.platform      = 'ruby'
         | 
| 7 | 
            +
              spec.summary       = 'A foo gem'
         | 
| 7 8 | 
             
              spec.require_paths = ['lib']
         | 
| 8 | 
            -
              spec.summary = 'A foo gem'
         | 
| 9 9 |  | 
| 10 10 | 
             
              spec.add_dependency 'pastel'
         | 
| 11 11 | 
             
              spec.add_dependency 'equatable'
         | 
| @@ -0,0 +1,341 @@ | |
| 1 | 
            +
            RSpec.describe "`teletype add --desc --args` command", type: :cli do
         | 
| 2 | 
            +
              it "adds command with description and custom arguments" do
         | 
| 3 | 
            +
                app_path = tmp_path('newcli')
         | 
| 4 | 
            +
                cli_template = <<-EOS
         | 
| 5 | 
            +
            require 'thor'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module Newcli
         | 
| 8 | 
            +
              class CLI < Thor
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| 11 | 
            +
                EOS
         | 
| 12 | 
            +
                dir = {
         | 
| 13 | 
            +
                  app_path => [
         | 
| 14 | 
            +
                    'lib' => [
         | 
| 15 | 
            +
                      'newcli' => [
         | 
| 16 | 
            +
                        ['cli.rb', cli_template]
         | 
| 17 | 
            +
                      ]
         | 
| 18 | 
            +
                    ]
         | 
| 19 | 
            +
                  ]
         | 
| 20 | 
            +
                }
         | 
| 21 | 
            +
                ::TTY::File.create_dir(dir, verbose: false)
         | 
| 22 | 
            +
                within_dir(app_path) do
         | 
| 23 | 
            +
                  command = "teletype add config --test rspec --desc='Set and get configuration option' --args=arg1 arg2 --no-color"
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                  out, err, status = Open3.capture3(command)
         | 
| 26 | 
            +
             | 
| 27 | 
            +
                  expect(out).to match <<-OUT
         | 
| 28 | 
            +
                  create  spec/integration/config_spec.rb
         | 
| 29 | 
            +
                  create  spec/unit/config_spec.rb
         | 
| 30 | 
            +
                  create  lib/newcli/commands/config.rb
         | 
| 31 | 
            +
                  create  lib/newcli/templates/config/.gitkeep
         | 
| 32 | 
            +
                  inject  lib/newcli/cli.rb
         | 
| 33 | 
            +
                  OUT
         | 
| 34 | 
            +
                  expect(err).to eq('')
         | 
| 35 | 
            +
                  expect(status.exitstatus).to eq(0)
         | 
| 36 | 
            +
             | 
| 37 | 
            +
                  expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
         | 
| 38 | 
            +
            require 'thor'
         | 
| 39 | 
            +
             | 
| 40 | 
            +
            module Newcli
         | 
| 41 | 
            +
              class CLI < Thor
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                desc 'config ARG1 ARG2', 'Set and get configuration option'
         | 
| 44 | 
            +
                method_option :help, aliases: '-h', type: :boolean,
         | 
| 45 | 
            +
                                     desc: 'Display usage information'
         | 
| 46 | 
            +
                def config(arg1, arg2)
         | 
| 47 | 
            +
                  if options[:help]
         | 
| 48 | 
            +
                    invoke :help, ['config']
         | 
| 49 | 
            +
                  else
         | 
| 50 | 
            +
                    require_relative 'commands/config'
         | 
| 51 | 
            +
                    Newcli::Commands::Config.new(arg1, arg2, options).execute
         | 
| 52 | 
            +
                  end
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
              end
         | 
| 55 | 
            +
            end
         | 
| 56 | 
            +
                  EOS
         | 
| 57 | 
            +
             | 
| 58 | 
            +
                  expect(::File.read('lib/newcli/commands/config.rb')).to eq <<-EOS
         | 
| 59 | 
            +
            # frozen_string_literal: true
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            require_relative '../command'
         | 
| 62 | 
            +
             | 
| 63 | 
            +
            module Newcli
         | 
| 64 | 
            +
              module Commands
         | 
| 65 | 
            +
                class Config < Newcli::Command
         | 
| 66 | 
            +
                  def initialize(arg1, arg2, options)
         | 
| 67 | 
            +
                    @arg1 = arg1
         | 
| 68 | 
            +
                    @arg2 = arg2
         | 
| 69 | 
            +
                    @options = options
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  def execute(input: $stdin, output: $stdout)
         | 
| 73 | 
            +
                    # Command logic goes here ...
         | 
| 74 | 
            +
                    output.puts "OK"
         | 
| 75 | 
            +
                  end
         | 
| 76 | 
            +
                end
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
            end
         | 
| 79 | 
            +
                  EOS
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                  # test setup
         | 
| 82 | 
            +
                  #
         | 
| 83 | 
            +
                  expect(::File.read('spec/integration/config_spec.rb')).to eq <<-EOS
         | 
| 84 | 
            +
            RSpec.describe "`newcli config` command", type: :cli do
         | 
| 85 | 
            +
              it "executes `newcli help config` command successfully" do
         | 
| 86 | 
            +
                output = `newcli help config`
         | 
| 87 | 
            +
                expected_output = <<-OUT
         | 
| 88 | 
            +
            Usage:
         | 
| 89 | 
            +
              newcli config ARG1 ARG2
         | 
| 90 | 
            +
             | 
| 91 | 
            +
            Options:
         | 
| 92 | 
            +
              -h, [--help], [--no-help]  # Display usage information
         | 
| 93 | 
            +
             | 
| 94 | 
            +
            Set and get configuration option
         | 
| 95 | 
            +
                OUT
         | 
| 96 | 
            +
             | 
| 97 | 
            +
                expect(output).to eq(expected_output)
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
            end
         | 
| 100 | 
            +
                  EOS
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                  expect(::File.read('spec/unit/config_spec.rb')).to eq <<-EOS
         | 
| 103 | 
            +
            require 'newcli/commands/config'
         | 
| 104 | 
            +
             | 
| 105 | 
            +
            RSpec.describe Newcli::Commands::Config do
         | 
| 106 | 
            +
              it "executes `config` command successfully" do
         | 
| 107 | 
            +
                output = StringIO.new
         | 
| 108 | 
            +
                arg1 = nil
         | 
| 109 | 
            +
                arg2 = nil
         | 
| 110 | 
            +
                options = {}
         | 
| 111 | 
            +
                command = Newcli::Commands::Config.new(arg1, arg2, options)
         | 
| 112 | 
            +
             | 
| 113 | 
            +
                command.execute(output: output)
         | 
| 114 | 
            +
             | 
| 115 | 
            +
                expect(output.string).to eq("OK\\n")
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
            end
         | 
| 118 | 
            +
                  EOS
         | 
| 119 | 
            +
                end
         | 
| 120 | 
            +
              end
         | 
| 121 | 
            +
             | 
| 122 | 
            +
              it "adds command with variadic number of arguments" do
         | 
| 123 | 
            +
                app_path = tmp_path('newcli')
         | 
| 124 | 
            +
                cli_template = <<-EOS
         | 
| 125 | 
            +
            require 'thor'
         | 
| 126 | 
            +
             | 
| 127 | 
            +
            module Newcli
         | 
| 128 | 
            +
              class CLI < Thor
         | 
| 129 | 
            +
              end
         | 
| 130 | 
            +
            end
         | 
| 131 | 
            +
                EOS
         | 
| 132 | 
            +
                dir = {
         | 
| 133 | 
            +
                  app_path => [
         | 
| 134 | 
            +
                    'lib' => [
         | 
| 135 | 
            +
                      'newcli' => [
         | 
| 136 | 
            +
                        ['cli.rb', cli_template]
         | 
| 137 | 
            +
                      ]
         | 
| 138 | 
            +
                    ]
         | 
| 139 | 
            +
                  ]
         | 
| 140 | 
            +
                }
         | 
| 141 | 
            +
                ::TTY::File.create_dir(dir, verbose: false)
         | 
| 142 | 
            +
                within_dir(app_path) do
         | 
| 143 | 
            +
                  command = "teletype add config --args=arg1 *names --test=minitest --no-color"
         | 
| 144 | 
            +
             | 
| 145 | 
            +
                  out, err, status = Open3.capture3(command)
         | 
| 146 | 
            +
             | 
| 147 | 
            +
                  expect(out).to match <<-OUT
         | 
| 148 | 
            +
                  create  test/integration/config_test.rb
         | 
| 149 | 
            +
                  create  test/unit/config_test.rb
         | 
| 150 | 
            +
                  create  lib/newcli/commands/config.rb
         | 
| 151 | 
            +
                  create  lib/newcli/templates/config/.gitkeep
         | 
| 152 | 
            +
                  inject  lib/newcli/cli.rb
         | 
| 153 | 
            +
                  OUT
         | 
| 154 | 
            +
                  expect(err).to eq('')
         | 
| 155 | 
            +
                  expect(status.exitstatus).to eq(0)
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                  expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
         | 
| 158 | 
            +
            require 'thor'
         | 
| 159 | 
            +
             | 
| 160 | 
            +
            module Newcli
         | 
| 161 | 
            +
              class CLI < Thor
         | 
| 162 | 
            +
             | 
| 163 | 
            +
                desc 'config ARG1 NAMES...', 'Command description...'
         | 
| 164 | 
            +
                method_option :help, aliases: '-h', type: :boolean,
         | 
| 165 | 
            +
                                     desc: 'Display usage information'
         | 
| 166 | 
            +
                def config(arg1, *names)
         | 
| 167 | 
            +
                  if options[:help]
         | 
| 168 | 
            +
                    invoke :help, ['config']
         | 
| 169 | 
            +
                  else
         | 
| 170 | 
            +
                    require_relative 'commands/config'
         | 
| 171 | 
            +
                    Newcli::Commands::Config.new(arg1, names, options).execute
         | 
| 172 | 
            +
                  end
         | 
| 173 | 
            +
                end
         | 
| 174 | 
            +
              end
         | 
| 175 | 
            +
            end
         | 
| 176 | 
            +
                  EOS
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                  expect(::File.read('lib/newcli/commands/config.rb')).to eq <<-EOS
         | 
| 179 | 
            +
            # frozen_string_literal: true
         | 
| 180 | 
            +
             | 
| 181 | 
            +
            require_relative '../command'
         | 
| 182 | 
            +
             | 
| 183 | 
            +
            module Newcli
         | 
| 184 | 
            +
              module Commands
         | 
| 185 | 
            +
                class Config < Newcli::Command
         | 
| 186 | 
            +
                  def initialize(arg1, names, options)
         | 
| 187 | 
            +
                    @arg1 = arg1
         | 
| 188 | 
            +
                    @names = names
         | 
| 189 | 
            +
                    @options = options
         | 
| 190 | 
            +
                  end
         | 
| 191 | 
            +
             | 
| 192 | 
            +
                  def execute(input: $stdin, output: $stdout)
         | 
| 193 | 
            +
                    # Command logic goes here ...
         | 
| 194 | 
            +
                    output.puts "OK"
         | 
| 195 | 
            +
                  end
         | 
| 196 | 
            +
                end
         | 
| 197 | 
            +
              end
         | 
| 198 | 
            +
            end
         | 
| 199 | 
            +
                  EOS
         | 
| 200 | 
            +
             | 
| 201 | 
            +
                  # test/integration/config_test.rb
         | 
| 202 | 
            +
                  #
         | 
| 203 | 
            +
                  expect(::File.read('test/integration/config_test.rb')).to eq <<-EOS
         | 
| 204 | 
            +
            require 'test_helper'
         | 
| 205 | 
            +
            require 'newcli/commands/config'
         | 
| 206 | 
            +
             | 
| 207 | 
            +
            class Newcli::Commands::ConfigTest < Minitest::Test
         | 
| 208 | 
            +
              def test_executes_newcli_help_config_command_successfully
         | 
| 209 | 
            +
                output = `newcli help config`
         | 
| 210 | 
            +
                expected_output = <<-OUT
         | 
| 211 | 
            +
            Usage:
         | 
| 212 | 
            +
              newcli config ARG1 NAMES...
         | 
| 213 | 
            +
             | 
| 214 | 
            +
            Options:
         | 
| 215 | 
            +
              -h, [--help], [--no-help]  # Display usage information
         | 
| 216 | 
            +
             | 
| 217 | 
            +
            Command description...
         | 
| 218 | 
            +
                OUT
         | 
| 219 | 
            +
             | 
| 220 | 
            +
                assert_equal expected_output, output
         | 
| 221 | 
            +
              end
         | 
| 222 | 
            +
            end
         | 
| 223 | 
            +
                  EOS
         | 
| 224 | 
            +
             | 
| 225 | 
            +
                  # test/unit/config_test.rb
         | 
| 226 | 
            +
                  #
         | 
| 227 | 
            +
                  expect(::File.read('test/unit/config_test.rb')).to eq <<-EOS
         | 
| 228 | 
            +
            require 'test_helper'
         | 
| 229 | 
            +
            require 'newcli/commands/config'
         | 
| 230 | 
            +
             | 
| 231 | 
            +
            class Newcli::Commands::ConfigTest < Minitest::Test
         | 
| 232 | 
            +
              def test_executes_config_command_successfully
         | 
| 233 | 
            +
                output = StringIO.new
         | 
| 234 | 
            +
                arg1 = nil
         | 
| 235 | 
            +
                names = nil
         | 
| 236 | 
            +
                options = {}
         | 
| 237 | 
            +
                command = Newcli::Commands::Config.new(arg1, names, options)
         | 
| 238 | 
            +
             | 
| 239 | 
            +
                command.execute(output: output)
         | 
| 240 | 
            +
             | 
| 241 | 
            +
                assert_equal "OK\\n", output.string
         | 
| 242 | 
            +
              end
         | 
| 243 | 
            +
            end
         | 
| 244 | 
            +
                  EOS
         | 
| 245 | 
            +
                end
         | 
| 246 | 
            +
              end
         | 
| 247 | 
            +
             | 
| 248 | 
            +
              it "adds subcommand with description and custom arguments" do
         | 
| 249 | 
            +
                app_path = tmp_path('newcli')
         | 
| 250 | 
            +
                cli_template = <<-EOS
         | 
| 251 | 
            +
            require 'thor'
         | 
| 252 | 
            +
             | 
| 253 | 
            +
            module Newcli
         | 
| 254 | 
            +
              class CLI < Thor
         | 
| 255 | 
            +
              end
         | 
| 256 | 
            +
            end
         | 
| 257 | 
            +
                EOS
         | 
| 258 | 
            +
                dir = {
         | 
| 259 | 
            +
                  app_path => [
         | 
| 260 | 
            +
                    'lib' => [
         | 
| 261 | 
            +
                      'newcli' => [
         | 
| 262 | 
            +
                        ['cli.rb', cli_template]
         | 
| 263 | 
            +
                      ]
         | 
| 264 | 
            +
                    ]
         | 
| 265 | 
            +
                  ]
         | 
| 266 | 
            +
                }
         | 
| 267 | 
            +
                ::TTY::File.create_dir(dir, verbose: false)
         | 
| 268 | 
            +
                within_dir(app_path) do
         | 
| 269 | 
            +
                  command = "teletype add config set --desc='Set configuration option' --args=name 'value = nil'"
         | 
| 270 | 
            +
             | 
| 271 | 
            +
                  _, err, status = Open3.capture3(command)
         | 
| 272 | 
            +
             | 
| 273 | 
            +
                  expect(err).to eq('')
         | 
| 274 | 
            +
                  expect(status.exitstatus).to eq(0)
         | 
| 275 | 
            +
             | 
| 276 | 
            +
                  expect(::File.read('lib/newcli/cli.rb')).to eq <<-EOS
         | 
| 277 | 
            +
            require 'thor'
         | 
| 278 | 
            +
             | 
| 279 | 
            +
            module Newcli
         | 
| 280 | 
            +
              class CLI < Thor
         | 
| 281 | 
            +
             | 
| 282 | 
            +
                require_relative 'commands/config'
         | 
| 283 | 
            +
                register Newcli::Commands::Config, 'config', 'config [SUBCOMMAND]', 'Set configuration option'
         | 
| 284 | 
            +
              end
         | 
| 285 | 
            +
            end
         | 
| 286 | 
            +
                  EOS
         | 
| 287 | 
            +
             | 
| 288 | 
            +
                  expect(::File.read('lib/newcli/commands/config.rb')).to eq <<-EOS
         | 
| 289 | 
            +
            # frozen_string_literal: true
         | 
| 290 | 
            +
             | 
| 291 | 
            +
            require 'thor'
         | 
| 292 | 
            +
             | 
| 293 | 
            +
            module Newcli
         | 
| 294 | 
            +
              module Commands
         | 
| 295 | 
            +
                class Config < Thor
         | 
| 296 | 
            +
             | 
| 297 | 
            +
                  namespace :config
         | 
| 298 | 
            +
             | 
| 299 | 
            +
                  desc 'set NAME [VALUE]', 'Set configuration option'
         | 
| 300 | 
            +
                  method_option :help, aliases: '-h', type: :boolean,
         | 
| 301 | 
            +
                                       desc: 'Display usage information'
         | 
| 302 | 
            +
                  def set(name, value = nil)
         | 
| 303 | 
            +
                    if options[:help]
         | 
| 304 | 
            +
                      invoke :help, ['set']
         | 
| 305 | 
            +
                    else
         | 
| 306 | 
            +
                      require_relative 'config/set'
         | 
| 307 | 
            +
                      Newcli::Commands::Config::Set.new(name, value, options).execute
         | 
| 308 | 
            +
                    end
         | 
| 309 | 
            +
                  end
         | 
| 310 | 
            +
                end
         | 
| 311 | 
            +
              end
         | 
| 312 | 
            +
            end
         | 
| 313 | 
            +
                  EOS
         | 
| 314 | 
            +
             | 
| 315 | 
            +
                  expect(::File.read('lib/newcli/commands/config/set.rb')).to eq <<-EOS
         | 
| 316 | 
            +
            # frozen_string_literal: true
         | 
| 317 | 
            +
             | 
| 318 | 
            +
            require_relative '../../command'
         | 
| 319 | 
            +
             | 
| 320 | 
            +
            module Newcli
         | 
| 321 | 
            +
              module Commands
         | 
| 322 | 
            +
                class Config
         | 
| 323 | 
            +
                  class Set < Newcli::Command
         | 
| 324 | 
            +
                    def initialize(name, value, options)
         | 
| 325 | 
            +
                      @name = name
         | 
| 326 | 
            +
                      @value = value
         | 
| 327 | 
            +
                      @options = options
         | 
| 328 | 
            +
                    end
         | 
| 329 | 
            +
             | 
| 330 | 
            +
                    def execute(input: $stdin, output: $stdout)
         | 
| 331 | 
            +
                      # Command logic goes here ...
         | 
| 332 | 
            +
                      output.puts "OK"
         | 
| 333 | 
            +
                    end
         | 
| 334 | 
            +
                  end
         | 
| 335 | 
            +
                end
         | 
| 336 | 
            +
              end
         | 
| 337 | 
            +
            end
         | 
| 338 | 
            +
                  EOS
         | 
| 339 | 
            +
                end
         | 
| 340 | 
            +
              end
         | 
| 341 | 
            +
            end
         | 
| @@ -0,0 +1,98 @@ | |
| 1 | 
            +
            RSpec.describe "`teletype add --force` command", type: :cli do
         | 
| 2 | 
            +
              it "forces adding already existing command" do
         | 
| 3 | 
            +
                app_path = tmp_path('newcli')
         | 
| 4 | 
            +
                cli_template = <<-EOS
         | 
| 5 | 
            +
            require 'thor'
         | 
| 6 | 
            +
             | 
| 7 | 
            +
            module Newcli
         | 
| 8 | 
            +
              class CLI < Thor
         | 
| 9 | 
            +
                desc 'config', 'Set and unset configuration information'
         | 
| 10 | 
            +
                method_option :help, aliases: '-h', type: :boolean,
         | 
| 11 | 
            +
                                     desc: 'Display usage information'
         | 
| 12 | 
            +
                def config(*)
         | 
| 13 | 
            +
                  if options[:help]
         | 
| 14 | 
            +
                  else
         | 
| 15 | 
            +
                    require_relative 'commands/config'
         | 
| 16 | 
            +
                    Newcli::Commands::Config.new(options).execute
         | 
| 17 | 
            +
                  end
         | 
| 18 | 
            +
                end
         | 
| 19 | 
            +
              end
         | 
| 20 | 
            +
            end
         | 
| 21 | 
            +
                EOS
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                config_template = <<-EOS
         | 
| 24 | 
            +
            require_relative '../command'
         | 
| 25 | 
            +
             | 
| 26 | 
            +
            module Newcli
         | 
| 27 | 
            +
              module Commands
         | 
| 28 | 
            +
                class Config < Newcli::Command
         | 
| 29 | 
            +
                  def initialize(options)
         | 
| 30 | 
            +
                    @options = options
         | 
| 31 | 
            +
                  end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                  def execute(input: $stdin, output: $stdout)
         | 
| 34 | 
            +
                    puts 'config command'
         | 
| 35 | 
            +
                  end
         | 
| 36 | 
            +
                end
         | 
| 37 | 
            +
              end
         | 
| 38 | 
            +
            end
         | 
| 39 | 
            +
                EOS
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                dir = {
         | 
| 42 | 
            +
                  app_path => [
         | 
| 43 | 
            +
                    'lib' => [
         | 
| 44 | 
            +
                      'newcli' => [
         | 
| 45 | 
            +
                        ['cli.rb', cli_template],
         | 
| 46 | 
            +
                        'commands' => [
         | 
| 47 | 
            +
                          ['config.rb', config_template]
         | 
| 48 | 
            +
                        ]
         | 
| 49 | 
            +
                      ]
         | 
| 50 | 
            +
                    ],
         | 
| 51 | 
            +
                    'spec' => [
         | 
| 52 | 
            +
                      'integration' => [
         | 
| 53 | 
            +
                        'config_spec.rb'
         | 
| 54 | 
            +
                      ]
         | 
| 55 | 
            +
                    ]
         | 
| 56 | 
            +
                  ]
         | 
| 57 | 
            +
                }
         | 
| 58 | 
            +
                ::TTY::File.create_dir(dir, verbose: false)
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                output = <<-OUT
         | 
| 61 | 
            +
                   force  spec/integration/config_spec.rb
         | 
| 62 | 
            +
                  create  spec/unit/config_spec.rb
         | 
| 63 | 
            +
                   force  lib/newcli/commands/config.rb
         | 
| 64 | 
            +
                  create  lib/newcli/templates/config/.gitkeep
         | 
| 65 | 
            +
                OUT
         | 
| 66 | 
            +
             | 
| 67 | 
            +
                within_dir(app_path) do
         | 
| 68 | 
            +
                  command = "teletype add config --no-color --force"
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                  out, err, status = Open3.capture3(command)
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                  expect(out).to eq(output)
         | 
| 73 | 
            +
                  expect(err).to eq('')
         | 
| 74 | 
            +
                  expect(status.exitstatus).to eq(0)
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                  expect(::File.read('lib/newcli/commands/config.rb')).to eq <<-EOS
         | 
| 77 | 
            +
            # frozen_string_literal: true
         | 
| 78 | 
            +
             | 
| 79 | 
            +
            require_relative '../command'
         | 
| 80 | 
            +
             | 
| 81 | 
            +
            module Newcli
         | 
| 82 | 
            +
              module Commands
         | 
| 83 | 
            +
                class Config < Newcli::Command
         | 
| 84 | 
            +
                  def initialize(options)
         | 
| 85 | 
            +
                    @options = options
         | 
| 86 | 
            +
                  end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
                  def execute(input: $stdin, output: $stdout)
         | 
| 89 | 
            +
                    # Command logic goes here ...
         | 
| 90 | 
            +
                    output.puts "OK"
         | 
| 91 | 
            +
                  end
         | 
| 92 | 
            +
                end
         | 
| 93 | 
            +
              end
         | 
| 94 | 
            +
            end
         | 
| 95 | 
            +
                  EOS
         | 
| 96 | 
            +
                end
         | 
| 97 | 
            +
              end
         | 
| 98 | 
            +
            end
         |