22
23
24
25
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
|
# File 'lib/okf/cli/graph.rb', line 22
def call(argv)
options = { json: false, minimal: false, body: true, hubs: false }
parser = OptionParser.new do |o|
o.banner = "Usage: okf graph <dir|@slug> [--json] [--minimal] [--no-body] [--hubs]"
json_flags(o, options, "emit nodes and edges as JSON")
o.on("--minimal", "leanest nodes (id + title); adds type/tag indexes") { options[:minimal] = true }
o.on("--[no-]body", "include each concept's body (default: yes)") { |v| options[:body] = v }
o.on("--hubs", "rank concepts by inbound links, with the source areas") { options[:hubs] = true }
help_flag(o)
end
dir = positional_dir(parser, argv) or return 2
return print_hubs(dir, options) if options[:hubs]
folder = OKF::Bundle::Folder.load(dir)
graph = folder.graph(minimal: options[:minimal], body: options[:body])
report_skipped(folder)
if options[:json]
payload = bundle_head(dir).merge(graph.to_h)
payload = payload.merge(types: graph.type_index, tags: graph.tag_index) if options[:minimal]
emit_json(payload)
else
@out.puts "Graph — #{bundle_label(dir)} (#{graph.nodes.size} #{pluralize(graph.nodes.size, "concept")}, " \
"#{graph.edges.size} #{pluralize(graph.edges.size, "link")})"
end
0
end
|