Class: OKF::CLI::Index
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
Class Method Summary collapse
Instance Method Summary collapse
Methods inherited from Command
Constructor Details
This class inherits a constructor from OKF::CLI::Command
Class Method Details
.group ⇒ Object
16 17 18 |
# File 'lib/okf/cli/index.rb', line 16 def self.group :read end |
.help_rows ⇒ Object
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 |
.id ⇒ Object
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) = { json: false, body: true, areas: nil } parser = OptionParser.new do |o| o. = "Usage: okf index <dir|@slug> [--area AREA] [--no-body] [--json]" json_flags(o, , "emit the index map as JSON") projection_flags(o, ) o.on("--area AREA", "only this directory/area (repeatable; `root` for the bundle root)") { |v| ([:areas] ||= []) << v } o.on("--[no-]body", "include each index's prose body (default: yes)") { |v| [: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, [:areas]) if [: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 ![:body] && Array([:fields]).map(&:downcase).include?("body") return usage_error("--no-body and --fields body contradict each other: drop one") end [:except] = Array([:except]) + [ "body" ] unless [:body] || [:fields] return print_index_map_json(dir, selected, ) end print_index_map(dir, selected, [:body]) 0 end |