Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use proper exit code for the formatting command. #586

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/commands/format.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ module Mint
if flags.stdin
format_stdin
else
succeeded = nil
all_formatted = true

execute "Formatting files" do
succeeded = format_files
all_formatted = format_files
end
exit(1) unless succeeded

exit(1) if flags.check && !all_formatted
end
end

Expand All @@ -39,6 +41,8 @@ module Mint
Formatter.new(MintJson.parse_current.formatter_config).format(artifact)

terminal.puts formatted
rescue error : Error
error(error.to_terminal, terminal.position)
end

private def format_files
Expand All @@ -61,6 +65,7 @@ module Mint

if files.empty?
terminal.puts "Nothing to format!"
true
else
all_formatted = true

Expand All @@ -72,18 +77,18 @@ module Mint
Formatter.new(MintJson.parse_current.formatter_config).format(artifact)

unless formatted == File.read(file)
File.write(file, formatted) unless flags.check
terminal.puts "Formatted: #{file}"
if flags.check
terminal.puts "Not formatted: #{file}"
else
File.write(file, formatted)
terminal.puts "Formatted: #{file}"
end
all_formatted = false
end
end

if all_formatted
terminal.puts "All files are formatted!"
true
else
false
end
terminal.puts "All files are formatted!" if all_formatted
all_formatted
end
rescue error : Error
raise error
Expand Down