Class: OKF::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/okf/cli.rb

Overview

Command-line front end: okf graph|validate|lint|loose|index|catalog|files|tags|types|stats|server <dir>. This is the only layer that parses argv, prints, writes files, and decides exit codes — the lib classes below it just return data. Streams are injectable for testing.

Exit codes: 0 success, 1 non-conformant / failing bundle, 2 usage error.

Constant Summary collapse

LINT_CATEGORIES =

Lint findings grouped for display, in category order.

{
  "Reachability" => %i[orphan not_in_index disconnected_component unlinked],
  "Backlog" => %i[missing_concept broken_index_entry],
  "Completeness" => %i[stub missing_title missing_description missing_timestamp],
  "Freshness" => %i[stale],
  "Provenance" => %i[uncited_external broken_citation],
  "Hygiene" => %i[duplicate_title unused_reference_def undefined_reference self_link]
}.freeze
WEBRICK =

Runs a Rack app under WEBrick until interrupted. Injected into the CLI so tests can drive server without opening a socket; the runner loads here (not at require time) so require "okf" and a Rails mount of the server stay light.

lambda do |app, host, port|
  require "okf/server/runner"
  OKF::Server::Runner.run(app, host: host, port: port)
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(out: $stdout, err: $stderr, runner: WEBRICK) ⇒ CLI

Returns a new instance of CLI.



36
37
38
39
40
41
# File 'lib/okf/cli.rb', line 36

def initialize(out: $stdout, err: $stderr, runner: WEBRICK)
  @out = out
  @err = err
  @runner = runner
  @pretty = false
end

Class Method Details

.start(argv, out: $stdout, err: $stderr) ⇒ Object



32
33
34
# File 'lib/okf/cli.rb', line 32

def self.start(argv, out: $stdout, err: $stderr)
  new(out: out, err: err).run(argv)
end

Instance Method Details

#run(argv) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/okf/cli.rb', line 43

def run(argv)
  argv = argv.dup
  case (command = argv.shift)
  when "graph" then graph(argv)
  when "validate" then validate(argv)
  when "lint" then lint(argv)
  when "loose" then loose(argv)
  when "index" then index(argv)
  when "catalog" then catalog(argv)
  when "files" then files(argv)
  when "tags" then tags(argv)
  when "types" then types(argv)
  when "stats" then stats(argv)
  when "server" then server(argv)
  when "skill" then skill(argv)
  when "version", "--version", "-v" then @out.puts(OKF::VERSION); 0
  when "help", "--help", "-h" then usage(@out); 0
  when nil then usage(@err); 2
  else
    @err.puts "okf: unknown command '#{command}'"
    usage(@err)
    2
  end
end