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



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

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)



65
66
67
68
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
# File 'lib/fontisan/commands/validate_command.rb', line 65

def run
  # Load font with appropriate mode
  profile_config = Validators::ProfileLoader.profile_info(@profile)
  unless profile_config
    unless @suppress_warnings
      puts "Error: Unknown profile '#{@profile}'"
      puts ""
      puts "Available profiles:"
      Validators::ProfileLoader.all_profiles.each do |name, config|
        puts "  #{name.to_s.ljust(20)} - #{config[:description]}"
      end
      puts ""
      puts "Use --list to see all available profiles"
    end
    return 1
  end

  mode = profile_config[:loading_mode].to_sym

  # Check if input is a collection
  if FontLoader.collection?(@input)
    validate_collection(mode)
  else
    validate_single_font(mode)
  end
rescue StandardError => e
  puts "Error: #{e.message}" unless @suppress_warnings
  puts e.backtrace.join("\n") if @verbose && !@suppress_warnings
  1
end