Class: Hashira::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/cli.rb,
lib/hashira/cli/flag.rb,
lib/hashira/cli/flags.rb,
lib/hashira/cli/options.rb

Defined Under Namespace

Modules: Choice, FailOn, Format, Needs, Only, PackageBy, Skip, Top, Usage Classes: Arguments, CommandLine, Flag, Options, Run

Constant Summary collapse

MISUSE =
2
BROKEN =
70
BLANK =
%i[arg field parse mode].to_h { [it, nil] }.freeze
FLAGS =
[
  Flag.new(
    name: "--format", arg: "FORMAT", parse: Format, mode: :parsed,
    text: ["text (default), json, dot, or mermaid"]
  ),
  Flag.new(name: "--json", mode: :json, text: ["shorthand for --format json"]),
  Flag.new(
    name: "--compact", field: :compact,
    text: ["emit JSON on one line, without the indentation", "meant for reading"]
  ),
  Flag.new(
    name: "--fail-on", arg: "KINDS", field: :fail_on, parse: FailOn, mode: :fail_on,
    text: [
      "exit 1 if findings exist; comma-separated",
      "kinds: cycles, sdp, mixed_audience, wide_edge,",
      "roll_call, complexity, duplication, smells (all",
      "of them), or one smell kind such as feature_envy"
    ]
  ),
  Flag.new(
    name: "--skip", arg: "ANALYZERS", field: :skip, parse: Skip,
    text: ["drop an analyzer; comma-separated: coupling,", "complexity, duplication, smells"]
  ),
  Flag.new(
    name: "--only", arg: "PATHS", field: :only, parse: Only,
    text: [
      "keep only the findings that name these files;",
      "comma-separated. The whole project is still read,",
      "so cross-file signals stay right. Meant for hooks:",
      "hashira --only $CHANGED --ratchet"
    ]
  ),
  Flag.new(
    name: "--top", arg: "N", field: :top, parse: Top,
    text: [
      "show at most N rows in each table and N",
      "findings (default: 25 packages and findings,",
      "10 methods and files)"
    ]
  ),
  Flag.new(
    name: "--package-by", arg: "WHAT", field: :packaging, parse: PackageBy,
    text: [
      "group coupling by: auto, folder, or namespace",
      "(top-level constant). Default auto: namespace for",
      "Rails apps (config/application.rb in or beside the",
      "analyzed directory), folder otherwise"
    ]
  ),
  Flag.new(
    name: "--ratchet", mode: :ratchet,
    text: ["fail when edges or findings appear that the", "baseline lacks"]
  ),
  Flag.new(name: "--update-baseline", mode: :update, text: ["record the current edges and findings"]),
  Flag.new(
    name: "--baseline", arg: "PATH", field: :baseline, default: "hashira_baseline.json",
    text: ["baseline file (default: hashira_baseline.json)"]
  ),
  Flag.new(name: "-h, --help", mode: :help, text: ["print this help"]),
  Flag.new(name: "--version", mode: :version, text: ["print the version"])
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ CLI

Returns a new instance of CLI.



7
8
9
# File 'lib/hashira/cli.rb', line 7

def initialize(argv)
  @argv = argv
end

Instance Method Details

#statusObject



11
12
13
14
15
16
17
# File 'lib/hashira/cli.rb', line 11

def status
  dispatch(Options.parse(@argv))
rescue Hashira::Error => error
  failure(error)
rescue StandardError => error
  crash(error)
end