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.
This commit is contained in:
gingerBill
2026-06-23 17:27:17 +01:00
parent c7d313b524
commit 07fee34419
2 changed files with 39 additions and 0 deletions

View File

@@ -449,6 +449,20 @@ gb_internal void array_unordered_remove(Array<T> *array, isize index) {
array_pop(array);
}
template <typename T>
gb_internal void array_inject_at(Array<T> *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 <typename T>

View File

@@ -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) {