Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/utils/trixi-format-file.jl
2055 views
1
#!/usr/bin/env julia
2
3
using Pkg
4
Pkg.activate(; temp = true, io = devnull)
5
Pkg.add(PackageSpec(name = "JuliaFormatter", version = "1.0.60"); preserve = PRESERVE_ALL,
6
io = devnull)
7
8
using JuliaFormatter: format_file
9
10
function main()
11
# Show help
12
if "-h" in ARGS || "--help" in ARGS
13
println("usage: trixi-format.jl PATH [PATH...]")
14
println()
15
println("positional arguments:")
16
println()
17
println(" PATH One or more paths (directories or files) to format. Default: '.'")
18
return nothing
19
end
20
21
file_list = ARGS
22
if isempty(ARGS)
23
exit(0)
24
end
25
non_formatted_files = Vector{String}()
26
for file in file_list
27
println("Checking file " * file)
28
if !format_file(file)
29
push!(non_formatted_files, file)
30
end
31
end
32
if isempty(non_formatted_files)
33
exit(0)
34
else
35
@error "Some files have not been formatted! Formatting has been applied, run 'git add -p' to update changes."
36
for file in non_formatted_files
37
println(file)
38
end
39
exit(1)
40
end
41
end
42
43
main()
44
45