Class: ColorLS::Flags
- Inherits:
-
Object
- Object
- ColorLS::Flags
- Defined in:
- lib/colorls/flags.rb
Instance Method Summary collapse
-
#initialize(*args) ⇒ Flags
constructor
A new instance of Flags.
- #options ⇒ Object
- #process ⇒ Object
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 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/colorls/flags.rb', line 9 def initialize(*args) @args = args @light_colors = false @opts = { show: false, sort: true, reverse: false, group: nil, mode: STDOUT.tty? ? :vertical : :one_per_line, all: false, almost_all: false, report: false, git_status: false, colors: [], tree_depth: 3 } 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
#options ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/colorls/flags.rb', line 57 def 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 |
#process ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/colorls/flags.rb', line 39 def process # initialize locale from environment CLocale.setlocale(CLocale::LC_COLLATE, '') @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.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 end end |