Class: OKF::CLI::Index

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

Overview

The progressive-disclosure map (spec §6): every directory that holds concepts or carries an index.md, with its authored index body, a type/tag rollup, its child directories, and — for a directory with no index.md — the listing synthesized from the concepts there. The "orient before you read" view. --area is repeatable (one or many directories; root is the bundle root); --no-body drops the prose to a skeleton; advisory, exit 0.

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



16
17
18
# File 'lib/okf/cli/index.rb', line 16

def self.group
  :read
end

.help_rowsObject



20
21
22
23
24
# File 'lib/okf/cli/index.rb', line 20

def self.help_rows
  [
    [ "index     <dir|@slug> [--json] [--area A] [--no-body]", "the index map: dirs, their listings and rollups" ]
  ]
end

.idObject



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

def self.id
  :index
end

Instance Method Details

#call(argv) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/okf/cli/index.rb', line 26

def call(argv)
  options = { json: false, body: true, areas: nil }
  parser = OptionParser.new do |o|
    o.banner = "Usage: okf index <dir|@slug> [--area AREA] [--no-body] [--json]"
    json_flags(o, options, "emit the index map as JSON")
    projection_flags(o, options)
    o.on("--area AREA", "only this directory/area (repeatable; `root` for the bundle root)") { |v| (options[:areas] ||= []) << v }
    o.on("--[no-]body", "include each index's prose body (default: yes)") { |v| options[:body] = v }
    help_flag(o)
  end
  dir = positional_dir(parser, argv) or return 2

  folder = OKF::Bundle::Folder.load(dir)
  report_skipped(folder)
  entries = folder.directory_index
  selected = select_directories(entries, options[:areas])
  if options[:json]
    # --no-body is shorthand for --except body, so asking for the body by
    # name in the same breath is a contradiction. Letting --fields quietly
    # win would hand back the very thing the other flag was there to drop.
    if !options[:body] && Array(options[:fields]).map(&:downcase).include?("body")
      return usage_error("--no-body and --fields body contradict each other: drop one")
    end

    options[:except] = Array(options[:except]) + [ "body" ] unless options[:body] || options[:fields]
    return print_index_map_json(dir, selected, options)
  end
  print_index_map(dir, selected, options[:body])
  0
end