Module: GreenHat::ShellHelper::List

Defined in:
lib/greenhat/shell/list.rb

Overview

Helper to handle listing of files

Class Method Summary collapse

Class Method Details

.helpObject

Unified Help



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/greenhat/shell/list.rb', line 32

def self.help
  puts '  ls'.pastel(:green)
  puts '    List available files'
  puts '    Options'.pastel(:cyan)
  puts '      -a, --all, show full file name/path including source'
  puts '      <string> filter available'
  puts '    Examples'.pastel(:cyan)
  puts '      ls -a rails'
  puts '      ls sys'
  puts
end

.list(raw = [], files) ⇒ Object

List Files Helpers



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/greenhat/shell/list.rb', line 6

def self.list(raw = [], files)
  filter, flags, _args = Args.parse(raw)

  # Sort
  files.sort_by!(&:name)

  # Simplified vs Full. Full file name/path / or just file kinds
  all = flags.key?(:all) || flags.key?(:a)

  # Short & Uniq
  files.uniq!(&:name) unless all

  # Filter / Pattern
  files.select! { |f| filter.any? { |x| f.name.include? x } } unless filter.empty?

  # Print
  files.each do |log|
    if all
      puts "- #{log.friendly_name}"
    else
      puts "- #{log.name.pastel(:yellow)}"
    end
  end
end