Class: Snip::Command::List

Inherits:
Object
  • Object
show all
Defined in:
lib/snip/command/list.rb

Instance Method Summary collapse

Constructor Details

#initialize(args = [], options = {}) ⇒ List

Returns a new instance of List.



6
7
8
9
# File 'lib/snip/command/list.rb', line 6

def initialize(args=[], options={})
  @args = Array(args)
  @options = options
end

Instance Method Details

#executeObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/snip/command/list.rb', line 11

def execute
  raise NotInitializedError unless Snip::initialized?

  Dir.foreach(Snip::INSTALL_DIR) do |file|
    next if file == '.' or file == '..'
    next unless @args.empty? || file.match(@args.first)

    first_line = ""
    File.open(File.join(Snip::INSTALL_DIR, file)) {|f| first_line = f.readline}

    printf("%-35s # %s", file.color(:blue), first_line);
  end
end