Skip to content

Commit

Permalink
Adding a formatting script.
Browse files Browse the repository at this point in the history
  • Loading branch information
codetalker7 committed May 29, 2024
1 parent 7c6f6a0 commit c258729
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dev/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
57 changes: 57 additions & 0 deletions dev/format.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()

using JuliaFormatter

help = """
Usage: format.jl [flags] [FILE/PATH]...
Formats the given julia files using the ColBERT formatting options.
If paths are given instead, it will format all *.jl files under
the paths. If nothing is given, all changed julia files are formatted.
-v, --verbose
Print the name of the files being formatted with relevant details.
-h, --help
Print this help message.
"""

options = Dict{Symbol, Bool}()
indices_to_remove = [] # used to delete options once processed

for (index, arg) in enumerate(ARGS)
if arg[1] != '-'
continue
end
if arg in ["-v", "--verbose"]
opt = :verbose
push!(indices_to_remove, index)
elseif arg in ["-h", "--help"]
opt = :help
push!(indices_to_remove, index)
else
error("Option $arg is not supported.")
end
options[opt] = true
end

# remove options from args
deleteat!(ARGS, indices_to_remove)

# print help message if asked
if haskey(options, :help)
write(stdout, help)
exit(0)
end

# otherwise format files
if isempty(ARGS)
filenames = readlines(`git ls-files "*.jl"`)
else
filenames = ARGS
end

write(stdout, "Formatting in progress.\n")
format(filenames; options...)

0 comments on commit c258729

Please sign in to comment.