package build import "base:runtime" import "core:fmt" import "core:os/os2" import "core:strings" Build_Errors :: enum { None, Unsuccessful_Exit, Unrecognized_Command, } Error :: union #shared_nil { os2.Error, runtime.Allocator_Error, Build_Errors, Maybe(string), } @(require_results) exec :: proc(command: string) -> Error { process := os2.process_start({command = strings.split(command, " ")}) or_return if !(os2.process_wait(process) or_return).success { return .Unsuccessful_Exit } return nil } @(require_results) handle_commands :: proc(commands: map[string][]proc() -> Error) -> Error { command_name := strings.join(os2.args[1:], " ") command := commands[command_name] if command == nil { builder := strings.builder_make(context.temp_allocator) or_return strings.write_string(&builder, "Unrecognized command ") strings.write_quoted_string(&builder, command_name) strings.write_string(&builder, "\nCommands:\n") for command_name, _ in commands { strings.write_string(&builder, "\t") strings.write_string(&builder, command_name) strings.write_string(&builder, "\n") } return Maybe(string)(strings.to_string(builder)) } for procedure, i in command { maybe_name: Maybe(string) for compare_name, compare_command in commands { if len(compare_command) == 1 && compare_command[0] == procedure { maybe_name = compare_name } } fmt.printf("[{}: {}/{}]", command_name, i + 1, len(command)) name, ok := maybe_name.? if ok { fmt.println(":", name) } else { fmt.println() } procedure() or_return } return nil } @(require_results) remove_multiple :: proc(files: ..string) -> Error { for file in files { fmt.printf("Removing {}... ", file) err := os2.remove(file) switch err { case nil: break case .Not_Exist: fmt.println("doesn't exist, skipping") continue case: fmt.println(err) return err } fmt.println("success") } return nil }