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.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/colorls/flags.rb', line 3

def initialize(*args)
  @args = args
  set_color_opts

  @opts = {
    show: fetch_show_opts,
    sort: fetch_sort_opts,
    all: flag_given?(%w[-a --all]),
    almost_all: flag_given?(%w[-A --almost-all]),
    report: flag_given?(%w[-r --report]),
    one_per_line: flag_given?(%w[-1]) || !STDOUT.tty?,
    long: flag_given?(%w[-l --long]),
    tree: flag_given?(%w[-t --tree]),
    colors: @colors
  }

  @args.keep_if { |arg| !arg.start_with?('-') }
end

Instance Method Details

#processObject



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/colorls/flags.rb', line 22

def process
  incompatible = report_incompatible_flags
  return STDERR.puts "\n   #{incompatible}".colorize(:red) if incompatible

  return Core.new(@opts).ls if @args.empty?

  @args.each do |path|
    next STDERR.puts "\n   Specified path '#{path}' doesn't exist.".colorize(:red) unless File.exist?(path)
    Core.new(path, @opts).ls
  end
end