Skip to content

Commit

Permalink
Remove --stdio flag
Browse files Browse the repository at this point in the history
Standard input and output are used if no files are given and standard
input is not connected to the terminal.

Closes shwestrick#84
  • Loading branch information
p-ouellette committed Apr 1, 2023
1 parent e7138e2 commit 7239597
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 33 deletions.
6 changes: 0 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ Additionally, code can be passed directly through `stdin` and `stdout`.
```bash
$ echo "val x = 5 val y = 6" | ./smlfmt
```
To force this behaviour, `--stdio` can be used.

### Command-line options

Expand All @@ -75,11 +74,6 @@ with syntax highlighting (if shown on terminal supporting ANSI colors).
`--preview-only` is the same as `--preview`, but also skips writing to file.
(This is incompatible with `--force`.)

`--stdio` reads SML input from `stdin`, and outputs the formatted SML
to `stdout`. (This is incompatible with file inputs and the flags above.)
If no incompatible flag is set and `stdin` is not a terminal, this is
the default.

`-mlb-path-var '<key> <value>'` for handling path variables, similar to
[MLton's path maps](http://mlton.org/MLBasisPathMap).

Expand Down
38 changes: 11 additions & 27 deletions src/smlfmt.sml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ val optionalArgDesc =
\ [--preview-only] show formatted output and skip file overwrite\n\
\ (incompatible with --force)\n\
\\n\
\ [--stdio] reads SML input from stdin and writes to stdout\n\
\ (incompatible with --force, --preview, --preview-only,\n\
\ and positional arguments)\n\
\\n\
\ [-max-width W] try to use at most <W> columns in each line\n\
\ (default 80)\n\
\\n\
Expand Down Expand Up @@ -68,7 +64,7 @@ val optionalArgDesc =


fun usage () =
"usage: smlfmt [ARGS] FILE ... FILE\n" ^ "Optional arguments:\n"
"usage: smlfmt [ARGS] [FILE ...]\n" ^ "Optional arguments:\n"
^ optionalArgDesc


Expand All @@ -93,16 +89,6 @@ val doHelp = CommandLineArgs.parseFlag "help"
val doCheck = CommandLineArgs.parseFlag "check"
val preview = CommandLineArgs.parseFlag "preview"
val previewOnly = CommandLineArgs.parseFlag "preview-only"
val stdio = CommandLineArgs.parseFlag "stdio"
val stdio =
stdio
orelse
(* if stdin is not a terminal and an incompabible flag is not set, take input from stdin *)
(not (Posix.ProcEnv.isatty Posix.FileSys.stdin)
andalso
not
(doForce orelse preview orelse previewOnly
orelse not (List.null inputfiles)))
val showPreview = preview orelse previewOnly

fun dbgprintln s =
Expand All @@ -117,10 +103,12 @@ val allows = AstAllows.make
}

val _ =
if doHelp orelse (not stdio andalso List.null inputfiles) then
(print (usage ()); OS.Process.exit OS.Process.success)
else
()
if
doHelp
orelse
(List.null inputfiles andalso Posix.ProcEnv.isatty Posix.FileSys.stdin)
then (print (usage ()); OS.Process.exit OS.Process.success)
else ()

fun warnWithMessage msg =
TCS.printErr (boldc Palette.yellow (msg ^ "\n"))
Expand All @@ -137,14 +125,10 @@ val _ =
()

val _ =
if
stdio
andalso
(doForce orelse preview orelse previewOnly orelse not (List.null inputfiles))
then
if List.null inputfiles andalso (doForce orelse preview orelse previewOnly) then
failWithMessage
"ERROR: --stdio incompatible with --force, --preview, --preview-only, \
\and passing input files"
"ERROR: --force, --preview, and --preview-only incompatible with \
\standard input"
else
()

Expand Down Expand Up @@ -402,7 +386,7 @@ val _ = List.app skipFile filesToSkip
val _ = List.app doFile filesToDo

val _ =
if stdio then
if List.null inputfiles then
let
val source = Source.loadFromStdin ()
val allTokens = Lexer.tokens allows source
Expand Down

0 comments on commit 7239597

Please sign in to comment.