Skip to content

Commit

Permalink
Use the defined type to the default value of directory
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
y-yagi committed Jan 8, 2023
1 parent abb90a5 commit f813b49
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Empty file added a.txt
Empty file.
6 changes: 3 additions & 3 deletions lib/listen/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -55,7 +55,7 @@ def start
end
end

listener = Listen.to(directory, relative: relative, &callback)
listener = Listen.to(*directory, relative: relative, &callback)

listener.start

Expand Down
4 changes: 2 additions & 2 deletions spec/lib/listen/cli_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit f813b49

Please sign in to comment.