diff options
| author | gingerBill <bill@gingerbill.org> | 2021-06-08 12:18:55 +0100 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-06-08 12:18:55 +0100 |
| commit | 286cb60c4506123fde203529043402744c82b7cd (patch) | |
| tree | 56173d6410dc8cdad16412420e582abd60ad399b /tools | |
| parent | 28e9a4f79c95784651649a799f594ab8c68aa207 (diff) | |
Minor changes to `tools/odinfmt`
Diffstat (limited to 'tools')
| -rw-r--r-- | tools/odinfmt/flag/flag.odin | 11 | ||||
| -rw-r--r-- | tools/odinfmt/main.odin | 33 |
2 files changed, 30 insertions, 14 deletions
diff --git a/tools/odinfmt/flag/flag.odin b/tools/odinfmt/flag/flag.odin index a943a5a1c..33c0bfe12 100644 --- a/tools/odinfmt/flag/flag.odin +++ b/tools/odinfmt/flag/flag.odin @@ -36,8 +36,7 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error { args := args;
- for true {
-
+ for {
if len(args) == 0 {
return .None;
}
@@ -82,15 +81,11 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error { }
if reflect.is_boolean(flag.type) {
- tmp := true;
+ tmp: b64 = true;
mem.copy(flag.data, &tmp, flag.type.size);
flag.parsed = true;
continue;
- } else
-
- //must be in the next argument
- if value == "" {
-
+ } else if value == "" { // must be in the next argument
if len(args) == 0 {
return .Arg_Error;
}
diff --git a/tools/odinfmt/main.odin b/tools/odinfmt/main.odin index 63e02269f..bc1b521ca 100644 --- a/tools/odinfmt/main.odin +++ b/tools/odinfmt/main.odin @@ -1,6 +1,7 @@ package odinfmt
import "core:os"
+import "core:odin/tokenizer"
import "core:odin/format"
import "core:fmt"
import "core:strings"
@@ -23,14 +24,30 @@ print_help :: proc(args: []string) { fmt.eprintln();
}
-print_arg_error :: proc(error: flag.Flag_Error) {
- fmt.println(error);
+print_arg_error :: proc(args: []string, error: flag.Flag_Error) {
+ switch error {
+ case .None:
+ print_help(args);
+ case .No_Base_Struct:
+ fmt.eprintln(args[0], "no base struct");
+ case .Arg_Error:
+ fmt.eprintln(args[0], "argument error");
+ case .Arg_Unsupported_Field_Type:
+ fmt.eprintln(args[0], "argument: unsupported field type");
+ case .Arg_Not_Defined:
+ fmt.eprintln(args[0], "argument: no defined");
+ case .Arg_Non_Optional:
+ fmt.eprintln(args[0], "argument: non optional");
+ case .Value_Parse_Error:
+ fmt.eprintln(args[0], "argument: value parse error");
+ case .Tag_Error:
+ fmt.eprintln(args[0], "argument: tag error");
+ }
}
format_file :: proc(filepath: string) -> (string, bool) {
-
if data, ok := os.read_entire_file(filepath); ok {
- return format.format(string(data), format.default_style);
+ return format.format(filepath, string(data), format.default_style);
} else {
return "", false;
}
@@ -63,7 +80,7 @@ main :: proc() { }
if res := flag.parse(args, os.args[1:len(os.args) - 1]); res != .None {
- print_arg_error(res);
+ print_arg_error(os.args, res);
os.exit(1);
}
@@ -71,6 +88,8 @@ main :: proc() { tick_time := time.tick_now();
+ write_failure := false;
+
if os.is_file(path) {
if _, ok := args.write.(bool); ok {
backup_path := strings.concatenate({path, "_bk"});
@@ -84,6 +103,7 @@ main :: proc() { }
} else {
fmt.eprintf("failed to write %v", path);
+ write_failure = true;
}
} else {
if data, ok := format_file(path); ok {
@@ -112,6 +132,7 @@ main :: proc() { }
} else {
fmt.eprintf("failed to format %v", file);
+ write_failure = true;
}
}
@@ -121,5 +142,5 @@ main :: proc() { os.exit(1);
}
- os.exit(0);
+ os.exit(1 if write_failure else 0);
}
|