Class: Fontisan::Commands::ValidateCommand

Inherits:
BaseCommand
  • Object
show all
Defined in:
lib/fontisan/commands/validate_command.rb

Overview

ValidateCommand provides CLI interface for font validation

This command validates fonts against quality checks, structural integrity, and OpenType specification compliance. It supports different validation levels and output formats.

Examples:

Validating a font

command = ValidateCommand.new(
  input: "font.ttf",
  level: :standard,
  format: :text
)
exit_code = command.run

Instance Method Summary collapse

Constructor Details

#initialize(input:, level: :standard, format: :text, verbose: true, quiet: false) ⇒ ValidateCommand

Initialize validate command

Parameters:

  • input (String)

    Path to font file

  • level (Symbol) (defaults to: :standard)

    Validation level (:strict, :standard, :lenient)

  • format (Symbol) (defaults to: :text)

    Output format (:text, :yaml, :json)

  • verbose (Boolean) (defaults to: true)

    Show all issues (default: true)

  • quiet (Boolean) (defaults to: false)

    Only return exit code, no output (default: false)



31
32
33
34
35
36
37
38
39
# File 'lib/fontisan/commands/validate_command.rb', line 31

def initialize(input:, level: :standard, format: :text, verbose: true,
quiet: false)
  super()
  @input = input
  @level = level.to_sym
  @format = format.to_sym
  @verbose = verbose
  @quiet = quiet
end

Instance Method Details

#runInteger

Run the validation command

Returns:

  • (Integer)

    Exit code (0 = valid, 1 = errors, 2 = warnings only)



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fontisan/commands/validate_command.rb', line 44

def run
  validate_params!

  # Load font
  font = load_font
  return 1 unless font

  # Create validator
  validator = Validation::Validator.new(level: @level)

  # Run validation
  report = validator.validate(font, @input)

  # Add variable font validation if applicable
  validate_variable_font(font, report) if font.has_table?("fvar")

  # Output results unless quiet mode
  output_report(report) unless @quiet

  # Return appropriate exit code
  determine_exit_code(report)
rescue StandardError => e
  puts "Error: #{e.message}" unless @quiet
  puts e.backtrace.join("\n") if @verbose && !@quiet
  1
end