Class: OKF::CLI::Dirs

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

Overview

The bundle's directories — its clusters — and how many concepts live directly in each. The shape view: index reads a directory's contents, dirs reads the layout they hang off, which is the question --dir is answered against.

count is direct, never cumulative: a dir's number is what lives in it, so the column sums to the bundle's concept count and an empty intermediate dir reads as the zero it is. subtree is the other half of that honesty — what --dir <that row> would return — because a direct count alone cannot say where the mass is once --depth truncates the listing: on a deep bundle the top-level rows are then all zeroes.

Presentation only — every number comes off Bundle#directory_index, the same source okf index and the server's Index panel read. 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



24
25
26
# File 'lib/okf/cli/dirs.rb', line 24

def self.group
  :read
end

.help_rowsObject



28
29
30
31
32
# File 'lib/okf/cli/dirs.rb', line 28

def self.help_rows
  [
    [ "dirs      <dir|@slug> [--json] [--dir D] [--depth N]", "list the bundle's dirs (clusters) and their concept counts" ]
  ]
end

.idObject



20
21
22
# File 'lib/okf/cli/dirs.rb', line 20

def self.id
  :dirs
end

Instance Method Details

#call(argv) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/okf/cli/dirs.rb', line 34

def call(argv)
  options = { json: false, dirs: nil, depth: nil, ancestors: true }
  parser = OptionParser.new do |o|
    o.banner = "Usage: okf dirs <dir|@slug> [--dir PATH] [--depth N] [--json]"
    json_flags(o, options, "emit the dirs as JSON")
    projection_flags(o, options)
    o.on("--dir PATH", "only this directory and the ones below it",
      "(repeatable; `root` for the bundle root)") { |v| (options[:dirs] ||= []) << v }
    depth_flag(o, options)
    ancestors_flag(o, options)
    help_flag(o)
  end
  dir = positional_dir(parser, argv) or return 2
  bad_depth = depth_error(options)
  return bad_depth if bad_depth

  folder = OKF::Bundle::Folder.load(dir)
  report_skipped(folder)
  rows = select_rows(folder.directory_index, options)
  return emit_list_json(dir, "dirs", rows, options, "total" => total(rows)) if options[:json]

  print_dirs(dir, rows)
  0
end