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: FailOn, Format, PackageBy, Skip, Usage Classes: Arguments, CommandLine, Flag, Options, Run

Constant Summary collapse

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: "--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: "--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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ CLI

Returns a new instance of CLI.



18
19
20
21
# File 'lib/hashira/cli.rb', line 18

def initialize(options)
  @options = options
  @pipeline = options.pipeline
end

Class Method Details

.failure(error) ⇒ Object



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

def self.failure(error)
  warn("hashira: #{error.message}")
  1
end

.run(argv) ⇒ Object



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

def self.run(argv)
  options = Options.parse(argv)
  usage?(options) ? Usage.public_send(options.mode) : new(options).run
rescue Hashira::Error => error
  failure(error)
end

.usage?(options) ⇒ Boolean

Returns:

  • (Boolean)


11
# File 'lib/hashira/cli.rb', line 11

def self.usage?(options) = Usage::PAGES.include?(options.mode)

Instance Method Details

#runObject



23
# File 'lib/hashira/cli.rb', line 23

def run = Run.new(@pipeline, @options).status