Class: OKF::CLI::Tags

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

Overview

The tag index: which tags exist, how often, and on what. --by regroups them per concept dimension, which is the view for curating a vocabulary rather than reading one.

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



13
14
15
# File 'lib/okf/cli/tags.rb', line 13

def self.group
  :read
end

.help_rowsObject



17
18
19
20
21
# File 'lib/okf/cli/tags.rb', line 17

def self.help_rows
  [
    [ "tags      <dir|@slug> [--json] [--by DIM] [filters]", "list tags with their concepts, by count" ]
  ]
end

.idObject



9
10
11
# File 'lib/okf/cli/tags.rb', line 9

def self.id
  :tags
end

Instance Method Details

#call(argv) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/okf/cli/tags.rb', line 23

def call(argv)
  options = { json: false, by: nil }
  parser = OptionParser.new do |o|
    o.banner = "Usage: okf tags <dir|@slug> [--by type|area] [--type T] [--area A] [--json]"
    json_flags(o, options, "emit the tag index as JSON")
    o.on("--by DIM", %w[type area], "group the tags by a concept dimension (type | area)") { |v| options[:by] = v.to_sym }
    filter_flags(o, options, :type, :area)
    help_flag(o)
  end
  dir = positional_dir(parser, argv) or return 2

  return grouped_tags(dir, options) if options[:by]

  print_inverted_index(dir, "Tags", :tag, "tags", options)
end