From f30d1fd5037b30e2978f2324b351e122aeb7e34e Mon Sep 17 00:00:00 2001 From: despiegk Date: Tue, 26 Aug 2025 04:53:39 +0200 Subject: [PATCH] ... --- .../core/playcmds/play_osal_core.v | 236 ++++++++---------- 1 file changed, 102 insertions(+), 134 deletions(-) rename lib/{freeflowuniverse/herolib => }/core/playcmds/play_osal_core.v (54%) diff --git a/lib/freeflowuniverse/herolib/core/playcmds/play_osal_core.v b/lib/core/playcmds/play_osal_core.v similarity index 54% rename from lib/freeflowuniverse/herolib/core/playcmds/play_osal_core.v rename to lib/core/playcmds/play_osal_core.v index 875f0d98..79ea39d1 100644 --- a/lib/freeflowuniverse/herolib/core/playcmds/play_osal_core.v +++ b/lib/core/playcmds/play_osal_core.v @@ -9,55 +9,62 @@ pub fn play_osal_core(mut plbook PlayBook) ! { return } + // Process done actions play_done(mut plbook)! + + // Process environment actions play_env(mut plbook)! + + // Process execution actions play_exec(mut plbook)! + + // Process package actions play_package(mut plbook)! } fn play_done(mut plbook PlayBook) ! { - // Handle !!osal.done_set actions + // done_set actions mut done_set_actions := plbook.find(filter: 'osal.done_set')! for mut action in done_set_actions { mut p := action.params key := p.get('key')! - value := p.get('value')! + val := p.get('val')! - console.print_header('Setting done key: ${key} = ${value}') - osal.done_set(key, value)! + console.print_header('Setting done flag: ${key} = ${val}') + osal.done_set(key, val)! action.done = true } - // Handle !!osal.done_delete actions + // done_delete actions mut done_delete_actions := plbook.find(filter: 'osal.done_delete')! for mut action in done_delete_actions { mut p := action.params key := p.get('key')! - console.print_header('Deleting done key: ${key}') + console.print_header('Deleting done flag: ${key}') osal.done_delete(key)! action.done = true } - // Handle !!osal.done_reset actions + // done_reset actions mut done_reset_actions := plbook.find(filter: 'osal.done_reset')! for mut action in done_reset_actions { - console.print_header('Resetting all done keys') + console.print_header('Resetting all done flags') osal.done_reset()! action.done = true } - // Handle !!osal.done_print actions + // done_print actions mut done_print_actions := plbook.find(filter: 'osal.done_print')! for mut action in done_print_actions { - console.print_header('Printing all done keys') + console.print_header('Printing done flags') osal.done_print()! action.done = true } } fn play_env(mut plbook PlayBook) ! { - // Handle !!osal.env_set actions + // env_set actions mut env_set_actions := plbook.find(filter: 'osal.env_set')! for mut action in env_set_actions { mut p := action.params @@ -66,11 +73,15 @@ fn play_env(mut plbook PlayBook) ! { overwrite := p.get_default_true('overwrite') console.print_header('Setting environment variable: ${key}') - osal.env_set(key: key, value: value, overwrite: overwrite) + osal.env_set( + key: key + value: value + overwrite: overwrite + ) action.done = true } - // Handle !!osal.env_unset actions + // env_unset actions mut env_unset_actions := plbook.find(filter: 'osal.env_unset')! for mut action in env_unset_actions { mut p := action.params @@ -81,42 +92,36 @@ fn play_env(mut plbook PlayBook) ! { action.done = true } - // Handle !!osal.env_unset_all actions - mut env_unset_all_actions := plbook.find(filter: 'osal.env_unset_all')! - for mut action in env_unset_all_actions { - console.print_header('Unsetting all environment variables') - osal.env_unset_all() - action.done = true - } - - // Handle !!osal.env_set_all actions + // env_set_all actions mut env_set_all_actions := plbook.find(filter: 'osal.env_set_all')! for mut action in env_set_all_actions { mut p := action.params - clear_before_set := p.get_default_false('clear_before_set') - overwrite_if_exists := p.get_default_true('overwrite_if_exists') // Parse environment variables from parameters - mut env_map := map[string]string{} - param_map := p.get_map() - for key, value in param_map { + mut env_vars := map[string]string{} + // Get all parameters and filter out the control parameters + params_map := p.get_map() + for key, value in params_map { if key !in ['clear_before_set', 'overwrite_if_exists'] { - env_map[key] = value + env_vars[key] = value } } + clear_before_set := p.get_default_false('clear_before_set') + overwrite_if_exists := p.get_default_true('overwrite_if_exists') + console.print_header('Setting multiple environment variables') osal.env_set_all( - env: env_map + env: env_vars clear_before_set: clear_before_set overwrite_if_exists: overwrite_if_exists ) action.done = true } - // Handle !!osal.load_env_file actions - mut load_env_file_actions := plbook.find(filter: 'osal.load_env_file')! - for mut action in load_env_file_actions { + // env_load_file actions + mut env_load_file_actions := plbook.find(filter: 'osal.env_load_file')! + for mut action in env_load_file_actions { mut p := action.params file_path := p.get('file_path')! @@ -127,17 +132,16 @@ fn play_env(mut plbook PlayBook) ! { } fn play_exec(mut plbook PlayBook) ! { - // Handle !!osal.exec actions + // exec actions mut exec_actions := plbook.find(filter: 'osal.exec')! for mut action in exec_actions { mut p := action.params + cmd := p.get('cmd')! - console.print_header('Executing command: ${cmd}') - - mut job := osal.exec( - name: p.get_default('name', '')! + mut command := osal.Command{ cmd: cmd + name: p.get_default('name', '')! description: p.get_default('description', '')! timeout: p.get_int_default('timeout', 3600)! stdout: p.get_default_true('stdout') @@ -145,82 +149,50 @@ fn play_exec(mut plbook PlayBook) ! { raise_error: p.get_default_true('raise_error') ignore_error: p.get_default_false('ignore_error') work_folder: p.get_default('work_folder', '')! - scriptkeep: p.get_default_false('scriptkeep') - debug: p.get_default_false('debug') - shell: p.get_default_false('shell') retry: p.get_int_default('retry', 0)! interactive: p.get_default_true('interactive') - async: p.get_default_false('async') - )! - - // Store job output in done if specified - if output_key := p.get_default('output_key', '') { - if output_key != '' { - osal.done_set(output_key, job.output)! - } + debug: p.get_default_false('debug') } + // Parse environment variables if provided + if p.exists('environment') { + env_str := p.get('environment')! + // Parse environment string (format: "KEY1=value1,KEY2=value2") + env_pairs := env_str.split(',') + mut env_map := map[string]string{} + for pair in env_pairs { + if pair.contains('=') { + key := pair.all_before('=').trim_space() + value := pair.all_after('=').trim_space() + env_map[key] = value + } + } + command.environment = env_map.clone() + } + + // Parse ignore_error_codes if provided + if p.exists('ignore_error_codes') { + ignore_codes := p.get_list_int('ignore_error_codes')! + command.ignore_error_codes = ignore_codes + } + + console.print_header('Executing command: ${cmd}') + osal.exec(command)! action.done = true } - // Handle !!osal.exec_silent actions + // exec_silent actions mut exec_silent_actions := plbook.find(filter: 'osal.exec_silent')! for mut action in exec_silent_actions { mut p := action.params cmd := p.get('cmd')! console.print_header('Executing command silently: ${cmd}') - output := osal.execute_silent(cmd)! - - // Store output in done if specified - if output_key := p.get_default('output_key', '') { - if output_key != '' { - osal.done_set(output_key, output)! - } - } - + osal.execute_silent(cmd)! action.done = true } - // Handle !!osal.exec_debug actions - mut exec_debug_actions := plbook.find(filter: 'osal.exec_debug')! - for mut action in exec_debug_actions { - mut p := action.params - cmd := p.get('cmd')! - - console.print_header('Executing command with debug: ${cmd}') - output := osal.execute_debug(cmd)! - - // Store output in done if specified - if output_key := p.get_default('output_key', '') { - if output_key != '' { - osal.done_set(output_key, output)! - } - } - - action.done = true - } - - // Handle !!osal.exec_stdout actions - mut exec_stdout_actions := plbook.find(filter: 'osal.exec_stdout')! - for mut action in exec_stdout_actions { - mut p := action.params - cmd := p.get('cmd')! - - console.print_header('Executing command to stdout: ${cmd}') - output := osal.execute_stdout(cmd)! - - // Store output in done if specified - if output_key := p.get_default('output_key', '') { - if output_key != '' { - osal.done_set(output_key, output)! - } - } - - action.done = true - } - - // Handle !!osal.exec_interactive actions + // exec_interactive actions mut exec_interactive_actions := plbook.find(filter: 'osal.exec_interactive')! for mut action in exec_interactive_actions { mut p := action.params @@ -233,7 +205,7 @@ fn play_exec(mut plbook PlayBook) ! { } fn play_package(mut plbook PlayBook) ! { - // Handle !!osal.package_refresh actions + // package_refresh actions mut package_refresh_actions := plbook.find(filter: 'osal.package_refresh')! for mut action in package_refresh_actions { console.print_header('Refreshing package lists') @@ -241,71 +213,67 @@ fn play_package(mut plbook PlayBook) ! { action.done = true } - // Handle !!osal.package_install actions + // package_install actions mut package_install_actions := plbook.find(filter: 'osal.package_install')! for mut action in package_install_actions { mut p := action.params - // Get package name(s) - can be a single package or comma-separated list + // Support both 'name' parameter and arguments mut packages := []string{} + if p.exists('name') { packages << p.get('name')! } - if p.exists('names') { - packages = p.get_list('names')! - } - // Also check for positional arguments - for i in 0 .. 10 { - if arg := p.get_arg_default(i, '') { - if arg != '' { - packages << arg - } - } else { + + // Add any arguments (packages without keys) + mut i := 0 + for { + arg := p.get_arg_default(i, '')! + if arg == '' { break } + packages << arg + i++ } - if packages.len == 0 { - return error('No packages specified for installation') + for package in packages { + if package != '' { + console.print_header('Installing package: ${package}') + osal.package_install(package)! + } } - - package_name := packages.join(' ') - console.print_header('Installing packages: ${package_name}') - osal.package_install(package_name)! action.done = true } - // Handle !!osal.package_remove actions + // package_remove actions mut package_remove_actions := plbook.find(filter: 'osal.package_remove')! for mut action in package_remove_actions { mut p := action.params - // Get package name(s) - can be a single package or comma-separated list + // Support both 'name' parameter and arguments mut packages := []string{} + if p.exists('name') { packages << p.get('name')! } - if p.exists('names') { - packages = p.get_list('names')! - } - // Also check for positional arguments - for i in 0 .. 10 { - if arg := p.get_arg_default(i, '') { - if arg != '' { - packages << arg - } - } else { + + // Add any arguments (packages without keys) + mut i := 0 + for { + arg := p.get_arg_default(i, '')! + if arg == '' { break } + packages << arg + i++ } - if packages.len == 0 { - return error('No packages specified for removal') + for package in packages { + if package != '' { + console.print_header('Removing package: ${package}') + osal.package_remove(package)! + } } - - package_name := packages.join(' ') - console.print_header('Removing packages: ${package_name}') - osal.package_remove(package_name)! action.done = true } } \ No newline at end of file