Class: Foxtail::CLI::Commands::Tidy

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/foxtail/cli/commands/tidy.rb

Overview

Format FTL files with consistent style

Instance Method Summary collapse

Instance Method Details

#call(files:, write:, check:, diff:, with_junk:) ⇒ void

This method returns an undefined value.

Execute the tidy command

Parameters:

  • files (Array<String>)

    FTL files to format

  • write (Boolean)

    Write result back to source file

  • check (Boolean)

    Check if files are formatted (for CI)

  • diff (Boolean)

    Show diff instead of formatted output

  • with_junk (Boolean)

    Allow formatting files with syntax errors

Raises:



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/foxtail/cli/commands/tidy.rb', line 25

def call(files:, write:, check:, diff:, with_junk:, **)
  raise Foxtail::CLI::NoFilesError if files.empty?

  files_with_errors = []
  files_needing_format = []
  multiple_files = files.size > 1

  files.each do |file|
    result = process_file(file, write:, check:, diff:, with_junk:, multiple_files:)
    case result
    when :has_errors
      files_with_errors << file
    when :needs_format
      files_needing_format << file
    end
  end

  raise Foxtail::CLI::TidyError, files_with_errors unless files_with_errors.empty?
  raise Foxtail::CLI::TidyCheckError, files_needing_format if check && !files_needing_format.empty?
end