summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorgodalming123 <68993177+godalming123@users.noreply.github.com>2025-09-18 19:49:51 +0100
committergodalming123 <68993177+godalming123@users.noreply.github.com>2025-09-18 19:49:51 +0100
commite6a3b84466e13abd74e81068ee7f06f7c4c569a3 (patch)
tree0ff487b85f98f287e820d9e2ecaef46dafd8e6b6 /tools
parent5d28d650d819277e6f640cad4ebb81a336372cb1 (diff)
Change the behavior back so that not specifying the path to format cuases an error unless odinfmt is formatting from stdin
Diffstat (limited to 'tools')
-rw-r--r--tools/odinfmt/main.odin24
1 files changed, 17 insertions, 7 deletions
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin
index 50777e2..3470ca5 100644
--- a/tools/odinfmt/main.odin
+++ b/tools/odinfmt/main.odin
@@ -3,6 +3,7 @@ package odinfmt
import "core:encoding/json"
import "core:flags"
import "core:fmt"
+import "core:io"
import "core:mem"
import "core:odin/tokenizer"
import "core:os"
@@ -12,6 +13,12 @@ import "core:time"
import "src:odin/format"
import "src:odin/printer"
+Args :: struct {
+ write: bool `args:"name=w" usage:"write the new format to file"`,
+ stdin: bool `usage:"formats code from standard input"`,
+ path: string `args:"pos=0" usage:"set the file or directory to format"`,
+}
+
format_file :: proc(filepath: string, config: printer.Config, allocator := context.allocator) -> (string, bool) {
if data, ok := os.read_entire_file(filepath, allocator); ok {
return format.format(filepath, string(data), config, {.Optional_Semicolons}, allocator)
@@ -44,16 +51,19 @@ main :: proc() {
init_global_temporary_allocator(mem.Megabyte * 20) //enough space for the walk
- args: struct {
- write: bool `args:"name=w" usage:"write the new format to file"`,
- stdin: bool `usage:"formats code from standard input"`,
- path: string `args:"pos=0" usage:"set the file or directory to format"`,
- }
+ args: Args
flags.parse_or_exit(&args, os.args)
- // if no file was specified, use current directory as the starting path to look for `odinfmt.json`
+ // only allow the path to not be specified when formatting from stdin
if args.path == "" {
- args.path = "."
+ if args.stdin {
+ // use current directory as the starting path to look for `odinfmt.json`
+ args.path = "."
+ } else {
+ fmt.fprint(os.stderr, "Missing path to format\n")
+ flags.write_usage(os.stream_from_handle(os.stderr), Args, os.args[0])
+ os.exit(1)
+ }
}
tick_time := time.tick_now()