Skip to content

Commit

Permalink
Add formatter functions (#37)
Browse files Browse the repository at this point in the history
* add formatting helper functions

* small update to help command
  • Loading branch information
andrewwinters5000 authored Apr 5, 2024
1 parent a76d1ba commit 4ae6d4c
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
43 changes: 43 additions & 0 deletions utils/trixisw-format-file.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env julia

using Pkg
Pkg.activate(; temp = true, io = devnull)
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.45"); preserve = PRESERVE_ALL,
io = devnull)

using JuliaFormatter: format_file

function main()
# Show help
if "-h" in ARGS || "--help" in ARGS
println("usage: trixisw-format.jl PATH [PATH...]")
println()
println("positional arguments:")
println()
println(" PATH One or more paths (directories or files) to format. Default: '.'")
return nothing
end

file_list = ARGS
if isempty(ARGS)
exit(0)
end
non_formatted_files = Vector{String}()
for file in file_list
println("Checking file " * file)
if !format_file(file)
push!(non_formatted_files, file)
end
end
if isempty(non_formatted_files)
exit(0)
else
@error "Some files have not been formatted! Formatting has been applied, run 'git add -p' to update changes."
for file in non_formatted_files
println(file)
end
exit(1)
end
end

main()
31 changes: 31 additions & 0 deletions utils/trixisw-format.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env julia

using Pkg
Pkg.activate(; temp = true, io = devnull)
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.45"); preserve = PRESERVE_ALL,
io = devnull)

using JuliaFormatter: format

function main()
# Show help
if "-h" in ARGS || "--help" in ARGS
println("usage: trixisw-format.jl PATH [PATH...]")
println()
println("positional arguments:")
println()
println(" PATH One or more paths (directories or files) to format. Default: '.'")
return nothing
end

# Set default path if none is given on command line
if isempty(ARGS)
paths = String["."]
else
paths = ARGS
end

return format(paths)
end

main()

0 comments on commit 4ae6d4c

Please sign in to comment.