aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIyaan Azeez <iyaanazeez757@gmail.com>2026-01-14 15:52:27 +0500
committerIyaan Azeez <iyaanazeez757@gmail.com>2026-01-14 15:52:27 +0500
commitc542aa57c87c805f53bba89a1018861194f07127 (patch)
tree73725fa89f61111e17eb032917db14b9a9bd6a44 /src
parent03d564b758d8c3942bcea7dc1eff6ad8211b71ea (diff)
Feat: Add support for odinfmt custom config path
Introduces a new argument to -config which allows a user to pass a json config for the formatter which is not neccesarilly in the path of the files we are formatting. For now the function will use the default_style if any errors occur. This was done due to that being the pattern in the source code. I think it would be useful to know if reading a config has failed or has defaulted to a default style but, I wanted to not include that in this.
Diffstat (limited to 'src')
-rw-r--r--src/odin/format/format.odin20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/odin/format/format.odin b/src/odin/format/format.odin
index e732d51..2ab6a94 100644
--- a/src/odin/format/format.odin
+++ b/src/odin/format/format.odin
@@ -49,6 +49,26 @@ find_config_file_or_default :: proc(path: string) -> printer.Config {
return config
}
+// Tries to read the config file from a given path instead
+// of searching for it up a directory tree of a path
+read_config_file_from_path_or_default :: proc(config_path: string) -> printer.Config {
+ path := config_path
+ ok: bool
+ if path, ok = filepath.abs(config_path); !ok {
+ return default_style
+ }
+ config := default_style
+ if (os.exists(path)) {
+ if data, ok := os.read_entire_file(path, context.temp_allocator); ok {
+ if json.unmarshal(data, &config) == nil {
+ return config
+ }
+ }
+ }
+
+ return default_style
+}
+
format :: proc(
filepath: string,
source: string,