Skip to content

Commit

Permalink
Merge pull request shwestrick#84 from kopecs/implied-stdio
Browse files Browse the repository at this point in the history
feat: Make `--stdio` the default for non-tty stdin
  • Loading branch information
shwestrick authored Mar 31, 2023
2 parents fb387c6 + 3587a96 commit e7138e2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,11 @@ to skip overwrite confirmations.
$ ./smlfmt --force src/smlfmt.mlb
```

To pass code through `stdin` and `stdout`, use the `--stdio` flag.
Additionally, code can be passed directly through `stdin` and `stdout`.
```bash
$ echo "val x = 5 val y = 6" | ./smlfmt --stdio
$ echo "val x = 5 val y = 6" | ./smlfmt
```
To force this behaviour, `--stdio` can be used.

### Command-line options

Expand All @@ -76,6 +77,8 @@ with syntax highlighting (if shown on terminal supporting ANSI colors).

`--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
9 changes: 9 additions & 0 deletions src/smlfmt.sml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ 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 Down

0 comments on commit e7138e2

Please sign in to comment.