Class: OKF::CLI::Files

Inherits:
Command show all
Defined in:
lib/okf/cli/files.rb

Overview

Every file with its title, grouped by folder — the view for "what is on disk" rather than "what is modelled".

Constant Summary

Constants inherited from Command

Command::DUCK_TYPE

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Command

hidden?, #initialize

Constructor Details

This class inherits a constructor from OKF::CLI::Command

Class Method Details

.groupObject



12
13
14
# File 'lib/okf/cli/files.rb', line 12

def self.group
  :read
end

.help_rowsObject



16
17
18
19
20
# File 'lib/okf/cli/files.rb', line 16

def self.help_rows
  [
    [ "files     <dir|@slug> [--json] [filters]", "list files with titles, by folder" ]
  ]
end

.idObject



8
9
10
# File 'lib/okf/cli/files.rb', line 8

def self.id
  :files
end

Instance Method Details

#call(argv) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/okf/cli/files.rb', line 22

def call(argv)
  options = { json: false }
  parser = OptionParser.new do |o|
    o.banner = "Usage: okf files <dir|@slug> [--type T] [--area A] [--tag T] [--json]"
    json_flags(o, options, "emit the file tree as JSON")
    projection_flags(o, options)
    filter_flags(o, options, :type, :area, :tag)
    help_flag(o)
  end
  dir = positional_dir(parser, argv) or return 2

  folder = OKF::Bundle::Folder.load(dir)
  report_skipped(folder)
  entries = folder.catalog
  selected = filter_entries(entries, options)
  return print_files_json(dir, selected, options) if options[:json]

  print_files(dir, selected, entries.size)
  0
end