diff options
| author | hchac <dev@hchac.com> | 2024-03-03 22:49:34 -0500 |
|---|---|---|
| committer | hchac <dev@hchac.com> | 2024-03-03 22:49:34 -0500 |
| commit | 9950fb1ec1c98ddc9227936200be6a80fbc94c62 (patch) | |
| tree | 9754e9dce9c6093cbdfada3495092db91f2a71e6 | |
| parent | acb232ac94f46d6c1b81378ab0be0c5b2f91a446 (diff) | |
Include `-stdin` in args to parse.
| -rw-r--r-- | tools/odinfmt/main.odin | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin index e5ca79b..8e0886b 100644 --- a/tools/odinfmt/main.odin +++ b/tools/odinfmt/main.odin @@ -102,13 +102,22 @@ main :: proc() { os.exit(1) } - if res := flag.parse(args, os.args[1:len(os.args) - 1]); res != .None { + // When running `$ odinfmt some_odin_file.odin`, the file shouldn't be passed to + // `flag.parse`. But, when running `$ odinfmt -stdin`, we do want to pass `-stdin` to + // `flag.parse`. Need to check if last arg is a flag, and if so, include it in the + // args to parse. + args_to_parse := os.args[1:len(os.args) - 1] + path := os.args[len(os.args) - 1] + if strings.has_prefix(os.args[len(os.args) - 1], "-") { + args_to_parse = os.args[1:] + path = "." // if no file was specified, use current directory as the starting path to look for `odinfmt.json` + } + + if res := flag.parse(args, args_to_parse); res != .None { print_arg_error(os.args, res) os.exit(1) } - path := os.args[len(os.args) - 1] - tick_time := time.tick_now() write_failure := false @@ -204,3 +213,4 @@ main :: proc() { os.exit(1 if write_failure else 0) } + |