diff -Nru ruby-thor-1.0.1/CHANGELOG.md ruby-thor-1.2.1/CHANGELOG.md --- ruby-thor-1.0.1/CHANGELOG.md 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/CHANGELOG.md 1970-01-01 00:00:00.000000000 +0000 @@ -1,220 +0,0 @@ -# 1.0.1 -* Fix thor when `thor/base` and `thor/group` are required without `thor.rb`. -* Handle relative source path in `create_link`. - -# 1.0.0 -* Drop support to Ruby 1.8 and 1.9. -* Deprecate relying on default `exit_on_failure?`. - In preparation to make Thor commands exit when there is a failure we are deprecating - defining a command without defining what behavior is expected when there is a failure. - - To fix the deprecation you need to define a class method called `exit_on_failure?` returning - - `false` if you want the current behavior or `true` if you want the new behavior. -* Deprecate defining an option with the default value using a different type as defined in the option. -* Allow options to be repeatable. See #674. - -# 0.20.3 -* Support old versions of `did_you_mean`. - -# 0.20.2 -* Fix `did_you_mean` support. - -# 0.20.1 -* Support new versions of ERB. -* Fix `check_unknown_options!` to not check the content that was not parsed, i.e. after a `--` or after the first unknown with `stop_on_unknown_option!` -* Add `did_you_mean` support. - -## 0.20.0 -* Add `check_default_type!` to check if the default value of an option matches the defined type. - It removes the warning on usage and gives the command authors the possibility to check for programming errors. - -* Add `disable_required_check!` to disable check for required options in some commands. - It is a substitute of `disable_class_options` that was not working as intended. - -* Add `inject_into_module`. - -## 0.19.4, release 2016-11-28 -* Rename `Thor::Base#thor_reserved_word?` to `#is_thor_reserved_word?` - -## 0.19.3, release 2016-11-27 -* Output a warning instead of raising an exception when a default option value doesn't match its specified type - -## 0.19.2, release 2016-11-26 -* Fix bug with handling of colors passed to `ask` (and methods like `yes?` and `no?` which it underpins) -* Allow numeric arguments to be negative -* Ensure that default option values are of the specified type (e.g. you can't specify `"foo"` as the default for a numeric option), but make symbols and strings interchangeable -* Add `Thor::Shell::Basic#indent` method for intending output -* Fix `remove_command` for an inherited command (see #451) -* Allow hash arguments to only have each key provided once (see #455) -* Allow commands to disable class options, for instance for "help" commands (see #363) -* Do not generate a negative option (`--no-no-foo`) for already negative boolean options (`--no-foo`) -* Improve compatibility of `Thor::CoreExt::HashWithIndifferentAccess` with Ruby standard library `Hash` -* Allow specifying a custom binding for template evaluation (e.g. `#key?` and `#fetch`) -* Fix support for subcommand-specific "help"s -* Use a string buffer when handling ERB for Ruby 2.3 compatibility -* Update dependencies - -## 0.19.1, release 2014-03-24 -* Fix `say` non-String break regression - -## 0.19.0, release 2014-03-22 -* Add support for a default to #ask -* Avoid @namespace not initialized warning -* Avoid private attribute? warning -* Fix initializing with unknown options -* Loosen required_rubygems_version for compatibility with Ubuntu 10.04 -* Shell#ask: support a noecho option for stdin -* Shell#ask: change API to be :echo => false -* Display a message without a stack trace for ambiguous commands -* Make say and say_status thread safe -* Dependency for console io version check -* Alias --help to help on subcommands -* Use mime-types 1.x for Ruby 1.8.7 compatibility for Ruby 1.8 only -* Accept .tt files as templates -* Check if numeric value is in enum -* Use Readline for user input -* Fix dispatching of subcommands (concerning :help and *args) -* Fix warnings when running specs with `$VERBOSE = true` -* Make subcommand help more consistent -* Make the current command chain accessible in command - -## 0.18.1, release 2013-03-30 -* Revert regressions found in 0.18.0 - -## 0.18.0, release 2013-03-26 -* Remove rake2thor -* Only display colors if output medium supports colors -* Pass parent_options to subcommands -* Fix non-dash-prefixed aliases -* Make error messages more helpful -* Rename "task" to "command" -* Add the method to allow for custom package name - -## 0.17.0, release 2013-01-24 -* Add better support for tasks that accept arbitrary additional arguments (e.g. things like `bundle exec`) -* Add #stop_on_unknown_option! -* Only strip from stdin.gets if it wasn't ended with EOF -* Allow "send" as a task name -* Allow passing options as arguments after "--" -* Autoload Thor::Group - -## 0.16.0, release 2012-08-14 -* Add enum to string arguments - -## 0.15.4, release 2012-06-29 -* Fix regression when destination root contains reserved regexp characters - -## 0.15.3, release 2012-06-18 -* Support strict_args_position! for backwards compatibility -* Escape Dir glob characters in paths - -## 0.15.2, released 2012-05-07 -* Added print_in_columns -* Exposed terminal_width as a public API - -## 0.15.1, release 2012-05-06 -* Fix Ruby 1.8 truncation bug with unicode chars -* Fix shell delegate methods to pass their block -* Don't output trailing spaces when printing the last column in a table - -## 0.15, released 2012-04-29 -* Alias method_options to options -* Refactor say to allow multiple colors -* Exposed error as a public API -* Exposed file_collision as a public API -* Exposed print_wrapped as a public API -* Exposed set_color as a public API -* Fix number-formatting bugs in print_table -* Fix "indent" typo in print_table -* Fix Errno::EPIPE when piping tasks to `head` -* More friendly error messages - -## 0.14, released 2010-07-25 -* Added CreateLink class and #link_file method -* Made Thor::Actions#run use system as default method for system calls -* Allow use of private methods from superclass as tasks -* Added mute(&block) method which allows to run block without any output -* Removed config[:pretend] -* Enabled underscores for command line switches -* Added Thor::Base.basename which is used by both Thor.banner and Thor::Group.banner -* Deprecated invoke() without arguments -* Added :only and :except to check_unknown_options - -## 0.13, released 2010-02-03 -* Added :lazy_default which is only triggered if a switch is given -* Added Thor::Shell::HTML -* Added subcommands -* Decoupled Thor::Group and Thor, so it's easier to vendor -* Added check_unknown_options! in case you want error messages to be raised in valid switches -* run(command) should return the results of command - -## 0.12, released 2010-01-02 -* Methods generated by attr_* are automatically not marked as tasks -* inject_into_file does not add the same content twice, unless :force is set -* Removed rr in favor to rspec mock framework -* Improved output for thor -T -* [#7] Do not force white color on status -* [#8] Yield a block with the filename on directory - -## 0.11, released 2009-07-01 -* Added a rake compatibility layer. It allows you to use spec and rdoc tasks on - Thor classes. -* BACKWARDS INCOMPATIBLE: aliases are not generated automatically anymore - since it may cause wrong behavior in the invocation system. -* thor help now show information about any class/task. All those calls are - possible: - - thor help describe - thor help describe:amazing - Or even with default namespaces: - - thor help :spec -* Thor::Runner now invokes the default task if none is supplied: - - thor describe # invokes the default task, usually help -* Thor::Runner now works with mappings: - - thor describe -h -* Added some documentation and code refactoring. - -## 0.9.8, released 2008-10-20 -* Fixed some tiny issues that were introduced lately. - -## 0.9.7, released 2008-10-13 -* Setting global method options on the initialize method works as expected: - All other tasks will accept these global options in addition to their own. -* Added 'group' notion to Thor task sets (class Thor); by default all tasks - are in the 'standard' group. Running 'thor -T' will only show the standard - tasks - adding --all will show all tasks. You can also filter on a specific - group using the --group option: thor -T --group advanced - -## 0.9.6, released 2008-09-13 -* Generic improvements - -## 0.9.5, released 2008-08-27 -* Improve Windows compatibility -* Update (incorrect) README and task.thor sample file -* Options hash is now frozen (once returned) -* Allow magic predicates on options object. For instance: `options.force?` -* Add support for :numeric type -* BACKWARDS INCOMPATIBLE: Refactor Thor::Options. You cannot access shorthand forms in options hash anymore (for instance, options[:f]) -* Allow specifying optional args with default values: method_options(:user => "mislav") -* Don't write options for nil or false values. This allows, for example, turning color off when running specs. -* Exit with the status of the spec command to help CI stuff out some. - -## 0.9.4, released 2008-08-13 -* Try to add Windows compatibility. -* BACKWARDS INCOMPATIBLE: options hash is now accessed as a property in your class and is not passed as last argument anymore -* Allow options at the beginning of the argument list as well as the end. -* Make options available with symbol keys in addition to string keys. -* Allow true to be passed to Thor#method_options to denote a boolean option. -* If loading a thor file fails, don't give up, just print a warning and keep going. -* Make sure that we re-raise errors if they happened further down the pipe than we care about. -* Only delete the old file on updating when the installation of the new one is a success -* Make it Ruby 1.8.5 compatible. -* Don't raise an error if a boolean switch is defined multiple times. -* Thor::Options now doesn't parse through things that look like options but aren't. -* Add URI detection to install task, and make sure we don't append ".thor" to URIs -* Add rake2thor to the gem binfiles. -* Make sure local Thorfiles override system-wide ones. diff -Nru ruby-thor-1.0.1/debian/changelog ruby-thor-1.2.1/debian/changelog --- ruby-thor-1.0.1/debian/changelog 2021-01-19 21:22:47.000000000 +0000 +++ ruby-thor-1.2.1/debian/changelog 2022-03-09 08:27:42.000000000 +0000 @@ -1,3 +1,14 @@ +ruby-thor (1.2.1-1) unstable; urgency=medium + + * New upstream release: 1.2.1 + * Refresh debian/patches/exclude-git-test.patch + * Bump Standards-Version to 4.6.0. No changes needed. + * Change Depends to dh-make-ruby's defaults + * Refresh debian/patches/0002-Disable-tests-that-depend-on-readline-as- + ruby-rb-rea.patch + + -- Lucas Nussbaum Wed, 09 Mar 2022 09:27:42 +0100 + ruby-thor (1.0.1-1) unstable; urgency=medium [ Cédric Boutillier ] diff -Nru ruby-thor-1.0.1/debian/control ruby-thor-1.2.1/debian/control --- ruby-thor-1.0.1/debian/control 2021-01-19 21:22:47.000000000 +0000 +++ ruby-thor-1.2.1/debian/control 2022-03-08 21:25:44.000000000 +0000 @@ -10,10 +10,10 @@ ruby-coveralls, ruby-diff-lcs, ruby-fakeweb, - ruby-rspec (>= 2.13.0~), + ruby-rspec, ruby-simplecov, ruby-webmock -Standards-Version: 4.5.1 +Standards-Version: 4.6.0 Vcs-Git: https://salsa.debian.org/ruby-team/ruby-thor.git Vcs-Browser: https://salsa.debian.org/ruby-team/ruby-thor Homepage: http://whatisthor.com/ @@ -24,8 +24,8 @@ Package: ruby-thor Architecture: all XB-Ruby-Versions: ${ruby:Versions} -Depends: ruby | ruby-interpreter, - ${misc:Depends}, +Depends: ${misc:Depends}, + ${ruby:Depends}, ${shlibs:Depends} Breaks: ruby-coveralls (<< 0.8.23-1~) Description: Ruby scripting framework diff -Nru ruby-thor-1.0.1/debian/patches/0002-Disable-tests-that-depend-on-readline-as-ruby-rb-rea.patch ruby-thor-1.2.1/debian/patches/0002-Disable-tests-that-depend-on-readline-as-ruby-rb-rea.patch --- ruby-thor-1.0.1/debian/patches/0002-Disable-tests-that-depend-on-readline-as-ruby-rb-rea.patch 2021-01-19 21:22:47.000000000 +0000 +++ ruby-thor-1.2.1/debian/patches/0002-Disable-tests-that-depend-on-readline-as-ruby-rb-rea.patch 2022-03-08 21:39:40.000000000 +0000 @@ -8,16 +8,15 @@ 1 file changed, 69 deletions(-) delete mode 100644 spec/line_editor/readline_spec.rb -diff --git a/spec/line_editor/readline_spec.rb b/spec/line_editor/readline_spec.rb -deleted file mode 100644 -index 86cf746..0000000 --- a/spec/line_editor/readline_spec.rb +++ /dev/null -@@ -1,69 +0,0 @@ +@@ -1,71 +0,0 @@ -require "helper" - -describe Thor::LineEditor::Readline do - before do +- # Eagerly check Readline availability before mocking +- Thor::LineEditor::Readline.available? - unless defined? ::Readline - ::Readline = double("Readline") - allow(::Readline).to receive(:completion_append_character=).with(nil) diff -Nru ruby-thor-1.0.1/debian/patches/exclude-git-test.patch ruby-thor-1.2.1/debian/patches/exclude-git-test.patch --- ruby-thor-1.0.1/debian/patches/exclude-git-test.patch 2021-01-19 21:22:47.000000000 +0000 +++ ruby-thor-1.2.1/debian/patches/exclude-git-test.patch 2022-03-08 21:35:12.000000000 +0000 @@ -7,8 +7,6 @@ spec/quality_spec.rb | 2 ++ 1 file changed, 2 insertions(+) -diff --git a/spec/quality_spec.rb b/spec/quality_spec.rb -index 99efb62..3942a0c 100644 --- a/spec/quality_spec.rb +++ b/spec/quality_spec.rb @@ -36,6 +36,7 @@ describe "The library itself" do @@ -17,7 +15,7 @@ +=begin it "has no malformed whitespace" do - exempt = /\.gitmodules|\.marshal|fixtures|vendor|spec|ssl_certs|LICENSE/ + exempt = /\.gitmodules|\.marshal|fixtures|vendor|spec|ssl_certs|LICENSE|.devcontainer/ error_messages = [] @@ -60,4 +61,5 @@ describe "The library itself" do end diff -Nru ruby-thor-1.0.1/debian/salsa-ci.yml ruby-thor-1.2.1/debian/salsa-ci.yml --- ruby-thor-1.0.1/debian/salsa-ci.yml 1970-01-01 00:00:00.000000000 +0000 +++ ruby-thor-1.2.1/debian/salsa-ci.yml 2022-03-08 21:23:32.000000000 +0000 @@ -0,0 +1,4 @@ +--- +include: + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/salsa-ci.yml + - https://salsa.debian.org/salsa-ci-team/pipeline/raw/master/pipeline-jobs.yml diff -Nru ruby-thor-1.0.1/.devcontainer/base.Dockerfile ruby-thor-1.2.1/.devcontainer/base.Dockerfile --- ruby-thor-1.0.1/.devcontainer/base.Dockerfile 1970-01-01 00:00:00.000000000 +0000 +++ ruby-thor-1.2.1/.devcontainer/base.Dockerfile 2022-01-04 23:17:23.000000000 +0000 @@ -0,0 +1,43 @@ +# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster +ARG VARIANT=2-bullseye +FROM ruby:${VARIANT} + +# Copy library scripts to execute +COPY library-scripts/*.sh library-scripts/*.env /tmp/library-scripts/ + +# [Option] Install zsh +ARG INSTALL_ZSH="true" +# [Option] Upgrade OS packages to their latest versions +ARG UPGRADE_PACKAGES="true" +# Install needed packages and setup non-root user. Use a separate RUN statement to add your own dependencies. +ARG USERNAME=vscode +ARG USER_UID=1000 +ARG USER_GID=$USER_UID +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131 + && apt-get purge -y imagemagick imagemagick-6-common \ + # Install common packages, non-root user, rvm, core build tools + && bash /tmp/library-scripts/common-debian.sh "${INSTALL_ZSH}" "${USERNAME}" "${USER_UID}" "${USER_GID}" "${UPGRADE_PACKAGES}" "true" "true" \ + && bash /tmp/library-scripts/ruby-debian.sh "none" "${USERNAME}" "true" "true" \ + && apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/* + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +ENV NVM_DIR=/usr/local/share/nvm +ENV NVM_SYMLINK_CURRENT=true \ + PATH=${NVM_DIR}/current/bin:${PATH} +RUN bash /tmp/library-scripts/node-debian.sh "${NVM_DIR}" "${NODE_VERSION}" "${USERNAME}" \ + && apt-get clean -y && rm -rf /var/lib/apt/lists/* + + # Remove library scripts for final image +RUN rm -rf /tmp/library-scripts + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install additional gems. +# RUN gem install + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff -Nru ruby-thor-1.0.1/.devcontainer/devcontainer.json ruby-thor-1.2.1/.devcontainer/devcontainer.json --- ruby-thor-1.0.1/.devcontainer/devcontainer.json 1970-01-01 00:00:00.000000000 +0000 +++ ruby-thor-1.2.1/.devcontainer/devcontainer.json 2022-01-04 23:17:23.000000000 +0000 @@ -0,0 +1,37 @@ +// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: +// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/ruby +{ + "name": "Ruby", + "build": { + "dockerfile": "Dockerfile", + "args": { + // Update 'VARIANT' to pick a Ruby version: 3, 3.0, 2, 2.7, 2.6 + // Append -bullseye or -buster to pin to an OS version. + // Use -bullseye variants on local on arm64/Apple Silicon. + "VARIANT": "3-bullseye", + // Options + "NODE_VERSION": "lts/*" + } + }, + + // Set *default* container specific settings.json values on container create. + "settings": {}, + + // Add the IDs of extensions you want installed when the container is created. + "extensions": [ + "rebornix.Ruby" + ], + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "ruby --version", + + // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode", + "features": { + "github-cli": "latest" + } + +} diff -Nru ruby-thor-1.0.1/.devcontainer/Dockerfile ruby-thor-1.2.1/.devcontainer/Dockerfile --- ruby-thor-1.0.1/.devcontainer/Dockerfile 1970-01-01 00:00:00.000000000 +0000 +++ ruby-thor-1.2.1/.devcontainer/Dockerfile 2022-01-04 23:17:23.000000000 +0000 @@ -0,0 +1,17 @@ +# [Choice] Ruby version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.0, 2, 2.7, 2.6, 3-bullseye, 3.0-bullseye, 2-bullseye, 2.7-bullseye, 2.6-bullseye, 3-buster, 3.0-buster, 2-buster, 2.7-buster, 2.6-buster +ARG VARIANT=2-bullseye +FROM mcr.microsoft.com/vscode/devcontainers/ruby:0-${VARIANT} + +# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 +ARG NODE_VERSION="none" +RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi + +# [Optional] Uncomment this section to install additional OS packages. +# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ +# && apt-get -y install --no-install-recommends + +# [Optional] Uncomment this line to install additional gems. +# RUN gem install + +# [Optional] Uncomment this line to install global node packages. +# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g " 2>&1 \ No newline at end of file diff -Nru ruby-thor-1.0.1/Gemfile ruby-thor-1.2.1/Gemfile --- ruby-thor-1.0.1/Gemfile 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/Gemfile 2022-01-04 23:17:23.000000000 +0000 @@ -10,13 +10,11 @@ group :test do gem "childlabor" gem "coveralls", ">= 0.8.19" - gem "rspec", ">= 3" + gem "rspec", ">= 3.2" gem "rspec-mocks", ">= 3" - gem "rubocop", ">= 0.19" + gem "rubocop", "~> 0.50.0" gem "simplecov", ">= 0.13" gem "webmock" end -gem 'did_you_mean' - gemspec diff -Nru ruby-thor-1.0.1/.github/workflows/tests.yml ruby-thor-1.2.1/.github/workflows/tests.yml --- ruby-thor-1.0.1/.github/workflows/tests.yml 1970-01-01 00:00:00.000000000 +0000 +++ ruby-thor-1.2.1/.github/workflows/tests.yml 2022-01-04 23:17:23.000000000 +0000 @@ -0,0 +1,16 @@ +name: Run tests +on: [push, pull_request] +jobs: + test: + strategy: + fail-fast: false + matrix: + ruby: [2.0, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6, 2.7, 3.0, 3.1, head] + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true # runs 'bundle install' and caches installed gems automatically + - run: bundle exec thor spec diff -Nru ruby-thor-1.0.1/lib/thor/actions/file_manipulation.rb ruby-thor-1.2.1/lib/thor/actions/file_manipulation.rb --- ruby-thor-1.0.1/lib/thor/actions/file_manipulation.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/actions/file_manipulation.rb 2022-01-04 23:17:23.000000000 +0000 @@ -210,9 +210,9 @@ # # ==== Examples # - # inject_into_class "app/controllers/application_controller.rb", ApplicationController, " filter_parameter :password\n" + # inject_into_class "app/controllers/application_controller.rb", "ApplicationController", " filter_parameter :password\n" # - # inject_into_class "app/controllers/application_controller.rb", ApplicationController do + # inject_into_class "app/controllers/application_controller.rb", "ApplicationController" do # " filter_parameter :password\n" # end # @@ -233,9 +233,9 @@ # # ==== Examples # - # inject_into_module "app/helpers/application_helper.rb", ApplicationHelper, " def help; 'help'; end\n" + # inject_into_module "app/helpers/application_helper.rb", "ApplicationHelper", " def help; 'help'; end\n" # - # inject_into_module "app/helpers/application_helper.rb", ApplicationHelper do + # inject_into_module "app/helpers/application_helper.rb", "ApplicationHelper" do # " def help; 'help'; end\n" # end # @@ -251,7 +251,8 @@ # path:: path of the file to be changed # flag:: the regexp or string to be replaced # replacement:: the replacement, can be also given as a block - # config:: give :verbose => false to not log the status. + # config:: give :verbose => false to not log the status, and + # :force => true, to force the replacement regardles of runner behavior. # # ==== Example # @@ -262,9 +263,10 @@ # end # def gsub_file(path, flag, *args, &block) - return unless behavior == :invoke config = args.last.is_a?(Hash) ? args.pop : {} + return unless behavior == :invoke || config.fetch(:force, false) + path = File.expand_path(path, destination_root) say_status :gsub, relative_to_original_destination_root(path), config.fetch(:verbose, true) @@ -329,7 +331,7 @@ path = File.expand_path(path, destination_root) say_status :remove, relative_to_original_destination_root(path), config.fetch(:verbose, true) - if !options[:pretend] && File.exist?(path) + if !options[:pretend] && (File.exist?(path) || File.symlink?(path)) require "fileutils" ::FileUtils.rm_rf(path) end diff -Nru ruby-thor-1.0.1/lib/thor/actions/inject_into_file.rb ruby-thor-1.2.1/lib/thor/actions/inject_into_file.rb --- ruby-thor-1.0.1/lib/thor/actions/inject_into_file.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/actions/inject_into_file.rb 2022-01-04 23:17:23.000000000 +0000 @@ -106,12 +106,11 @@ # Adds the content to the file. # def replace!(regexp, string, force) - return if pretend? content = File.read(destination) if force || !content.include?(replacement) success = content.gsub!(regexp, string) - File.open(destination, "wb") { |file| file.write(content) } + File.open(destination, "wb") { |file| file.write(content) } unless pretend? success end end diff -Nru ruby-thor-1.0.1/lib/thor/actions.rb ruby-thor-1.2.1/lib/thor/actions.rb --- ruby-thor-1.0.1/lib/thor/actions.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/actions.rb 2022-01-04 23:17:23.000000000 +0000 @@ -161,6 +161,8 @@ # to the block you provide. The path is set back to the previous path when # the method exits. # + # Returns the value yielded by the block. + # # ==== Parameters # dir:: the directory to move to. # config:: give :verbose => true to log and use padding. @@ -179,16 +181,18 @@ FileUtils.mkdir_p(destination_root) end + result = nil if pretend # In pretend mode, just yield down to the block - block.arity == 1 ? yield(destination_root) : yield + result = block.arity == 1 ? yield(destination_root) : yield else require "fileutils" - FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield } + FileUtils.cd(destination_root) { result = block.arity == 1 ? yield(destination_root) : yield } end @destination_stack.pop shell.padding -= 1 if verbose + result end # Goes to the root and execute the given block. @@ -219,7 +223,7 @@ contents = if is_uri require "open-uri" - open(path, "Accept" => "application/x-thor-template", &:read) + URI.open(path, "Accept" => "application/x-thor-template", &:read) else open(path, &:read) end diff -Nru ruby-thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb ruby-thor-1.2.1/lib/thor/core_ext/hash_with_indifferent_access.rb --- ruby-thor-1.0.1/lib/thor/core_ext/hash_with_indifferent_access.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/core_ext/hash_with_indifferent_access.rb 2022-01-04 23:17:23.000000000 +0000 @@ -28,6 +28,12 @@ super(convert_key(key)) end + def except(*keys) + dup.tap do |hash| + keys.each { |key| hash.delete(convert_key(key)) } + end + end + def fetch(key, *args) super(convert_key(key), *args) end diff -Nru ruby-thor-1.0.1/lib/thor/error.rb ruby-thor-1.2.1/lib/thor/error.rb --- ruby-thor-1.0.1/lib/thor/error.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/error.rb 2022-01-04 23:17:23.000000000 +0000 @@ -1,5 +1,5 @@ class Thor - Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) + Correctable = if defined?(DidYouMean::SpellChecker) && defined?(DidYouMean::Correctable) # rubocop:disable Naming/ConstantName # In order to support versions of Ruby that don't have keyword # arguments, we need our own spell checker class that doesn't take key # words. Even though this code wouldn't be hit because of the check @@ -102,9 +102,14 @@ end if Correctable - DidYouMean::SPELL_CHECKERS.merge!( - 'Thor::UndefinedCommandError' => UndefinedCommandError::SpellChecker, - 'Thor::UnknownArgumentError' => UnknownArgumentError::SpellChecker - ) + if DidYouMean.respond_to?(:correct_error) + DidYouMean.correct_error(Thor::UndefinedCommandError, UndefinedCommandError::SpellChecker) + DidYouMean.correct_error(Thor::UnknownArgumentError, UnknownArgumentError::SpellChecker) + else + DidYouMean::SPELL_CHECKERS.merge!( + 'Thor::UndefinedCommandError' => UndefinedCommandError::SpellChecker, + 'Thor::UnknownArgumentError' => UnknownArgumentError::SpellChecker + ) + end end end diff -Nru ruby-thor-1.0.1/lib/thor/parser/arguments.rb ruby-thor-1.2.1/lib/thor/parser/arguments.rb --- ruby-thor-1.0.1/lib/thor/parser/arguments.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/parser/arguments.rb 2022-01-04 23:17:23.000000000 +0000 @@ -30,7 +30,11 @@ arguments.each do |argument| if !argument.default.nil? - @assigns[argument.human_name] = argument.default + begin + @assigns[argument.human_name] = argument.default.dup + rescue TypeError # Compatibility shim for un-dup-able Fixnum in Ruby < 2.4 + @assigns[argument.human_name] = argument.default + end elsif argument.required? @non_assigned_required << argument end diff -Nru ruby-thor-1.0.1/lib/thor/parser/options.rb ruby-thor-1.2.1/lib/thor/parser/options.rb --- ruby-thor-1.0.1/lib/thor/parser/options.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/parser/options.rb 2022-01-04 23:17:23.000000000 +0000 @@ -45,6 +45,7 @@ @switches = {} @extra = [] @stopped_parsing_after_extra_index = nil + @is_treated_as_value = false options.each do |option| @switches[option.switch_name] = option @@ -74,8 +75,19 @@ end end + def shift + @is_treated_as_value = false + super + end + + def unshift(arg, is_value: false) + @is_treated_as_value = is_value + super(arg) + end + def parse(args) # rubocop:disable MethodLength @pile = args.dup + @is_treated_as_value = false @parsing_options = true while peek @@ -88,7 +100,10 @@ when SHORT_SQ_RE unshift($1.split("").map { |f| "-#{f}" }) next - when EQ_RE, SHORT_NUM + when EQ_RE + unshift($2, is_value: true) + switch = $1 + when SHORT_NUM unshift($2) switch = $1 when LONG_RE, SHORT_RE @@ -133,20 +148,22 @@ protected - def assign_result!(option, result) - if option.repeatable && option.type == :hash - (@assigns[option.human_name] ||= {}).merge!(result) - elsif option.repeatable - (@assigns[option.human_name] ||= []) << result - else - @assigns[option.human_name] = result + def assign_result!(option, result) + if option.repeatable && option.type == :hash + (@assigns[option.human_name] ||= {}).merge!(result) + elsif option.repeatable + (@assigns[option.human_name] ||= []) << result + else + @assigns[option.human_name] = result + end end - end + # Check if the current value in peek is a registered switch. # # Two booleans are returned. The first is true if the current value # starts with a hyphen; the second is true if it is a registered switch. def current_is_switch? + return [false, false] if @is_treated_as_value case peek when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM [true, switch?($1)] @@ -158,6 +175,7 @@ end def current_is_switch_formatted? + return false if @is_treated_as_value case peek when LONG_RE, SHORT_RE, EQ_RE, SHORT_NUM, SHORT_SQ_RE true @@ -167,6 +185,7 @@ end def current_is_value? + return true if @is_treated_as_value peek && (!parsing_options? || super) end diff -Nru ruby-thor-1.0.1/lib/thor/shell/basic.rb ruby-thor-1.2.1/lib/thor/shell/basic.rb --- ruby-thor-1.0.1/lib/thor/shell/basic.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/lib/thor/shell/basic.rb 2022-01-04 23:17:23.000000000 +0000 @@ -94,6 +94,8 @@ # say("I know you knew that.") # def say(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) + return if quiet? + buffer = prepare_message(message, *color) buffer << "\n" if force_new_line && !message.to_s.end_with?("\n") @@ -101,6 +103,23 @@ stdout.flush end + # Say (print) an error to the user. If the sentence ends with a whitespace + # or tab character, a new line is not appended (print + flush). Otherwise + # are passed straight to puts (behavior got from Highline). + # + # ==== Example + # say_error("error: something went wrong") + # + def say_error(message = "", color = nil, force_new_line = (message.to_s !~ /( |\t)\Z/)) + return if quiet? + + buffer = prepare_message(message, *color) + buffer << "\n" if force_new_line && !message.to_s.end_with?("\n") + + stderr.print(buffer) + stderr.flush + end + # Say a status with the given color and appends the message. Since this # method is used frequently by actions, it allows nil or false to be given # in log_status, avoiding the message from being shown. If a Symbol is @@ -109,13 +128,14 @@ def say_status(status, message, log_status = true) return if quiet? || log_status == false spaces = " " * (padding + 1) - color = log_status.is_a?(Symbol) ? log_status : :green - status = status.to_s.rjust(12) + margin = " " * status.length + spaces + + color = log_status.is_a?(Symbol) ? log_status : :green status = set_color status, color, true if color - buffer = "#{status}#{spaces}#{message}" - buffer = "#{buffer}\n" unless buffer.end_with?("\n") + message = message.to_s.chomp.gsub(/(? destination_root) + def runner(options = {}, behavior = :invoke) + @runner ||= MyCounter.new([1], options, :destination_root => destination_root, :behavior => behavior) end def action(*args, &block) @@ -259,6 +256,13 @@ expect(File.exist?(file)).to be false end + it "removes broken symlinks too" do + link_path = File.join(destination_root, "broken_symlink") + ::FileUtils.ln_s("invalid_reference", link_path) + action :remove_file, "broken_symlink" + expect(File.symlink?(link_path) || File.exist?(link_path)).to be false + end + it "removes directories too" do action :remove_dir, "doc" expect(File.exist?(File.join(destination_root, "doc"))).to be false @@ -280,28 +284,92 @@ end describe "#gsub_file" do - it "replaces the content in the file" do - action :gsub_file, "doc/README", "__start__", "START" - expect(File.binread(file)).to eq("START\nREADME\n__end__\n") - end - - it "does not replace if pretending" do - runner(:pretend => true) - action :gsub_file, "doc/README", "__start__", "START" - expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") - end - - it "accepts a block" do - action(:gsub_file, "doc/README", "__start__") { |match| match.gsub("__", "").upcase } - expect(File.binread(file)).to eq("START\nREADME\n__end__\n") - end - - it "logs status" do - expect(action(:gsub_file, "doc/README", "__start__", "START")).to eq(" gsub doc/README\n") - end - - it "does not log status if required" do - expect(action(:gsub_file, file, "__", :verbose => false) { |match| match * 2 }).to be_empty + context "with invoke behavior" do + it "replaces the content in the file" do + action :gsub_file, "doc/README", "__start__", "START" + expect(File.binread(file)).to eq("START\nREADME\n__end__\n") + end + + it "does not replace if pretending" do + runner(:pretend => true) + action :gsub_file, "doc/README", "__start__", "START" + expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") + end + + it "accepts a block" do + action(:gsub_file, "doc/README", "__start__") { |match| match.gsub("__", "").upcase } + expect(File.binread(file)).to eq("START\nREADME\n__end__\n") + end + + it "logs status" do + expect(action(:gsub_file, "doc/README", "__start__", "START")).to eq(" gsub doc/README\n") + end + + it "does not log status if required" do + expect(action(:gsub_file, file, "__", :verbose => false) { |match| match * 2 }).to be_empty + end + end + + context "with revoke behavior" do + context "and no force option" do + it "does not replace the content in the file" do + runner({}, :revoke) + action :gsub_file, "doc/README", "__start__", "START" + expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") + end + + it "does not replace if pretending" do + runner({ :pretend => true }, :revoke) + action :gsub_file, "doc/README", "__start__", "START" + expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") + end + + it "does not replace the content in the file when given a block" do + runner({}, :revoke) + action(:gsub_file, "doc/README", "__start__") { |match| match.gsub("__", "").upcase } + expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") + end + + it "does not log status" do + runner({}, :revoke) + expect(action(:gsub_file, "doc/README", "__start__", "START")).to be_empty + end + + it "does not log status if required" do + runner({}, :revoke) + expect(action(:gsub_file, file, "__", :verbose => false) { |match| match * 2 }).to be_empty + end + end + + context "and force option" do + it "replaces the content in the file" do + runner({}, :revoke) + action :gsub_file, "doc/README", "__start__", "START", :force => true + expect(File.binread(file)).to eq("START\nREADME\n__end__\n") + end + + it "does not replace if pretending" do + runner({ :pretend => true }, :revoke) + action :gsub_file, "doc/README", "__start__", "START", :force => true + expect(File.binread(file)).to eq("__start__\nREADME\n__end__\n") + end + + it "replaces the content in the file when given a block" do + runner({}, :revoke) + action(:gsub_file, "doc/README", "__start__", :force => true) { |match| match.gsub("__", "").upcase } + expect(File.binread(file)).to eq("START\nREADME\n__end__\n") + end + + it "logs status" do + runner({}, :revoke) + expect(action(:gsub_file, "doc/README", "__start__", "START", :force => true)).to eq(" gsub doc/README\n") + end + + it "does not log status if required" do + runner({}, :revoke) + expect(action(:gsub_file, file, "__", :verbose => false, :force => true) { |match| match * 2 }).to be_empty + end + end end end @@ -343,17 +411,17 @@ end it "appends content to a class" do - action :inject_into_class, "application.rb", Application, " filter_parameters :password\n" + action :inject_into_class, "application.rb", "Application", " filter_parameters :password\n" expect(File.binread(file)).to eq("class Application < Base\n filter_parameters :password\nend\n") end it "accepts a block" do - action(:inject_into_class, "application.rb", Application) { " filter_parameters :password\n" } + action(:inject_into_class, "application.rb", "Application") { " filter_parameters :password\n" } expect(File.binread(file)).to eq("class Application < Base\n filter_parameters :password\nend\n") end it "logs status" do - expect(action(:inject_into_class, "application.rb", Application, " filter_parameters :password\n")).to eq(" insert application.rb\n") + expect(action(:inject_into_class, "application.rb", "Application", " filter_parameters :password\n")).to eq(" insert application.rb\n") end it "does not append if class name does not match" do @@ -368,17 +436,17 @@ end it "appends content to a module" do - action :inject_into_module, "application_helper.rb", ApplicationHelper, " def help; 'help'; end\n" + action :inject_into_module, "application_helper.rb", "ApplicationHelper", " def help; 'help'; end\n" expect(File.binread(file)).to eq("module ApplicationHelper\n def help; 'help'; end\nend\n") end it "accepts a block" do - action(:inject_into_module, "application_helper.rb", ApplicationHelper) { " def help; 'help'; end\n" } + action(:inject_into_module, "application_helper.rb", "ApplicationHelper") { " def help; 'help'; end\n" } expect(File.binread(file)).to eq("module ApplicationHelper\n def help; 'help'; end\nend\n") end it "logs status" do - expect(action(:inject_into_module, "application_helper.rb", ApplicationHelper, " def help; 'help'; end\n")).to eq(" insert application_helper.rb\n") + expect(action(:inject_into_module, "application_helper.rb", "ApplicationHelper", " def help; 'help'; end\n")).to eq(" insert application_helper.rb\n") end it "does not append if module name does not match" do diff -Nru ruby-thor-1.0.1/spec/actions/inject_into_file_spec.rb ruby-thor-1.2.1/spec/actions/inject_into_file_spec.rb --- ruby-thor-1.0.1/spec/actions/inject_into_file_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/actions/inject_into_file_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -62,6 +62,11 @@ expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n") end + it "logs status if pretending" do + invoker(:pretend => true) + expect(invoke!("doc/README", "\nmore content", :after => "__start__")).to eq(" insert doc/README\n") + end + it "does not change the file if pretending" do invoker :pretend => true invoke! "doc/README", "\nmore content", :after => "__start__" @@ -79,6 +84,34 @@ "more content\n" end + expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") + end + + it "does not change the file if already includes content using before with capture" do + invoke! "doc/README", :before => /(__end__)/ do + "more content\n" + end + + expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") + + invoke! "doc/README", :before => /(__end__)/ do + "more content\n" + end + + expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") + end + + it "does not change the file if already includes content using after with capture" do + invoke! "doc/README", :after => /(README\n)/ do + "more content\n" + end + + expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") + + invoke! "doc/README", :after => /(README\n)/ do + "more content\n" + end + expect(File.read(file)).to eq("__start__\nREADME\nmore content\n__end__\n") end diff -Nru ruby-thor-1.0.1/spec/actions_spec.rb ruby-thor-1.2.1/spec/actions_spec.rb --- ruby-thor-1.0.1/spec/actions_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/actions_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -165,11 +165,19 @@ end end + it "returns the value yielded by the block" do + expect(runner.inside("foo") { 123 }).to eq(123) + end + describe "when pretending" do it "no directories should be created" do runner.inside("bar", :pretend => true) {} expect(File.exist?("bar")).to be false end + + it "returns the value yielded by the block" do + expect(runner.inside("foo") { 123 }).to eq(123) + end end describe "when verbose" do @@ -231,13 +239,17 @@ it "accepts a URL as the path" do @file = "http://gist.github.com/103208.txt" - expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template) + stub_request(:get, @file) + + expect(runner).to receive(:apply).with(@file).and_return(@template) action(:apply, @file) end it "accepts a secure URL as the path" do @file = "https://gist.github.com/103208.txt" - expect(runner).to receive(:open).with(@file, "Accept" => "application/x-thor-template").and_return(@template) + stub_request(:get, @file) + + expect(runner).to receive(:apply).with(@file).and_return(@template) action(:apply, @file) end diff -Nru ruby-thor-1.0.1/spec/core_ext/hash_with_indifferent_access_spec.rb ruby-thor-1.2.1/spec/core_ext/hash_with_indifferent_access_spec.rb --- ruby-thor-1.0.1/spec/core_ext/hash_with_indifferent_access_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/core_ext/hash_with_indifferent_access_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -14,6 +14,17 @@ expect(@hash.delete(:foo)).to eq("bar") end + it "supports except" do + unexcepted_hash = @hash.dup + @hash.except("foo") + expect(@hash).to eq(unexcepted_hash) + + expect(@hash.except("foo")).to eq("baz" => "bee", "force" => true) + expect(@hash.except("foo", "baz")).to eq("force" => true) + expect(@hash.except(:foo)).to eq("baz" => "bee", "force" => true) + expect(@hash.except(:foo, :baz)).to eq("force" => true) + end + it "supports fetch" do expect(@hash.fetch("foo")).to eq("bar") expect(@hash.fetch("foo", nil)).to eq("bar") diff -Nru ruby-thor-1.0.1/spec/fixtures/verbose.thor ruby-thor-1.2.1/spec/fixtures/verbose.thor --- ruby-thor-1.0.1/spec/fixtures/verbose.thor 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/fixtures/verbose.thor 2022-01-04 23:17:23.000000000 +0000 @@ -5,6 +5,9 @@ require 'thor' class Test < Thor + def self.exit_on_failure? + true + end end Test.start(ARGV) diff -Nru ruby-thor-1.0.1/spec/line_editor/readline_spec.rb ruby-thor-1.2.1/spec/line_editor/readline_spec.rb --- ruby-thor-1.0.1/spec/line_editor/readline_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/line_editor/readline_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -2,6 +2,8 @@ describe Thor::LineEditor::Readline do before do + # Eagerly check Readline availability before mocking + Thor::LineEditor::Readline.available? unless defined? ::Readline ::Readline = double("Readline") allow(::Readline).to receive(:completion_append_character=).with(nil) diff -Nru ruby-thor-1.0.1/spec/nested_context_spec.rb ruby-thor-1.2.1/spec/nested_context_spec.rb --- ruby-thor-1.0.1/spec/nested_context_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/nested_context_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -2,7 +2,7 @@ describe Thor::NestedContext do subject(:context) { described_class.new } - + describe "#enter" do it "is never empty within the entered block" do context.enter do @@ -17,4 +17,4 @@ expect(context).not_to be_entered end end -end \ No newline at end of file +end diff -Nru ruby-thor-1.0.1/spec/no_warnings_spec.rb ruby-thor-1.2.1/spec/no_warnings_spec.rb --- ruby-thor-1.0.1/spec/no_warnings_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/no_warnings_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -3,8 +3,14 @@ context "when $VERBOSE is enabled" do it "prints no warnings" do root = File.expand_path("..", __dir__) - _, err, _ = Open3.capture3("ruby -I #{root}/lib #{root}/spec/fixtures/verbose.thor") + _, err, = Open3.capture3("ruby -I #{root}/lib #{root}/spec/fixtures/verbose.thor") expect(err).to be_empty end + + it "prints no warnings even when erroring" do + root = File.expand_path("..", __dir__) + _, err, = Open3.capture3("ruby -I #{root}/lib #{root}/spec/fixtures/verbose.thor noop") + expect(err).to_not match(/warning:/) + end end diff -Nru ruby-thor-1.0.1/spec/parser/options_spec.rb ruby-thor-1.2.1/spec/parser/options_spec.rb --- ruby-thor-1.0.1/spec/parser/options_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/parser/options_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -263,6 +263,8 @@ expect(parse("-f=12")["foo"]).to eq("12") expect(parse("--foo=12")["foo"]).to eq("12") expect(parse("--foo=bar=baz")["foo"]).to eq("bar=baz") + expect(parse("--foo=-bar")["foo"]).to eq("-bar") + expect(parse("--foo=-bar -baz")["foo"]).to eq("-bar -baz") end it "must accept underscores switch=value assignment" do @@ -302,11 +304,10 @@ "Expected '--fruit' to be one of #{enum.join(', ')}; got orange") end - it "allows multiple values if repeatable is specified" do - create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true) - + it "does not erroneously mutate defaults" do + create :foo => Thor::Option.new("foo", :type => :string, :repeatable => true, :required => false, :default => []) expect(parse("--foo=bar", "--foo", "12")["foo"]).to eq(["bar", "12"]) - expect(parse("--foo", "13", "--foo", "14")["foo"]).to eq(["bar", "12", "13", "14"]) + expect(@opt.instance_variable_get(:@switches)["--foo"].default).to eq([]) end end @@ -399,6 +400,7 @@ it "accepts a switch= assignment" do expect(parse("--attributes=name:string", "age:integer")["attributes"]).to eq("name" => "string", "age" => "integer") + expect(parse("--attributes=-name:string", "age:integer", "--gender:string")["attributes"]).to eq("-name" => "string", "age" => "integer") end it "accepts a switch assignment" do @@ -426,6 +428,7 @@ it "accepts a switch= assignment" do expect(parse("--attributes=a", "b", "c")["attributes"]).to eq(%w(a b c)) + expect(parse("--attributes=-a", "b", "-c")["attributes"]).to eq(%w(-a b)) end it "accepts a switch assignment" do diff -Nru ruby-thor-1.0.1/spec/quality_spec.rb ruby-thor-1.2.1/spec/quality_spec.rb --- ruby-thor-1.0.1/spec/quality_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/quality_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -37,7 +37,7 @@ end it "has no malformed whitespace" do - exempt = /\.gitmodules|\.marshal|fixtures|vendor|spec|ssl_certs|LICENSE/ + exempt = /\.gitmodules|\.marshal|fixtures|vendor|spec|ssl_certs|LICENSE|.devcontainer/ error_messages = [] Dir.chdir(File.expand_path("../..", __FILE__)) do `git ls-files`.split("\n").each do |filename| diff -Nru ruby-thor-1.0.1/spec/shell/basic_spec.rb ruby-thor-1.2.1/spec/shell/basic_spec.rb --- ruby-thor-1.0.1/spec/shell/basic_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/shell/basic_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -173,6 +173,103 @@ expect($stdout).to receive(:print).with("this_is_not_a_string\n") shell.say(:this_is_not_a_string, nil, true) end + + it "does not print a message if muted" do + expect($stdout).not_to receive(:print) + shell.mute do + shell.say("Running...") + end + end + + it "does not print a message if base is set to quiet" do + shell.base = MyCounter.new [1, 2] + expect(shell.base).to receive(:options).and_return(:quiet => true) + + expect($stdout).not_to receive(:print) + shell.say("Running...") + end + end + + describe "#say_error" do + it "prints a message to the user" do + expect($stderr).to receive(:print).with("Running...\n") + shell.say_error("Running...") + end + + it "prints a message to the user without new line if it ends with a whitespace" do + expect($stderr).to receive(:print).with("Running... ") + shell.say_error("Running... ") + end + + it "does not use a new line with whitespace+newline embedded" do + expect($stderr).to receive(:print).with("It's \nRunning...\n") + shell.say_error("It's \nRunning...") + end + + it "prints a message to the user without new line" do + expect($stderr).to receive(:print).with("Running...") + shell.say_error("Running...", nil, false) + end + + it "coerces everything to a string before printing" do + expect($stderr).to receive(:print).with("this_is_not_a_string\n") + shell.say_error(:this_is_not_a_string, nil, true) + end + + it "does not print a message if muted" do + expect($stderr).not_to receive(:print) + shell.mute do + shell.say_error("Running...") + end + end + + it "does not print a message if base is set to quiet" do + shell.base = MyCounter.new [1, 2] + expect(shell.base).to receive(:options).and_return(:quiet => true) + + expect($stderr).not_to receive(:print) + shell.say_error("Running...") + end + end + + describe "#print_wrapped" do + let(:message) do + "Creates a back-up of the given folder by compressing it in a .tar.gz\n"\ + "file and then uploading it to the configured Amazon S3 Bucket.\n\n"\ + "It does not verify the integrity of the generated back-up." + end + + before do + allow(ENV).to receive(:[]).with("THOR_COLUMNS").and_return(80) + end + + context "without indentation" do + subject(:wrap_text) { described_class.new.print_wrapped(message) } + + let(:expected_output) do + "Creates a back-up of the given folder by compressing it in a .tar.gz file and\n"\ + "then uploading it to the configured Amazon S3 Bucket.\n\n"\ + "It does not verify the integrity of the generated back-up.\n" + end + + it "properly wraps the text around the 80th column" do + expect { wrap_text }.to output(expected_output).to_stdout + end + end + + context "with indentation" do + subject(:wrap_text) { described_class.new.print_wrapped(message, :indent => 4) } + + let(:expected_output) do + " Creates a back-up of the given folder by compressing it in a .tar.gz file\n"\ + " and then uploading it to the configured Amazon S3 Bucket.\n\n"\ + " It does not verify the integrity of the generated back-up.\n" + end + + it "properly wraps the text around the 80th column" do + expect { wrap_text }.to output(expected_output).to_stdout + end + end end describe "#say_status" do @@ -186,6 +283,20 @@ shell.say_status(:create, "") end + it "indents a multiline message" do + status = :foobar + lines = ["first line", "second line", " third line", " fourth line"] + + expect($stdout).to receive(:print) do |string| + formatted_status = string[/^\s*#{status}\s*/] + margin = " " * formatted_status.length + + expect(string).to eq(formatted_status + lines.join("\n#{margin}") + "\n") + end + + shell.say_status(status, lines.join("\n") + "\n") + end + it "does not print a message if base is muted" do expect(shell).to receive(:mute?).and_return(true) expect($stdout).not_to receive(:print) @@ -281,7 +392,7 @@ 2.times { @table.first.pop } content = capture(:stdout) { shell.print_table(@table) } expect(content).to eq(<<-TABLE) -abc +abc#{" "} #0 empty xyz #786 last three TABLE diff -Nru ruby-thor-1.0.1/spec/shell/color_spec.rb ruby-thor-1.2.1/spec/shell/color_spec.rb --- ruby-thor-1.0.1/spec/shell/color_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/shell/color_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -7,6 +7,8 @@ before do allow($stdout).to receive(:tty?).and_return(true) + allow(ENV).to receive(:[]).and_return(nil) + allow(ENV).to receive(:[]).with("TERM").and_return("ansi") allow_any_instance_of(StringIO).to receive(:tty?).and_return(true) end @@ -131,13 +133,19 @@ expect(colorless).to eq("hi!") end - it "does nothing when the terminal does not support color" do + it "does nothing when stdout is not a tty" do allow($stdout).to receive(:tty?).and_return(false) colorless = shell.set_color "hi!", :white expect(colorless).to eq("hi!") end - it "does nothing when the terminal has the NO_COLOR environment variable set" do + it "does nothing when the TERM environment variable is set to 'dumb'" do + allow(ENV).to receive(:[]).with("TERM").and_return("dumb") + colorless = shell.set_color "hi!", :white + expect(colorless).to eq("hi!") + end + + it "does nothing when the NO_COLOR environment variable is set" do allow(ENV).to receive(:[]).with("NO_COLOR").and_return("") allow($stdout).to receive(:tty?).and_return(true) colorless = shell.set_color "hi!", :white diff -Nru ruby-thor-1.0.1/spec/util_spec.rb ruby-thor-1.2.1/spec/util_spec.rb --- ruby-thor-1.0.1/spec/util_spec.rb 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/spec/util_spec.rb 2022-01-04 23:17:23.000000000 +0000 @@ -180,7 +180,7 @@ '/home/apps\\{1\\}/Thorfile', '/home/apps\\{1\\}/*.thor', '/home/apps\\{1\\}/tasks/*.thor', - '/home/apps\\{1\\}/lib/tasks/*.thor' + '/home/apps\\{1\\}/lib/tasks/**/*.thor' ]) end end diff -Nru ruby-thor-1.0.1/thor.gemspec ruby-thor-1.2.1/thor.gemspec --- ruby-thor-1.0.1/thor.gemspec 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/thor.gemspec 2022-01-04 23:17:23.000000000 +0000 @@ -14,11 +14,12 @@ spec.licenses = %w(MIT) spec.name = "thor" spec.metadata = { - "bug_tracker_uri" => "https://github.com/erikhuda/thor/issues", - "changelog_uri" => "https://github.com/erikhuda/thor/blob/master/CHANGELOG.md", + "bug_tracker_uri" => "https://github.com/rails/thor/issues", + "changelog_uri" => "https://github.com/rails/thor/releases/tag/v#{Thor::VERSION}", "documentation_uri" => "http://whatisthor.com/", - "source_code_uri" => "https://github.com/erikhuda/thor/tree/v#{Thor::VERSION}", - "wiki_uri" => "https://github.com/erikhuda/thor/wiki" + "source_code_uri" => "https://github.com/rails/thor/tree/v#{Thor::VERSION}", + "wiki_uri" => "https://github.com/rails/thor/wiki", + "rubygems_mfa_required" => "true", } spec.require_paths = %w(lib) spec.required_ruby_version = ">= 2.0.0" diff -Nru ruby-thor-1.0.1/.travis.yml ruby-thor-1.2.1/.travis.yml --- ruby-thor-1.0.1/.travis.yml 2019-12-17 15:12:43.000000000 +0000 +++ ruby-thor-1.2.1/.travis.yml 1970-01-01 00:00:00.000000000 +0000 @@ -1,21 +0,0 @@ -before_install: - - gem update --system 2.7.9 - - gem install bundler:1.17.3 - - rvm @global do gem uninstall did_you_mean -bundler_args: --without development -language: ruby -rvm: - - 2.0.0 - - 2.1.10 - - 2.2.10 - - 2.3.8 - - 2.4.7 - - 2.5.6 - - 2.6.4 - - ruby-head -matrix: - allow_failures: - - rvm: ruby-head - fast_finish: true -script: bundle exec thor spec -cache: bundler