diff --git a/src/array.cpp b/src/array.cpp index ec2c97d0e..9cf7c6ce3 100644 --- a/src/array.cpp +++ b/src/array.cpp @@ -449,6 +449,20 @@ gb_internal void array_unordered_remove(Array *array, isize index) { array_pop(array); } +template +gb_internal void array_inject_at(Array *array, isize index, T value) { + GB_ASSERT(0 <= index); + + isize n = gb_max(array->count, index); + isize new_size = n+1; + array_resize(array, new_size); + + gb_memmove(array->data+index+1, array->data+index, gb_size_of(T)*(array->count-index-1)); + array->data[index] = value; +} + + + template diff --git a/src/main.cpp b/src/main.cpp index 51dade656..4dccd8f9c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3693,16 +3693,41 @@ int main(int arg_count, char const **arg_ptr) { String init_filename = {}; isize last_non_run_arg = args.count; + isize double_dash_pos = -1; for_array(i, args) { if (args[i] == "--") { + double_dash_pos = i; break; } + if (args[i] == "-help" || args[i] == "--help") { build_context.show_help = true; return print_show_help(args[0], command); } } + if (args.count > 2) { + // NOTE(bill): Allow for both `odin command path -flags` and `odin command -flags path` + // To do this, if the first argument after the command and last argument is NOT a flag, + // then put that last parameter first + isize end_arg = double_dash_pos >= 0 ? double_dash_pos : args.count-1; + if (args[1] == "bundle" && args.count > 4) { + if (string_starts_with(args[3], str_lit("-")) && + !string_starts_with(args[end_arg], str_lit("-"))) { + String possible_path = args[end_arg]; + array_ordered_remove(&args, end_arg); + array_inject_at(&args, 3, possible_path); + } + } else if (args.count > 3) { + if (string_starts_with(args[2], str_lit("-")) && + !string_starts_with(args[end_arg], str_lit("-"))) { + String possible_path = args[end_arg]; + array_ordered_remove(&args, end_arg); + array_inject_at(&args, 2, possible_path); + } + } + } + bool run_output = false; if (command == "run" || command == "test") { if (args.count < 3) {