Module: Hashira::CLI::Usage

Defined in:
lib/hashira/cli/usage.rb

Constant Summary collapse

PAGES =
%i[help version].freeze
HEADER =
<<~TEXT
  Usage: hashira [DIRECTORY ...] [options]

  Coupling, cognitive-complexity, duplication, and code-smell metrics
  for Ruby, via Prism, rolled up per file as a ranked list of hotspots.
  With no directory, auto-detects lib/<gem>.

  Options:
TEXT
<<~TEXT

  Exit codes: 0 clean · 1 findings or a regression · 2 misuse
  (bad flags, missing directory, unusable baseline) · 3 an
  improvement the baseline has not recorded · 70 internal error.

  Findings accepted by design can be recorded in the baseline as
    "accepted": [{"kind": "...", "package": "...", "reason": "..."}]
  — they leave reports and gates, keeping a one-line reminder each.
  Clones are named by "digest" instead of "package", so an acceptance
  survives the lines above it moving. Read digests from --json.
TEXT

Class Method Summary collapse

Class Method Details

.emit(output) ⇒ Object



44
45
46
47
# File 'lib/hashira/cli/usage.rb', line 44

def emit(output)
  $stdout.puts(output)
  0
end

.helpObject



33
# File 'lib/hashira/cli/usage.rb', line 33

def help = emit(HEADER + options + FOOTER)

.optionsObject



37
# File 'lib/hashira/cli/usage.rb', line 37

def options = Hashira::CLI::FLAGS.map { rows(it) }.join

.rows(flag) ⇒ Object



39
40
41
42
# File 'lib/hashira/cli/usage.rb', line 39

def rows(flag)
  first, *rest = flag.text
  ["  #{flag.label.ljust(21)}#{first}\n", *rest.map { "#{" " * 23}#{it}\n" }].join
end

.versionObject



35
# File 'lib/hashira/cli/usage.rb', line 35

def version = emit("hashira #{Hashira::VERSION}")