Class: ColorLS::Flags

Inherits:
Object
  • Object
show all
Defined in:
lib/colorls/flags.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Flags

Returns a new instance of Flags.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/colorls/flags.rb', line 9

def initialize(*args)
  @args = args
  @light_colors = false

  @opts = default_opts

  parse_options

  return unless @opts[:mode] == :tree

  # FIXME: `--all` and `--tree` do not work together, use `--almost-all` instead
  @opts[:almost_all] = true if @opts[:all]
  @opts[:all] = false

  # `--tree` does not support reports
  @opts[:report] = false
end

Instance Method Details

#optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/colorls/flags.rb', line 48

def options
  list = @parser.top.list + @parser.base.list

  result = list.collect do |o|
    next unless o.respond_to? 'desc'

    flags = o.short + o.long
    next if flags.empty?

    OpenStruct.new(flags: flags, desc: o.desc)
  end

  result.compact
end

#processObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/colorls/flags.rb', line 27

def process
  init_locale

  @args = ['.'] if @args.empty?
  exit_status_code = 0
  @args.sort!.each_with_index do |path, i|
    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
    Core.new(path, **@opts).ls
  rescue SystemCallError => e
    $stderr.puts "#{path}: #{e}".colorize(:red)
  end
  exit_status_code
end