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 profiles and output formats, with ftxvalidator-compatible options.

Examples:

Validating a font with default profile

command = ValidateCommand.new(input: "font.ttf")
exit_code = command.run

Validating with specific profile

command = ValidateCommand.new(
  input: "font.ttf",
  profile: :web,
  format: :json
)
exit_code = command.run

Instance Method Summary collapse

Constructor Details

#initialize(input:, profile: nil, exclude: [], output: nil, format: :text, full_report: false, summary_report: false, table_report: false, verbose: false, suppress_warnings: false, return_value_results: false) ⇒ ValidateCommand

Initialize validate command

Parameters:

  • input (String)

    Path to font file

  • profile (Symbol, String, nil) (defaults to: nil)

    Validation profile (default: :default)

  • exclude (Array<String>) (defaults to: [])

    Tests to exclude

  • output (String, nil) (defaults to: nil)

    Output file path

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

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

  • full_report (Boolean) (defaults to: false)

    Generate full detailed report

  • summary_report (Boolean) (defaults to: false)

    Generate brief summary report

  • table_report (Boolean) (defaults to: false)

    Generate tabular format report

  • verbose (Boolean) (defaults to: false)

    Show verbose output

  • suppress_warnings (Boolean) (defaults to: false)

    Suppress warning output

  • return_value_results (Boolean) (defaults to: false)

    Use return values to indicate results



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fontisan/commands/validate_command.rb', line 40

def initialize(
  input:,
  profile: nil,
  exclude: [],
  output: nil,
  format: :text,
  full_report: false,
  summary_report: false,
  table_report: false,
  verbose: false,
  suppress_warnings: false,
  return_value_results: false
)
  @input = input
  @profile = profile || :default
  @exclude = exclude
  @output = output
  @format = format
  @full_report = full_report
  @summary_report = summary_report
  @table_report = table_report
  @verbose = verbose
  @suppress_warnings = suppress_warnings
  @return_value_results = return_value_results
end

Instance Method Details

#runInteger

Run the validation command

Returns:

  • (Integer)

    Exit code (0 = valid, 2 = fatal, 3 = errors, 4 = warnings, 5 = info)



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/fontisan/commands/validate_command.rb', line 69

def run
  # Load font with appropriate mode
  profile_config = Validators::ProfileLoader.profile_info(@profile)
  unless profile_config
    puts "Error: Unknown profile '#{@profile}'" unless @suppress_warnings
    return 1
  end

  mode = profile_config[:loading_mode].to_sym

  font = FontLoader.load(@input, mode: mode)

  # Select validator
  validator = Validators::ProfileLoader.load(@profile)

  # Run validation
  report = validator.validate(font)

  # Filter excluded checks if specified
  if @exclude.any?
    report.check_results.reject! { |cr| @exclude.include?(cr.check_id) }
  end

  # Generate output
  output = generate_output(report)

  # Write to file or stdout
  if @output
    File.write(@output, output)
    puts "Validation report written to #{@output}" if @verbose && !@suppress_warnings
  else
    puts output unless @suppress_warnings
  end

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