-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add formatting helper functions * small update to help command
- Loading branch information
1 parent
a76d1ba
commit 4ae6d4c
Showing
2 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |