Class: SyntaxTree::CLI::Check

Inherits:
Action
  • Object
show all
Defined in:
lib/syntax_tree/cli.rb

Overview

An action of the CLI that ensures that the filepath is formatted as expected.

Defined Under Namespace

Classes: UnformattedError

Instance Attribute Summary

Attributes inherited from Action

#options

Instance Method Summary collapse

Methods inherited from Action

#initialize

Constructor Details

This class inherits a constructor from SyntaxTree::CLI::Action

Instance Method Details

#failureObject



152
153
154
# File 'lib/syntax_tree/cli.rb', line 152

def failure
  warn("The listed files did not match the expected format.")
end

#run(item) ⇒ Object



133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/syntax_tree/cli.rb', line 133

def run(item)
  source = item.source
  formatted =
    item.handler.format(
      source,
      options.print_width,
      options: options.formatter_options
    )

  raise UnformattedError if source != formatted
rescue StandardError
  warn("[#{Color.yellow("warn")}] #{item.filepath}")
  raise
end

#successObject



148
149
150
# File 'lib/syntax_tree/cli.rb', line 148

def success
  puts("All files matched expected format.")
end