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
# File 'lib/colorls/flags.rb', line 3

def initialize(*args)
  @args = args
  @opts = {
    show: fetch_show_opts,
    sort: fetch_sort_opts,
    all: flag_given?(%w[-a --all]),
    report: flag_given?(%w[-r --report]),
    one_per_line: flag_given?(%w[-1])
  }

  return if @opts[:show].nil? || @opts[:sort].nil?

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

Instance Method Details

#processObject



18
19
20
21
22
23
24
25
# File 'lib/colorls/flags.rb', line 18

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

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