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

feat(cli): add read-only flag #87

Merged
merged 2 commits into from
May 11, 2023
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
19 changes: 12 additions & 7 deletions src/smlfmt.sml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ val optionalArgDesc =
\\n\
\ [--preview-only] show formatted output and skip file overwrite\n\
\ (incompatible with --force)\n\
\ [--read-only] just parse files, without interactive confirmation\n\
\\n\
\ [-max-width W] try to use at most <W> columns in each line\n\
\ (default 80)\n\
Expand Down Expand Up @@ -85,6 +86,7 @@ val allowExtendedText =

val doDebug = CommandLineArgs.parseFlag "debug-engine"
val doForce = CommandLineArgs.parseFlag "force"
val doReadOnly = CommandLineArgs.parseFlag "read-only"
val doHelp = CommandLineArgs.parseFlag "help"
val doCheck = CommandLineArgs.parseFlag "check"
val preview = CommandLineArgs.parseFlag "preview"
Expand Down Expand Up @@ -259,13 +261,16 @@ fun formatOneSML
end

fun confirm () =
( print ("overwrite " ^ hfp ^ " [y/N]? ")
; case TextIO.inputLine TextIO.stdIn of
NONE => printErr ("skipping " ^ hfp ^ "\n")
| SOME line =>
if line = "y\n" orelse line = "Y\n" then writeOut ()
else printErr ("skipping " ^ hfp ^ "\n")
)
if doReadOnly then
()
else
( print ("overwrite " ^ hfp ^ " [y/N]? ")
; case TextIO.inputLine TextIO.stdIn of
NONE => printErr ("skipping " ^ hfp ^ "\n")
| SOME line =>
if line = "y\n" orelse line = "Y\n" then writeOut ()
else printErr ("skipping " ^ hfp ^ "\n")
)
in
if not showPreview then
()
Expand Down