aboutsummaryrefslogtreecommitdiff
path: root/core/flags/util.odin
diff options
context:
space:
mode:
Diffstat (limited to 'core/flags/util.odin')
-rw-r--r--core/flags/util.odin47
1 files changed, 36 insertions, 11 deletions
diff --git a/core/flags/util.odin b/core/flags/util.odin
index ce7e2e36c..b5e557cf6 100644
--- a/core/flags/util.odin
+++ b/core/flags/util.odin
@@ -1,9 +1,9 @@
package flags
-import "core:fmt"
+import "core:fmt"
@require import "core:os"
@require import "core:path/filepath"
-import "core:strings"
+import "core:strings"
/*
Parse any arguments into an annotated struct or exit if there was an error.
@@ -38,7 +38,7 @@ parse_or_exit :: proc(
error := parse(model, args, style, true, true, allocator, loc)
if error != nil {
- stderr := os.stream_from_handle(os.stderr)
+ stderr := os.to_stream(os.stderr)
if len(args) == 0 {
// No arguments entered, and there was an error; show the usage,
@@ -65,19 +65,44 @@ Inputs:
*/
@(optimization_mode="favor_size")
print_errors :: proc(data_type: typeid, error: Error, program: string, style: Parsing_Style = .Odin) {
- stderr := os.stream_from_handle(os.stderr)
- stdout := os.stream_from_handle(os.stdout)
+ stderr := os.to_stream(os.stderr)
+ stdout := os.to_stream(os.stdout)
switch specific_error in error {
case Parse_Error:
fmt.wprintfln(stderr, "[%T.%v] %s", specific_error, specific_error.reason, specific_error.message)
case Open_File_Error:
- fmt.wprintfln(stderr, "[%T#%i] Unable to open file with perms 0o%o in mode 0x%x: %s",
- specific_error,
- specific_error.errno,
- specific_error.perms,
- specific_error.mode,
- specific_error.filename)
+ if os.exists(specific_error.filename) {
+ flags: string
+ if specific_error.flags == {.Read} {
+ flags = "read-only"
+ } else if specific_error.flags == {.Write} {
+ flags = "write-only"
+ } else if specific_error.flags == {.Read, .Write} {
+ flags = "read/write"
+ }
+
+ if flags != "" {
+ fmt.wprintfln(stderr, "[%T#%i] Unable to open %q with perms 0o%o as %s",
+ specific_error,
+ specific_error.errno,
+ specific_error.filename,
+ u16(transmute(u32)specific_error.perms),
+ flags)
+ } else {
+ fmt.wprintfln(stderr, "[%T#%i] Unable to open %q with perms 0o%o and flags %v",
+ specific_error,
+ specific_error.errno,
+ specific_error.filename,
+ u16(transmute(u32)specific_error.perms),
+ specific_error.flags)
+ }
+ } else {
+ fmt.wprintfln(stderr, "[%T#%i] Unable to open %q. File not found",
+ specific_error,
+ specific_error.errno,
+ specific_error.filename)
+ }
case Validation_Error:
fmt.wprintfln(stderr, "[%T] %s", specific_error, specific_error.message)
case Help_Request: