mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Minor changes to tools/odinfmt
This commit is contained in:
@@ -36,8 +36,7 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
|||||||
|
|
||||||
args := args;
|
args := args;
|
||||||
|
|
||||||
for true {
|
for {
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return .None;
|
return .None;
|
||||||
}
|
}
|
||||||
@@ -82,15 +81,11 @@ parse_args :: proc(ctx: ^Flag_Context, args: []string) -> Flag_Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if reflect.is_boolean(flag.type) {
|
if reflect.is_boolean(flag.type) {
|
||||||
tmp := true;
|
tmp: b64 = true;
|
||||||
mem.copy(flag.data, &tmp, flag.type.size);
|
mem.copy(flag.data, &tmp, flag.type.size);
|
||||||
flag.parsed = true;
|
flag.parsed = true;
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else if value == "" { // must be in the next argument
|
||||||
|
|
||||||
//must be in the next argument
|
|
||||||
if value == "" {
|
|
||||||
|
|
||||||
if len(args) == 0 {
|
if len(args) == 0 {
|
||||||
return .Arg_Error;
|
return .Arg_Error;
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-6
@@ -1,6 +1,7 @@
|
|||||||
package odinfmt
|
package odinfmt
|
||||||
|
|
||||||
import "core:os"
|
import "core:os"
|
||||||
|
import "core:odin/tokenizer"
|
||||||
import "core:odin/format"
|
import "core:odin/format"
|
||||||
import "core:fmt"
|
import "core:fmt"
|
||||||
import "core:strings"
|
import "core:strings"
|
||||||
@@ -23,14 +24,30 @@ print_help :: proc(args: []string) {
|
|||||||
fmt.eprintln();
|
fmt.eprintln();
|
||||||
}
|
}
|
||||||
|
|
||||||
print_arg_error :: proc(error: flag.Flag_Error) {
|
print_arg_error :: proc(args: []string, error: flag.Flag_Error) {
|
||||||
fmt.println(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) {
|
format_file :: proc(filepath: string) -> (string, bool) {
|
||||||
|
|
||||||
if data, ok := os.read_entire_file(filepath); ok {
|
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 {
|
} else {
|
||||||
return "", false;
|
return "", false;
|
||||||
}
|
}
|
||||||
@@ -63,7 +80,7 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if res := flag.parse(args, os.args[1:len(os.args) - 1]); res != .None {
|
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);
|
os.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +88,8 @@ main :: proc() {
|
|||||||
|
|
||||||
tick_time := time.tick_now();
|
tick_time := time.tick_now();
|
||||||
|
|
||||||
|
write_failure := false;
|
||||||
|
|
||||||
if os.is_file(path) {
|
if os.is_file(path) {
|
||||||
if _, ok := args.write.(bool); ok {
|
if _, ok := args.write.(bool); ok {
|
||||||
backup_path := strings.concatenate({path, "_bk"});
|
backup_path := strings.concatenate({path, "_bk"});
|
||||||
@@ -84,6 +103,7 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.eprintf("failed to write %v", path);
|
fmt.eprintf("failed to write %v", path);
|
||||||
|
write_failure = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if data, ok := format_file(path); ok {
|
if data, ok := format_file(path); ok {
|
||||||
@@ -112,6 +132,7 @@ main :: proc() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.eprintf("failed to format %v", file);
|
fmt.eprintf("failed to format %v", file);
|
||||||
|
write_failure = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -121,5 +142,5 @@ main :: proc() {
|
|||||||
os.exit(1);
|
os.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
os.exit(0);
|
os.exit(1 if write_failure else 0);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user