mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Merge pull request #397 from t-mangoe/set_error_code
Set exit status code when specified path doesn't exist
This commit is contained in:
commit
035bcec412
5 changed files with 29 additions and 3 deletions
11
.travis.yml
11
.travis.yml
|
@ -89,6 +89,17 @@ script:
|
|||
- colorls --tree=1
|
||||
- LC_ALL=C colorls spec/fixtures/
|
||||
- LC_ALL=C colorls --git spec/fixtures/
|
||||
- |
|
||||
if colorls does-not-exist; then
|
||||
echo "expected error!"
|
||||
exit 1
|
||||
else
|
||||
ret=$?
|
||||
if [ $ret -ne 2 ]; then
|
||||
echo "unexpected error: $ret"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
deploy:
|
||||
provider: rubygems
|
||||
|
|
|
@ -23,4 +23,4 @@ require 'colorls'
|
|||
$loading = false
|
||||
# rubocop:enable Style/GlobalVars
|
||||
|
||||
ColorLS::Flags.new(*ARGV).process
|
||||
exit ColorLS::Flags.new(*ARGV).process
|
||||
|
|
|
@ -40,8 +40,13 @@ module ColorLS
|
|||
init_locale
|
||||
|
||||
@args = ['.'] if @args.empty?
|
||||
exit_status_code = 0
|
||||
@args.sort!.each_with_index do |path, i|
|
||||
next $stderr.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path)
|
||||
unless File.exist?(path)
|
||||
$stderr.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red)
|
||||
exit_status_code = 2
|
||||
next
|
||||
end
|
||||
|
||||
puts '' if i.positive?
|
||||
puts "\n#{path}:" if Dir.exist?(path) && @args.size > 1
|
||||
|
@ -49,6 +54,7 @@ module ColorLS
|
|||
rescue SystemCallError => e
|
||||
$stderr.puts "#{path}: #{e}".colorize(:red)
|
||||
end
|
||||
exit_status_code
|
||||
end
|
||||
|
||||
def options
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
.\" generated with Ronn/v0.7.3
|
||||
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
||||
.
|
||||
.TH "COLORLS" "1" "May 2020" "colorls 1.4.2" "colorls Manual"
|
||||
.TH "COLORLS" "1" "September 2020" "colorls 1.4.2" "colorls Manual"
|
||||
.
|
||||
.SH "NAME"
|
||||
\fBcolorls\fR \- list directory contents with colors and icons
|
||||
|
|
|
@ -308,4 +308,13 @@ RSpec.describe ColorLS::Flags do
|
|||
expect { subject }.to output(/Unrecognized files\s+: 3/).to_stdout
|
||||
end
|
||||
end
|
||||
|
||||
context 'with non-existent path' do
|
||||
let(:args) { ['not_exist_file'] }
|
||||
|
||||
it 'should exit with status code 2' do
|
||||
expect {subject}.to output(/ Specified path 'not_exist_file' doesn't exist./).to_stderr
|
||||
expect(subject).to eq 2
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue