From bac8015f98d751d9cf38173edcee13602f1a66d0 Mon Sep 17 00:00:00 2001 From: "yuuji.yaginuma" Date: Thu, 5 Jan 2023 17:00:19 +0900 Subject: [PATCH] Use the defined type to the default value of `directory` Currently, you will get Thor's deprecated message when starting the `Listen::CLI`. ``` Deprecation warning: Expected array default value for '--directory'; got "." (string). This will be rejected in the future unless you explicitly pass the options `check_default_type: false` or call `allow_incompatible_default_type!` in your code You can silence deprecations warning by setting the environment variable THOR_SILENCE_DEPRECATION. ``` This is due to the incorrect default value(`directory` is defined as an `array`, but the default value is a `string`). This fixed to use the correct default value and correctly pass to the `directory` to `Listen.to`. --- lib/listen/cli.rb | 6 +++--- spec/lib/listen/cli_spec.rb | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/listen/cli.rb b/lib/listen/cli.rb index 6fcfbe46..e3173133 100644 --- a/lib/listen/cli.rb +++ b/lib/listen/cli.rb @@ -18,9 +18,9 @@ class CLI < Thor class_option :directory, type: :array, - default: '.', + default: ['.'], aliases: '-d', - banner: 'The directory to listen to' + banner: 'One or more directories to listen to' class_option :relative, type: :boolean, @@ -55,7 +55,7 @@ def start end end - listener = Listen.to(directory, relative: relative, &callback) + listener = Listen.to(*directory, relative: relative, &callback) listener.start diff --git a/spec/lib/listen/cli_spec.rb b/spec/lib/listen/cli_spec.rb index 80133a9f..a85381fa 100644 --- a/spec/lib/listen/cli_spec.rb +++ b/spec/lib/listen/cli_spec.rb @@ -15,7 +15,7 @@ let(:options) { %w[] } it 'is set to local directory' do expect(Listen::Forwarder).to receive(:new) do |options| - expect(options[:directory]).to eq('.') + expect(options[:directory]).to eq(['.']) forwarder end described_class.start(options) @@ -108,7 +108,7 @@ it 'passes relative option to Listen' do value = double('value') expect(Listen).to receive(:to). - with(nil, hash_including(relative: value)). + with(hash_including(relative: value)). and_return(listener) described_class.new(relative: value).start