mirror of
https://github.com/athityakumar/colorls.git
synced 2024-09-19 05:31:23 +02:00
Merge pull request #166 from avdv/rescue-errors
Handle errors gracefully
This commit is contained in:
commit
445cfc3836
2 changed files with 11 additions and 18 deletions
|
@ -1,9 +1,9 @@
|
|||
module ColorLS
|
||||
class Core
|
||||
def initialize(input=nil, all: false, report: false, sort: false, show: false,
|
||||
def initialize(input, all: false, report: false, sort: false, show: false,
|
||||
mode: nil, git_status: false, almost_all: false, colors: [], group: nil,
|
||||
reverse: false)
|
||||
@input = init_input_path(input)
|
||||
@input = File.absolute_path(input)
|
||||
@count = {folders: 0, recognized_files: 0, unrecognized_files: 0}
|
||||
@all = all
|
||||
@almost_all = almost_all
|
||||
|
@ -44,17 +44,6 @@ module ColorLS
|
|||
|
||||
private
|
||||
|
||||
def init_input_path(input)
|
||||
return Dir.pwd unless input
|
||||
return input unless Dir.exist?(input)
|
||||
|
||||
actual = Dir.pwd
|
||||
Dir.chdir(input)
|
||||
input = Dir.pwd
|
||||
Dir.chdir(actual)
|
||||
input
|
||||
end
|
||||
|
||||
def init_contents(path)
|
||||
is_directory = Dir.exist?(path)
|
||||
@contents = if is_directory
|
||||
|
|
|
@ -37,12 +37,16 @@ module ColorLS
|
|||
# initialize locale from environment
|
||||
CLocale.setlocale(CLocale::LC_COLLATE, '')
|
||||
|
||||
return Core.new(@opts).ls if @args.empty?
|
||||
@args = [Dir.pwd] if @args.empty?
|
||||
@args.sort!.each_with_index do |path, i|
|
||||
begin
|
||||
next STDERR.puts "\n Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path)
|
||||
puts '' if i > 0
|
||||
puts "#{path}:" if Dir.exist?(path) && @args.size > 1
|
||||
puts "\n#{path}:" if Dir.exist?(path) && @args.size > 1
|
||||
Core.new(path, @opts).ls
|
||||
rescue SystemCallError => e
|
||||
STDERR.puts "#{path}: #{e}".colorize(:red)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue