aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDanielGavin <danielgavin5@hotmail.com>2026-02-01 20:38:09 +0100
committerGitHub <noreply@github.com>2026-02-01 20:38:09 +0100
commit2d860c98337471d14d068089796b8c4ccede9405 (patch)
tree3352f9f0a0b55fc4c116940829087e5a91ce2a01
parente00ab8c20f10eea7974cc2bfabbb4c3bff20d8d8 (diff)
parentc542aa57c87c805f53bba89a1018861194f07127 (diff)
Merge pull request #1252 from gxhamster/custom-config-path
Feat: Add support for odinfmt custom config path
-rw-r--r--src/odin/format/format.odin20
-rw-r--r--tools/odinfmt/main.odin8
2 files changed, 27 insertions, 1 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,
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin
index f0ab79b..b44af5c 100644
--- a/tools/odinfmt/main.odin
+++ b/tools/odinfmt/main.odin
@@ -18,6 +18,7 @@ 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"`,
+ config: string `usage:"path to a config file"`
}
format_file :: proc(filepath: string, config: printer.Config, allocator := context.allocator) -> (string, bool) {
@@ -73,7 +74,12 @@ main :: proc() {
watermark : uint = 0
- config := format.find_config_file_or_default(args.path)
+ config: printer.Config
+ if args.config == "" {
+ config = format.find_config_file_or_default(args.path)
+ } else {
+ config = format.read_config_file_from_path_or_default(args.config)
+ }
if args.stdin {
data := make([dynamic]byte, arena_allocator)