From 8acbcd750b7ae3e8c0bb4b61407fc6c1d56119e2 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 31 Aug 2024 16:16:10 +0000 Subject: [PATCH 01/12] Enhancement: Runtime - [Breaking Change] New Env struct enabling commands to redirect out/err to provided streams #440 --- CHANGELOG.md | 4 + docs/_includes/content.md | 8 +- duckscript/src/runner.rs | 43 +++++--- duckscript/src/runner_test.rs | 98 ++++++++++++++----- duckscript/src/test/mod.rs | 4 + duckscript/src/types/command.rs | 3 + duckscript/src/types/command_test.rs | 2 + duckscript/src/types/env.rs | 42 ++++++++ duckscript/src/types/env_test.rs | 26 +++++ duckscript/src/types/mod.rs | 1 + duckscript/src/types/runtime.rs | 9 +- duckscript/src/types/runtime_test.rs | 18 +++- duckscript_cli/src/main.rs | 4 +- duckscript_sdk/src/lib_test.rs | 1 + .../src/sdk/internal/sdkdocs/mod.rs | 6 +- .../src/sdk/std/collections/array/mod.rs | 2 + .../sdk/std/collections/array_clear/mod.rs | 2 + .../src/sdk/std/collections/array_get/mod.rs | 2 + .../sdk/std/collections/array_length/mod.rs | 2 + .../src/sdk/std/collections/array_pop/mod.rs | 2 + .../src/sdk/std/collections/array_push/mod.rs | 2 + .../sdk/std/collections/array_remove/mod.rs | 2 + .../src/sdk/std/collections/array_set/mod.rs | 2 + .../src/sdk/std/collections/is_array/mod.rs | 2 + .../src/sdk/std/collections/is_map/mod.rs | 2 + .../src/sdk/std/collections/is_set/mod.rs | 2 + .../src/sdk/std/collections/map/mod.rs | 2 + .../src/sdk/std/collections/map_clear/mod.rs | 2 + .../src/sdk/std/collections/map_get/mod.rs | 2 + .../src/sdk/std/collections/map_keys/mod.rs | 2 + .../collections/map_load_properties/mod.rs | 2 + .../src/sdk/std/collections/map_put/mod.rs | 2 + .../src/sdk/std/collections/map_remove/mod.rs | 2 + .../src/sdk/std/collections/map_size/mod.rs | 2 + .../std/collections/map_to_properties/mod.rs | 2 + .../src/sdk/std/collections/range/mod.rs | 2 + .../std/collections/read_properties/mod.rs | 2 + .../src/sdk/std/collections/set/mod.rs | 2 + .../src/sdk/std/collections/set_clear/mod.rs | 2 + .../sdk/std/collections/set_contains/mod.rs | 2 + .../src/sdk/std/collections/set_put/mod.rs | 2 + .../src/sdk/std/collections/set_remove/mod.rs | 2 + .../src/sdk/std/collections/set_size/mod.rs | 2 + .../sdk/std/collections/set_to_array/mod.rs | 2 + .../std/collections/write_properties/mod.rs | 2 + .../sdk/std/debug/dump_instructions/mod.rs | 9 +- .../src/sdk/std/debug/dump_state/mod.rs | 7 +- .../src/sdk/std/debug/dump_variables/mod.rs | 7 +- duckscript_sdk/src/sdk/std/echo/mod.rs | 33 +++++-- .../src/sdk/std/env/env_to_map/mod.rs | 2 + .../std/env/print_current_directory/mod.rs | 28 +++++- duckscript_sdk/src/sdk/std/env/set_env/mod.rs | 2 + duckscript_sdk/src/sdk/std/eval/mod.rs | 4 +- .../src/sdk/std/flowcontrol/end/mod.rs | 3 + .../src/sdk/std/flowcontrol/forin/mod.rs | 3 + .../src/sdk/std/flowcontrol/function/mod.rs | 5 + .../src/sdk/std/flowcontrol/ifelse/mod.rs | 7 +- .../src/sdk/std/flowcontrol/while_mod/mod.rs | 4 + .../sdk/std/fs/gitignore_path_array/mod.rs | 2 + .../src/sdk/std/fs/glob_array/mod.rs | 2 + duckscript_sdk/src/sdk/std/fs/list/mod.rs | 40 ++++++-- duckscript_sdk/src/sdk/std/fs/print/mod.rs | 28 +++++- .../src/sdk/std/fs/read_bytes/mod.rs | 2 + .../src/sdk/std/fs/write_bytes/mod.rs | 2 + duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs | 2 + .../src/sdk/std/is_command_defined/mod.rs | 2 + duckscript_sdk/src/sdk/std/json/encode/mod.rs | 2 + duckscript_sdk/src/sdk/std/json/parse/mod.rs | 2 + .../src/sdk/std/lib/alias/set/mod.rs | 5 +- .../src/sdk/std/lib/alias/unset/mod.rs | 2 + .../src/sdk/std/lib/command/remove/mod.rs | 2 + duckscript_sdk/src/sdk/std/man/mod.rs | 16 +-- .../src/sdk/std/net/ftp/get_in_memory/mod.rs | 2 + .../src/sdk/std/net/ftp/list/mod.rs | 2 + .../src/sdk/std/net/ftp/nlst/mod.rs | 2 + duckscript_sdk/src/sdk/std/not/mod.rs | 11 ++- .../src/sdk/std/on_error/exit_on_error/mod.rs | 2 + .../sdk/std/on_error/get_last_error/mod.rs | 2 + .../std/on_error/get_last_error_line/mod.rs | 2 + .../std/on_error/get_last_error_source/mod.rs | 2 + .../src/sdk/std/on_error/on_error/mod.rs | 2 + .../src/sdk/std/on_error/set_error/mod.rs | 2 + duckscript_sdk/src/sdk/std/print/mod.rs | 33 +++++-- duckscript_sdk/src/sdk/std/println/mod.rs | 36 +++++-- .../src/sdk/std/process/exec/mod.rs | 2 + duckscript_sdk/src/sdk/std/release/mod.rs | 2 + duckscript_sdk/src/sdk/std/scope/clear/mod.rs | 2 + .../src/sdk/std/scope/pop_stack/mod.rs | 2 + .../src/sdk/std/scope/push_stack/mod.rs | 2 + .../src/sdk/std/semver/parse/mod.rs | 2 + .../src/sdk/std/string/base64_decode/mod.rs | 2 + .../src/sdk/std/string/base64_encode/mod.rs | 2 + .../src/sdk/std/string/bytes_to_string/mod.rs | 2 + .../src/sdk/std/string/split/mod.rs | 2 + .../src/sdk/std/string/string_to_bytes/mod.rs | 2 + .../src/sdk/std/test/test_directory/mod.rs | 4 +- .../src/sdk/std/test/test_file/mod.rs | 18 +++- .../src/sdk/std/var/get_all_var_names/mod.rs | 2 + .../src/sdk/std/var/get_by_name/mod.rs | 2 + .../src/sdk/std/var/is_defined/mod.rs | 2 + .../src/sdk/std/var/set_by_name/mod.rs | 2 + .../src/sdk/std/var/unset_all_vars/mod.rs | 2 + duckscript_sdk/src/test/mod.rs | 6 +- duckscript_sdk/src/types/command.rs | 4 +- duckscript_sdk/src/utils/condition.rs | 12 ++- duckscript_sdk/src/utils/condition_test.rs | 6 ++ duckscript_sdk/src/utils/eval.rs | 20 +++- duckscript_sdk/src/utils/eval_test.rs | 20 ++++ test/std/fs/gitignore_path_array_test.ds | 2 +- 109 files changed, 663 insertions(+), 111 deletions(-) create mode 100644 duckscript/src/types/env.rs create mode 100644 duckscript/src/types/env_test.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index f07a6782..f1b439da 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## CHANGELOG +### v0.10.0 + +* Enhancement: Runtime - \[Breaking Change\] New Env struct enabling commands to redirect out/err to provided streams #440 + ### v0.9.3 (2024-01-19) * Fix: if/else condition with a command that accepts empty values #390 diff --git a/docs/_includes/content.md b/docs/_includes/content.md index 3784fcdf..ca756b2b 100755 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -457,6 +457,7 @@ The run_with_context signature is as follows: /// * `instructions` - The entire list of instructions which make up the currently running script /// * `commands` - The currently known commands /// * `line` - The current instruction line number (global line number after including all scripts into one global script) +/// * `env` - The current runtime env with access to out/err writers, etc... fn run_with_context( &self, arguments: Vec, @@ -466,6 +467,7 @@ fn run_with_context( instructions: &Vec, commands: &mut Commands, line: usize, + env: &mut Env, ) -> CommandResult; ``` @@ -479,7 +481,7 @@ The duckscript cli basically embeds duckscript so you can look at it as a refere ```rust let mut context = Context::new(); duckscriptsdk::load(&mut context.commands)?; -runner::run_script_file(file, context)?; +runner::run_script_file(file, context, None)?; ``` That's it!
@@ -502,10 +504,10 @@ The following public functions are available: ```rust /// Executes the provided script with the given context -pub fn run_script(text: &str, context: Context) -> Result; +pub fn run_script(text: &str, context: Context, env: Option) -> Result; /// Executes the provided script file with the given context -pub fn run_script_file(file: &str, context: Context) -> Result; +pub fn run_script_file(file: &str, context: Context, env: Option) -> Result; ``` diff --git a/duckscript/src/runner.rs b/duckscript/src/runner.rs index 495c755b..2b9c2ba0 100644 --- a/duckscript/src/runner.rs +++ b/duckscript/src/runner.rs @@ -10,6 +10,7 @@ mod runner_test; use crate::expansion::{self, ExpandedValue}; use crate::parser; use crate::types::command::{CommandResult, Commands, GoToValue}; +use crate::types::env::Env; use crate::types::error::ScriptError; use crate::types::instruction::{ Instruction, InstructionMetaInfo, InstructionType, ScriptInstruction, @@ -26,17 +27,21 @@ enum EndReason { } /// Executes the provided script with the given context -pub fn run_script(text: &str, context: Context) -> Result { +pub fn run_script(text: &str, context: Context, env: Option) -> Result { match parser::parse_text(text) { - Ok(instructions) => run(instructions, context), + Ok(instructions) => run(instructions, context, env), Err(error) => Err(error), } } /// Executes the provided script file with the given context -pub fn run_script_file(file: &str, context: Context) -> Result { +pub fn run_script_file( + file: &str, + context: Context, + env: Option, +) -> Result { match parser::parse_file(file) { - Ok(instructions) => run(instructions, context), + Ok(instructions) => run(instructions, context, env), Err(error) => Err(error), } } @@ -58,7 +63,7 @@ pub fn repl(mut context: Context) -> Result { // add new instructions instructions.append(&mut new_instructions); - let runtime = create_runtime(instructions.clone(), context); + let runtime = create_runtime(instructions.clone(), context, None); let (updated_context, end_reason) = run_instructions(runtime, start, true)?; @@ -83,8 +88,12 @@ pub fn repl(mut context: Context) -> Result { } } -fn run(instructions: Vec, context: Context) -> Result { - let runtime = create_runtime(instructions, context); +fn run( + instructions: Vec, + context: Context, + env: Option, +) -> Result { + let runtime = create_runtime(instructions, context, env); match run_instructions(runtime, 0, false) { Ok((context, _)) => Ok(context), @@ -92,8 +101,8 @@ fn run(instructions: Vec, context: Context) -> Result, context: Context) -> Runtime { - let mut runtime = Runtime::new(context); +fn create_runtime(instructions: Vec, context: Context, env: Option) -> Runtime { + let mut runtime = Runtime::new(context, env); let mut line = 0; for instruction in &instructions { @@ -141,6 +150,7 @@ fn run_instructions( instructions, instruction, line, + &mut runtime.env, ); match command_result { @@ -185,6 +195,7 @@ fn run_instructions( instructions, error, meta_info.clone(), + &mut runtime.env, ) { return Err(ScriptError::Runtime(error, Some(meta_info.clone()))); }; @@ -249,6 +260,7 @@ fn run_on_error_instruction( instructions: &Vec, error: String, meta_info: InstructionMetaInfo, + env: &mut Env, ) -> Result<(), String> { if commands.exists("on_error") { let mut script_instruction = ScriptInstruction::new(); @@ -263,8 +275,15 @@ fn run_on_error_instruction( instruction_type: InstructionType::Script(script_instruction), }; - let (command_result, output_variable) = - run_instruction(commands, variables, state, instructions, instruction, 0); + let (command_result, output_variable) = run_instruction( + commands, + variables, + state, + instructions, + instruction, + 0, + env, + ); match command_result { CommandResult::Exit(output) => { @@ -288,6 +307,7 @@ pub fn run_instruction( instructions: &Vec, instruction: Instruction, line: usize, + env: &mut Env, ) -> (CommandResult, Option) { let mut output_variable = None; let command_result = match instruction.instruction_type { @@ -314,6 +334,7 @@ pub fn run_instruction( instructions, commands, line, + env, ) } else { command_instance.run(command_arguments) diff --git a/duckscript/src/runner_test.rs b/duckscript/src/runner_test.rs index 650a7567..4334df00 100644 --- a/duckscript/src/runner_test.rs +++ b/duckscript/src/runner_test.rs @@ -23,14 +23,14 @@ fn assert_end_reason_reached_end(end_reason: EndReason) { #[test] fn run_script_parse_error() { - let result = run_script("!bad", Context::new()); + let result = run_script("!bad", Context::new(), None); assert!(result.is_err()); } #[test] fn run_script_valid() { - let result = run_script("!print test", Context::new()); + let result = run_script("!print test", Context::new(), None); assert!(result.is_ok()); } @@ -40,21 +40,25 @@ fn run_script_runtime_error() { let mut context = Context::new(); let cmd_result = context.commands.set(Box::new(CrashCommand {})); assert!(cmd_result.is_ok()); - let result = run_script_file("./src/test/scripts/crash.ds", context); + let result = run_script_file("./src/test/scripts/crash.ds", context, None); assert!(result.is_err()); } #[test] fn run_script_file_valid() { - let result = run_script_file("./src/test/scripts/print_preprocessor.ds", Context::new()); + let result = run_script_file( + "./src/test/scripts/print_preprocessor.ds", + Context::new(), + None, + ); assert!(result.is_ok()); } #[test] fn run_no_instructions() { - let result = run(vec![], Context::new()); + let result = run(vec![], Context::new(), None); assert!(result.is_ok()); } @@ -71,7 +75,7 @@ fn run_empty_instructions() { instruction_type: InstructionType::Empty, }); - let result = run(instructions, Context::new()); + let result = run(instructions, Context::new(), None); assert!(result.is_ok()); } @@ -88,7 +92,7 @@ fn run_pre_processor_instructions() { instruction_type: InstructionType::PreProcess(PreProcessInstruction::new()), }); - let result = run(instructions, Context::new()); + let result = run(instructions, Context::new(), None); assert!(result.is_ok()); } @@ -105,7 +109,7 @@ fn run_no_command_script_instructions() { instruction_type: InstructionType::Script(ScriptInstruction::new()), }); - let result = run(instructions, Context::new()); + let result = run(instructions, Context::new(), None); assert!(result.is_ok()); } @@ -126,7 +130,7 @@ fn run_all_types_instructions() { instruction_type: InstructionType::Script(ScriptInstruction::new()), }); - let result = run(instructions, Context::new()); + let result = run(instructions, Context::new(), None); assert!(result.is_ok()); } @@ -148,7 +152,7 @@ fn create_runtime_with_labels() { instruction_type: InstructionType::Script(script_instruction), }); - let runtime = create_runtime(instructions, Context::new()); + let runtime = create_runtime(instructions, Context::new(), None); assert_eq!(runtime.label_to_line.get("test1"), Some(&0)); assert_eq!(runtime.label_to_line.get("test2"), Some(&1)); @@ -165,7 +169,7 @@ fn run_instructions_unknown_command() { instruction_type: InstructionType::Script(script_instruction), }); - let runtime = create_runtime(instructions, Context::new()); + let runtime = create_runtime(instructions, Context::new(), None); let context_result = run_instructions(runtime, 0, false); @@ -181,7 +185,7 @@ fn run_instructions_start_bigger_then_script() { instruction_type: InstructionType::Script(ScriptInstruction::new()), }); - let runtime = create_runtime(instructions, Context::new()); + let runtime = create_runtime(instructions, Context::new(), None); let context_result = run_instructions(runtime, 10, false); @@ -211,7 +215,7 @@ fn run_instructions_start_after_bad_command() { result = context.commands.set(Box::new(SetCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 1, false); @@ -239,7 +243,7 @@ fn run_instructions_exit_result_no_output() { let result = context.commands.set(Box::new(ExitCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -272,7 +276,7 @@ fn run_instructions_exit_result_with_string_output() { let result = context.commands.set(Box::new(ExitCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -308,7 +312,7 @@ fn run_instructions_exit_result_with_0_output() { let result = context.commands.set(Box::new(ExitCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -341,7 +345,7 @@ fn run_instructions_exit_result_with_error_code_output() { let result = context.commands.set(Box::new(ExitCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -364,7 +368,7 @@ fn run_instructions_error_result() { let result = context.commands.set(Box::new(ErrorCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -405,7 +409,7 @@ fn run_instructions_error_result_with_on_error() { result = context.commands.set(Box::new(OnErrorCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 2, false); @@ -435,7 +439,7 @@ fn run_instructions_crash_result() { let result = context.commands.set(Box::new(CrashCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -457,7 +461,7 @@ fn run_instructions_crash_result_repl_mode() { let result = context.commands.set(Box::new(CrashCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, true); @@ -477,7 +481,7 @@ fn run_instructions_continue_result_no_output() { instruction_type: InstructionType::Empty, }); - let runtime = create_runtime(instructions, Context::new()); + let runtime = create_runtime(instructions, Context::new(), None); let context_result = run_instructions(runtime, 0, false); @@ -512,7 +516,7 @@ fn run_instructions_continue_result_with_output() { let result = context.commands.set(Box::new(SetCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -565,7 +569,7 @@ fn run_instructions_goto_label_result_no_output() { result = context.commands.set(Box::new(GoToLabelCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -615,7 +619,7 @@ fn run_instructions_goto_label_result_with_output() { result = context.commands.set(Box::new(GoToLabelCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -668,7 +672,7 @@ fn run_instructions_goto_line_result_no_output() { result = context.commands.set(Box::new(GoToLineCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -718,7 +722,7 @@ fn run_instructions_goto_line_result_with_output() { result = context.commands.set(Box::new(GoToLineCommand {})); assert!(result.is_ok()); - let runtime = create_runtime(instructions, context); + let runtime = create_runtime(instructions, context, None); let context_result = run_instructions(runtime, 0, false); @@ -784,6 +788,7 @@ fn run_instruction_empty_instruction() { }; let mut context = Context::new(); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -792,6 +797,7 @@ fn run_instruction_empty_instruction() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -806,6 +812,7 @@ fn run_instruction_pre_processor_instruction() { }; let mut context = Context::new(); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -814,6 +821,7 @@ fn run_instruction_pre_processor_instruction() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -828,6 +836,7 @@ fn run_instruction_script_instruction_no_command() { }; let mut context = Context::new(); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -836,6 +845,7 @@ fn run_instruction_script_instruction_no_command() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -853,6 +863,7 @@ fn run_instruction_script_instruction_unknown_command() { }; let mut context = Context::new(); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -861,6 +872,7 @@ fn run_instruction_script_instruction_unknown_command() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -880,6 +892,7 @@ fn run_instruction_script_instruction_continue_result_no_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(SetCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -888,6 +901,7 @@ fn run_instruction_script_instruction_continue_result_no_output() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -909,6 +923,7 @@ fn run_instruction_script_instruction_continue_result_with_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(SetCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -917,6 +932,7 @@ fn run_instruction_script_instruction_continue_result_with_output() { &vec![], instruction, 0, + &mut env, ); assert_eq!(output_variable.unwrap(), "out"); @@ -939,6 +955,7 @@ fn run_instruction_script_instruction_exit_result_no_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(ExitCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -947,6 +964,7 @@ fn run_instruction_script_instruction_exit_result_no_output() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -968,6 +986,7 @@ fn run_instruction_script_instruction_exit_result_with_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(ExitCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -976,6 +995,7 @@ fn run_instruction_script_instruction_exit_result_with_output() { &vec![], instruction, 0, + &mut env, ); assert_eq!(output_variable.unwrap(), "out"); @@ -998,6 +1018,7 @@ fn run_instruction_script_instruction_goto_label_result_no_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(GoToLabelCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -1006,6 +1027,7 @@ fn run_instruction_script_instruction_goto_label_result_no_output() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -1027,6 +1049,7 @@ fn run_instruction_script_instruction_goto_label_result_with_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(GoToLabelCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -1035,6 +1058,7 @@ fn run_instruction_script_instruction_goto_label_result_with_output() { &vec![], instruction, 0, + &mut env, ); assert_eq!(output_variable.unwrap(), "out"); @@ -1057,6 +1081,7 @@ fn run_instruction_script_instruction_goto_line_result_no_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(GoToLineCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -1065,6 +1090,7 @@ fn run_instruction_script_instruction_goto_line_result_no_output() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -1086,6 +1112,7 @@ fn run_instruction_script_instruction_goto_line_result_with_output() { let mut context = Context::new(); let result = context.commands.set(Box::new(GoToLineCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -1094,6 +1121,7 @@ fn run_instruction_script_instruction_goto_line_result_with_output() { &vec![], instruction, 0, + &mut env, ); assert_eq!(output_variable.unwrap(), "out"); @@ -1116,6 +1144,7 @@ fn run_instruction_script_instruction_error_result() { let mut context = Context::new(); let result = context.commands.set(Box::new(ErrorCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -1124,6 +1153,7 @@ fn run_instruction_script_instruction_error_result() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_none()); @@ -1145,6 +1175,7 @@ fn run_instruction_control_characters() { let mut context = Context::new(); let result = context.commands.set(Box::new(SetCommand {})); assert!(result.is_ok()); + let mut env = Env::default(); let (command_result, output_variable) = run_instruction( &mut context.commands, @@ -1153,6 +1184,7 @@ fn run_instruction_control_characters() { &vec![], instruction, 0, + &mut env, ); assert!(output_variable.is_some()); @@ -1167,6 +1199,7 @@ fn run_on_error_instruction_no_command() { let mut commands = Commands::new(); let mut variables = HashMap::new(); let mut state = HashMap::new(); + let mut env = Env::default(); let result = run_on_error_instruction( &mut commands, @@ -1175,6 +1208,7 @@ fn run_on_error_instruction_no_command() { &vec![], "error".to_string(), InstructionMetaInfo::new(), + &mut env, ); assert!(result.is_ok()); @@ -1185,6 +1219,7 @@ fn run_on_error_instruction_unknown_command() { let mut commands = Commands::new(); let mut variables = HashMap::new(); let mut state = HashMap::new(); + let mut env = Env::default(); commands .aliases @@ -1197,6 +1232,7 @@ fn run_on_error_instruction_unknown_command() { &vec![], "error".to_string(), InstructionMetaInfo::new(), + &mut env, ); assert!(result.is_ok()); @@ -1207,6 +1243,7 @@ fn run_on_error_instruction_exit_response() { let mut commands = Commands::new(); let mut variables = HashMap::new(); let mut state = HashMap::new(); + let mut env = Env::default(); let set_result = commands.set(Box::new(ExitCommand {})); assert!(set_result.is_ok()); @@ -1221,6 +1258,7 @@ fn run_on_error_instruction_exit_response() { &vec![], "error".to_string(), InstructionMetaInfo::new(), + &mut env, ); assert!(result.is_err()); @@ -1231,6 +1269,7 @@ fn run_on_error_instruction_crash_response() { let mut commands = Commands::new(); let mut variables = HashMap::new(); let mut state = HashMap::new(); + let mut env = Env::default(); let set_result = commands.set(Box::new(CrashCommand {})); assert!(set_result.is_ok()); @@ -1245,6 +1284,7 @@ fn run_on_error_instruction_crash_response() { &vec![], "error".to_string(), InstructionMetaInfo::new(), + &mut env, ); assert!(result.is_err()); @@ -1255,6 +1295,7 @@ fn run_on_error_instruction_continue_response() { let mut commands = Commands::new(); let mut variables = HashMap::new(); let mut state = HashMap::new(); + let mut env = Env::default(); let set_result = commands.set(Box::new(SetCommand {})); assert!(set_result.is_ok()); @@ -1269,6 +1310,7 @@ fn run_on_error_instruction_continue_response() { &vec![], "error".to_string(), InstructionMetaInfo::new(), + &mut env, ); assert!(result.is_ok()); @@ -1279,6 +1321,7 @@ fn run_on_error_instruction_error_response() { let mut commands = Commands::new(); let mut variables = HashMap::new(); let mut state = HashMap::new(); + let mut env = Env::default(); let set_result = commands.set(Box::new(ErrorCommand {})); assert!(set_result.is_ok()); @@ -1293,6 +1336,7 @@ fn run_on_error_instruction_error_response() { &vec![], "error".to_string(), InstructionMetaInfo::new(), + &mut env, ); assert!(result.is_ok()); diff --git a/duckscript/src/test/mod.rs b/duckscript/src/test/mod.rs index eeaae3fd..b1c05c41 100644 --- a/duckscript/src/test/mod.rs +++ b/duckscript/src/test/mod.rs @@ -1,4 +1,5 @@ use crate::types::command::{Command, CommandResult, Commands, GoToValue}; +use crate::types::env::Env; use crate::types::instruction::{ Instruction, InstructionType, PreProcessInstruction, ScriptInstruction, }; @@ -76,6 +77,7 @@ impl Command for OnErrorCommand { _instructions: &Vec, _commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { let mut index = 0; for argument in arguments { @@ -83,6 +85,8 @@ impl Command for OnErrorCommand { variables.insert(index.to_string(), argument.clone()); } + writeln!(env.out, "{}", "test").unwrap(); + CommandResult::Continue(None) } } diff --git a/duckscript/src/types/command.rs b/duckscript/src/types/command.rs index 84d6e8b2..3134fe06 100644 --- a/duckscript/src/types/command.rs +++ b/duckscript/src/types/command.rs @@ -7,6 +7,7 @@ #[path = "./command_test.rs"] mod command_test; +use crate::types::env::Env; use crate::types::error::ScriptError; use crate::types::instruction::Instruction; use crate::types::runtime::StateValue; @@ -75,6 +76,7 @@ pub trait Command { /// * `instructions` - The entire list of instructions which make up the currently running script /// * `commands` - The currently known commands /// * `line` - The current instruction line number (global line number after including all scripts into one global script) + /// * `env` - The current runtime env with access to out/err writers, etc... fn run_with_context( &self, _arguments: Vec, @@ -84,6 +86,7 @@ pub trait Command { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { CommandResult::Crash(format!("Not implemented for command: {}", &self.name()).to_string()) } diff --git a/duckscript/src/types/command_test.rs b/duckscript/src/types/command_test.rs index 6d665580..fbd8976e 100644 --- a/duckscript/src/types/command_test.rs +++ b/duckscript/src/types/command_test.rs @@ -82,6 +82,7 @@ fn command_default_run_with_context() { } let mut context = Context::new(); + let mut env = Env::default(); let command = InnerCommand {}; let result = command.run_with_context( vec![], @@ -91,6 +92,7 @@ fn command_default_run_with_context() { &vec![], &mut context.commands, 0, + &mut env, ); test::validate_continue_result(&result, None); diff --git a/duckscript/src/types/env.rs b/duckscript/src/types/env.rs new file mode 100644 index 00000000..340b53e6 --- /dev/null +++ b/duckscript/src/types/env.rs @@ -0,0 +1,42 @@ +//! # env +//! +//! The runtime env structures. +//! + +#[cfg(test)] +#[path = "./env_test.rs"] +mod env_test; + +use std::io::{stderr, stdout, Write}; + +/// The runtime env +pub struct Env { + /// The output writer + pub out: Box, + /// The error writer + pub err: Box, +} + +impl Env { + /// Creates and returns a new instance. + pub fn default() -> Env { + Env { + out: Box::new(stdout()), + err: Box::new(stderr()), + } + } + + /// Creates and returns a new instance. + pub fn new(out: Option>, err: Option>) -> Env { + Env { + out: match out { + Some(value) => value, + None => Box::new(stdout()), + }, + err: match err { + Some(value) => value, + None => Box::new(stderr()), + }, + } + } +} diff --git a/duckscript/src/types/env_test.rs b/duckscript/src/types/env_test.rs new file mode 100644 index 00000000..c66ef5fc --- /dev/null +++ b/duckscript/src/types/env_test.rs @@ -0,0 +1,26 @@ +use super::*; + +fn validate_env(env: &mut Env) { + writeln!(env.out, "test").unwrap(); +} + +#[test] +fn env_default() { + let mut env = Env::default(); + + validate_env(&mut env); +} + +#[test] +fn env_new_none() { + let mut env = Env::new(None, None); + + validate_env(&mut env); +} + +#[test] +fn env_new_with_values() { + let mut env = Env::new(Some(Box::new(stdout())), Some(Box::new(stdout()))); + + validate_env(&mut env); +} diff --git a/duckscript/src/types/mod.rs b/duckscript/src/types/mod.rs index 0553f3a2..0f92cd8f 100755 --- a/duckscript/src/types/mod.rs +++ b/duckscript/src/types/mod.rs @@ -3,6 +3,7 @@ //! All duckscript types. //! pub mod command; +pub mod env; pub mod error; pub mod instruction; pub mod runtime; diff --git a/duckscript/src/types/runtime.rs b/duckscript/src/types/runtime.rs index a70b41fb..fa1d748a 100644 --- a/duckscript/src/types/runtime.rs +++ b/duckscript/src/types/runtime.rs @@ -8,6 +8,7 @@ mod runtime_test; use crate::types::command::Commands; +use crate::types::env::Env; use crate::types::instruction::Instruction; use std::any::Any; use std::cell::RefCell; @@ -75,15 +76,21 @@ pub struct Runtime { pub label_to_line: HashMap, /// The runtime context pub context: Context, + /// The runtime env + pub env: Env, } impl Runtime { /// Creates and returns a new instance. - pub fn new(context: Context) -> Runtime { + pub fn new(context: Context, env: Option) -> Runtime { Runtime { instructions: None, label_to_line: HashMap::new(), context, + env: match env { + Some(value) => value, + None => Env::default(), + }, } } } diff --git a/duckscript/src/types/runtime_test.rs b/duckscript/src/types/runtime_test.rs index ab529c20..091eea86 100644 --- a/duckscript/src/types/runtime_test.rs +++ b/duckscript/src/types/runtime_test.rs @@ -10,11 +10,25 @@ fn context_new() { } #[test] -fn runtime_new() { +fn runtime_new_no_env() { let mut context = Context::new(); context.variables.insert("a".to_string(), "b".to_string()); - let runtime = Runtime::new(context); + let runtime = Runtime::new(context, None); + + assert!(runtime.instructions.is_none()); + assert!(runtime.label_to_line.is_empty()); + assert!(runtime.context.variables.contains_key("a")); +} + +#[test] +fn runtime_new_with_env() { + let mut context = Context::new(); + context.variables.insert("a".to_string(), "b".to_string()); + + let env = Env::default(); + + let runtime = Runtime::new(context, Some(env)); assert!(runtime.instructions.is_none()); assert!(runtime.label_to_line.is_empty()); diff --git a/duckscript_cli/src/main.rs b/duckscript_cli/src/main.rs index 4ddb9023..91f64585 100755 --- a/duckscript_cli/src/main.rs +++ b/duckscript_cli/src/main.rs @@ -100,9 +100,9 @@ fn run_script(value: &str, is_file: bool) -> Result<(), ScriptError> { let context = create_context()?; if is_file { - runner::run_script_file(value, context)?; + runner::run_script_file(value, context, None)?; } else { - runner::run_script(value, context)?; + runner::run_script(value, context, None)?; } Ok(()) diff --git a/duckscript_sdk/src/lib_test.rs b/duckscript_sdk/src/lib_test.rs index 14311bf1..73c51141 100644 --- a/duckscript_sdk/src/lib_test.rs +++ b/duckscript_sdk/src/lib_test.rs @@ -36,6 +36,7 @@ fn test_scripts() { unset_env DUCKSCRIPT_TEST_RUST "#, context, + None, ); assert!(result.is_ok()); diff --git a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs index 62e12025..c968774b 100755 --- a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs +++ b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs @@ -2,6 +2,7 @@ use crate::utils::io; use crate::utils::pckg; use duckscript::types::command::Commands; use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -41,6 +42,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Documentation output directory not provided.".to_string()) @@ -85,7 +87,9 @@ impl Command for CommandImpl { } }; } else { - println!("Command: {} skipped.", &name); + if let Err(error) = writeln!(env.out, "Command: {} skipped.", &name) { + return CommandResult::Error(error.to_string()); + } } } diff --git a/duckscript_sdk/src/sdk/std/collections/array/mod.rs b/duckscript_sdk/src/sdk/std/collections/array/mod.rs index e027a9d9..ce188012 100755 --- a/duckscript_sdk/src/sdk/std/collections/array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let mut array = vec![]; diff --git a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs index 4db7be1c..e3f5a03e 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs index 5f4cf689..a2522e5b 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_list}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { CommandResult::Error("Array handle or item index not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs index 91336936..96ad0ba9 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -48,6 +49,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs index 48a5e910..e47f3d13 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_list}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs index 1ef1aedb..1c6eb1b5 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -48,6 +49,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs index 933a6994..737e9bce 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { CommandResult::Error("Invalid input provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs index ae110240..b81a8095 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 3 { CommandResult::Error("Invalid input provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs index 96ec6af0..d6568b23 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs index 020db202..3994b0b1 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs index a9e63547..4d85b3f3 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map/mod.rs b/duckscript_sdk/src/sdk/std/collections/map/mod.rs index 2ac531df..5b7ce46c 100755 --- a/duckscript_sdk/src/sdk/std/collections/map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let map = HashMap::new(); diff --git a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs index 206e9f6a..56d1c8c6 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs index ae07a916..dcbaee89 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_map}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs index 3894e3a9..9b8b73be 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs index ac2b1e8f..f841801d 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use java_properties::read; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { CommandResult::Error("Map handle and/or properties text not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs index 538cb2c2..1c224957 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs index 89ef905b..c4f31b22 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_map}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs index 87c56231..dcce577d 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs index e915ffe4..ff99dafc 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_as_string, get_handles_sub_state}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use java_properties::write; @@ -46,6 +47,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/range/mod.rs b/duckscript_sdk/src/sdk/std/collections/range/mod.rs index a4e77c56..8fd845f0 100755 --- a/duckscript_sdk/src/sdk/std/collections/range/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/range/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { CommandResult::Error("Invalid arguments provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs index 0c679d0d..0606c316 100755 --- a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use java_properties::read; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 1 { CommandResult::Error("Missing properties text argument.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/set/mod.rs b/duckscript_sdk/src/sdk/std/collections/set/mod.rs index 757c9f74..aa747315 100755 --- a/duckscript_sdk/src/sdk/std/collections/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::{HashMap, HashSet}; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let mut set = HashSet::new(); diff --git a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs index 4d6130f1..786834ea 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs index afb8c80c..344eb92b 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs index 659f698c..6335ea28 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs index 497c7cd6..e608b31c 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs index b2b5a844..b110f816 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs index 66eefae3..3e489c7b 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs index f0d9f110..a5b951fd 100755 --- a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use java_properties::write; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 1 { CommandResult::Error("Missing properties names.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs index c3ae03cd..7723effb 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,12 +44,16 @@ impl Command for CommandImpl { instructions: &Vec, _commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { let string_value = format!("{:#?}", instructions).to_string(); if output_variable.is_none() { - println!("{}", string_value); - } + match writeln!(env.out, "{}", string_value) { + Ok(_) => (), + Err(error) => return CommandResult::Error(error.to_string()), + } + }; CommandResult::Continue(Some(string_value)) } diff --git a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs index 57cc534f..c86ce94b 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,11 +44,15 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { let string_value = format!("{:#?}", state).to_string(); if output_variable.is_none() { - println!("{}", string_value); + match writeln!(env.out, "{}", &string_value) { + Ok(_) => (), + Err(error) => return CommandResult::Error(error.to_string()), + }; } CommandResult::Continue(Some(string_value)) diff --git a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs index 9f64e712..a3549e7b 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,11 +44,15 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { let string_value = format!("{:#?}", variables).to_string(); if output_variable.is_none() { - println!("{}", string_value); + match writeln!(env.out, "{}", string_value) { + Ok(_) => (), + Err(error) => return CommandResult::Error(error.to_string()), + }; } CommandResult::Continue(Some(string_value)) diff --git a/duckscript_sdk/src/sdk/std/echo/mod.rs b/duckscript_sdk/src/sdk/std/echo/mod.rs index 9fb3f86d..80831dfc 100755 --- a/duckscript_sdk/src/sdk/std/echo/mod.rs +++ b/duckscript_sdk/src/sdk/std/echo/mod.rs @@ -1,5 +1,9 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; +use duckscript::types::instruction::Instruction; +use duckscript::types::runtime::StateValue; +use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,14 +31,31 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn requires_context(&self) -> bool { + true + } + + fn run_with_context( + &self, + arguments: Vec, + _state: &mut HashMap, + _variables: &mut HashMap, + _output_variable: Option, + _instructions: &Vec, + _commands: &mut Commands, + _line: usize, + env: &mut Env, + ) -> CommandResult { for argument in &arguments { - print!("{} ", argument); + if let Err(error) = write!(env.out, "{}", argument) { + return CommandResult::Error(error.to_string()); + } } - println!(); - - CommandResult::Continue(Some(arguments.len().to_string())) + match writeln!(env.out, "") { + Ok(_) => CommandResult::Continue(Some(arguments.len().to_string())), + Err(error) => CommandResult::Error(error.to_string()), + } } } diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs index 73078eba..8deaa867 100755 --- a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let all_vars = env::vars(); let mut map = HashMap::new(); diff --git a/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs b/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs index f6923007..1091376e 100755 --- a/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs @@ -1,5 +1,9 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; +use duckscript::types::instruction::Instruction; +use duckscript::types::runtime::StateValue; +use std::collections::HashMap; use std::env; #[cfg(test)] @@ -28,12 +32,28 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn requires_context(&self) -> bool { + true + } + + fn run_with_context( + &self, + _arguments: Vec, + _state: &mut HashMap, + _variables: &mut HashMap, + _output_variable: Option, + _instructions: &Vec, + _commands: &mut Commands, + _line: usize, + env: &mut Env, + ) -> CommandResult { match env::current_dir() { Ok(directory_path) => { let directory = directory_path.display(); - println!("{}", &directory); - CommandResult::Continue(Some(directory.to_string())) + match writeln!(env.out, "{}", &directory) { + Ok(_) => CommandResult::Continue(Some(directory.to_string())), + Err(error) => CommandResult::Error(error.to_string()), + } } Err(_) => CommandResult::Continue(None), } diff --git a/duckscript_sdk/src/sdk/std/env/set_env/mod.rs b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs index fa5b9f4b..27929e5c 100755 --- a/duckscript_sdk/src/sdk/std/env/set_env/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_as_string, get_handles_sub_state}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing environment variable name and value.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/eval/mod.rs b/duckscript_sdk/src/sdk/std/eval/mod.rs index 80d056d5..41acab45 100755 --- a/duckscript_sdk/src/sdk/std/eval/mod.rs +++ b/duckscript_sdk/src/sdk/std/eval/mod.rs @@ -1,5 +1,6 @@ use crate::utils::{eval, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,8 +44,9 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { - eval::eval_with_error(&arguments, state, variables, commands) + eval::eval_with_error(&arguments, state, variables, commands, env) } } diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs index ee0bcc37..e679e976 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::flowcontrol::get_line_key; use crate::utils::state::get_core_sub_state_for_command; use duckscript::runner; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::{ Instruction, InstructionMetaInfo, InstructionType, ScriptInstruction, }; @@ -69,6 +70,7 @@ impl Command for CommandImpl { instructions: &Vec, commands: &mut Commands, line: usize, + env: &mut Env, ) -> CommandResult { match get_command(line, state) { Some(command) => { @@ -88,6 +90,7 @@ impl Command for CommandImpl { instructions, instruction, line, + env, ); command_result diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs index f4937e5d..17688f5a 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs @@ -5,6 +5,7 @@ use crate::utils::state::{ }; use crate::utils::{instruction_query, pckg}; use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -322,6 +323,7 @@ impl Command for ForInCommand { instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() != 3 || arguments[1] != "in" { CommandResult::Error("Invalid for/in statement".to_string()) @@ -424,6 +426,7 @@ impl Command for EndForInCommand { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { match pop_call_info_for_line(line, state, true) { Some(call_info) => { diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs index 6feac336..b8693721 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs @@ -3,6 +3,7 @@ use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{annotation, instruction_query, pckg, scope}; use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -299,6 +300,7 @@ impl Command for FunctionCommand { instructions: &Vec, commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing function name.".to_string()) @@ -417,6 +419,7 @@ impl Command for FunctionCommand { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { run_call( @@ -499,6 +502,7 @@ impl Command for EndFunctionCommand { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { let line_context_name = get_line_context_name(state); @@ -560,6 +564,7 @@ impl Command for ReturnCommand { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { let line_context_name = get_line_context_name(state); diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs index 6c27160c..d85d03e3 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs @@ -3,6 +3,7 @@ use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{condition, instruction_query, pckg}; use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -356,6 +357,7 @@ impl Command for IfCommand { instructions: &Vec, commands: &mut Commands, line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing condition".to_string()) @@ -373,6 +375,7 @@ impl Command for IfCommand { state, variables, commands, + env, ) { Ok(passed) => { if passed { @@ -460,6 +463,7 @@ impl Command for ElseIfCommand { instructions: &Vec, commands: &mut Commands, line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing condition".to_string()) @@ -472,7 +476,7 @@ impl Command for ElseIfCommand { } else { let if_else_info = call_info.meta_info.clone(); let line_context_name = get_line_context_name(state); - match condition::eval_condition(arguments, instructions, state, variables, commands) { + match condition::eval_condition(arguments, instructions, state, variables, commands, env) { Ok(passed) => { if passed { let next_line = if call_info.else_line_index + 1 < if_else_info.else_lines.len() { @@ -558,6 +562,7 @@ impl Command for ElseCommand { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { match pop_call_info_for_line(line, state) { Some(call_info) => { diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs index ccbc7bc2..6aea076e 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs @@ -3,6 +3,7 @@ use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{condition, instruction_query, pckg}; use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -279,6 +280,7 @@ impl Command for WhileCommand { instructions: &Vec, commands: &mut Commands, line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing condition".to_string()) @@ -296,6 +298,7 @@ impl Command for WhileCommand { state, variables, commands, + env, ) { Ok(passed) => { if passed { @@ -367,6 +370,7 @@ impl Command for EndWhileCommand { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { match pop_call_info_for_line(line, state) { Some(call_info) => { diff --git a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs index cdcdf812..bd6c889d 100755 --- a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use fsio::path::from_path::FromPath; @@ -46,6 +47,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Root directory not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs index 8ccc645c..a662912e 100755 --- a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use fsio::path::from_path::FromPath; @@ -46,6 +47,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Glob pattern not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/fs/list/mod.rs b/duckscript_sdk/src/sdk/std/fs/list/mod.rs index 0f197af6..6d0fc89f 100755 --- a/duckscript_sdk/src/sdk/std/fs/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/list/mod.rs @@ -1,5 +1,8 @@ use crate::utils::{flags, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; +use duckscript::types::instruction::Instruction; +use duckscript::types::runtime::StateValue; use fs_extra::dir::{ls, DirEntryAttr, DirEntryValue}; use fsio::path::{get_basename, get_parent_directory}; use std::collections::{HashMap, HashSet}; @@ -42,7 +45,7 @@ fn get_boolean_value(key: DirEntryAttr, attributes: &HashMap, extended_details: bool) { +fn print_entry(env: &mut Env, item: &HashMap, extended_details: bool) { if extended_details { let directory_flag = if get_boolean_value(DirEntryAttr::IsDir, &item) { "" @@ -50,14 +53,21 @@ fn print_entry(item: &HashMap, extended_details: bo "" }; - println!( + writeln!( + env.out, "{}\t{}\t{}", get_u64_value(DirEntryAttr::FileSize, &item), directory_flag, get_string_value(DirEntryAttr::FullName, &item) - ); + ) + .unwrap(); } else { - println!("{} ", get_string_value(DirEntryAttr::FullName, &item)); + writeln!( + env.out, + "{} ", + get_string_value(DirEntryAttr::FullName, &item) + ) + .unwrap(); } } @@ -83,7 +93,21 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn requires_context(&self) -> bool { + true + } + + fn run_with_context( + &self, + arguments: Vec, + _state: &mut HashMap, + _variables: &mut HashMap, + _output_variable: Option, + _instructions: &Vec, + _commands: &mut Commands, + _line: usize, + env: &mut Env, + ) -> CommandResult { let (path_str, flags) = if arguments.is_empty() { (".", "") } else if arguments.len() == 1 { @@ -138,13 +162,13 @@ impl Command for CommandImpl { let item_name = get_string_value(DirEntryAttr::FullName, &item); if item_name == file_name { - print_entry(&item, extended_details); + print_entry(env, &item, extended_details); break; } } } else { for item in items { - print_entry(&item, extended_details); + print_entry(env, &item, extended_details); } } diff --git a/duckscript_sdk/src/sdk/std/fs/print/mod.rs b/duckscript_sdk/src/sdk/std/fs/print/mod.rs index 2a1607e2..7c7c054d 100755 --- a/duckscript_sdk/src/sdk/std/fs/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/print/mod.rs @@ -1,5 +1,9 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; +use duckscript::types::instruction::Instruction; +use duckscript::types::runtime::StateValue; +use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +31,21 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn requires_context(&self) -> bool { + true + } + + fn run_with_context( + &self, + arguments: Vec, + _state: &mut HashMap, + _variables: &mut HashMap, + _output_variable: Option, + _instructions: &Vec, + _commands: &mut Commands, + _line: usize, + env: &mut Env, + ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("File name not provided.".to_string()) } else { @@ -41,8 +59,10 @@ impl Command for CommandImpl { } } - println!("{}", &all_text); - CommandResult::Continue(Some(all_text)) + match writeln!(env.out, "{}", &all_text) { + Ok(_) => CommandResult::Continue(Some(all_text)), + Err(error) => CommandResult::Error(error.to_string()), + } } } } diff --git a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs index d13f0f95..6a557706 100755 --- a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs @@ -1,6 +1,7 @@ use crate::utils::state::put_handle; use crate::utils::{io, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("File name not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs index 74959dc8..49ffc5d1 100755 --- a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs @@ -1,6 +1,7 @@ use crate::utils::state::get_handles_sub_state; use crate::utils::{io, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("File name and text not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs index bb5e2bcd..7fe59946 100644 --- a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs @@ -1,5 +1,6 @@ use crate::utils::{pckg, state}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -51,6 +52,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { return CommandResult::Error( diff --git a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs index de2853ba..15a325d4 100755 --- a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,6 +44,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Command name not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/json/encode/mod.rs b/duckscript_sdk/src/sdk/std/json/encode/mod.rs index aa39f218..29ba7f52 100755 --- a/duckscript_sdk/src/sdk/std/json/encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/encode/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::json::OBJECT_VALUE; use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use serde_json::map::Map; @@ -212,6 +213,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("No JSON root variable name provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/json/parse/mod.rs b/duckscript_sdk/src/sdk/std/json/parse/mod.rs index d2424a28..15792085 100755 --- a/duckscript_sdk/src/sdk/std/json/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/parse/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::json::OBJECT_VALUE; use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use serde_json::{Result, Value}; @@ -117,6 +118,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("No JSON string provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs index b93a0488..95c9c4ea 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::lib::alias::ALIAS_STATE_KEY; use crate::utils::state::get_sub_state; use crate::utils::{eval, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -48,12 +49,13 @@ fn create_alias_command( _instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { let mut all_arguments = vec![]; all_arguments.append(&mut self.arguments.clone()); all_arguments.append(&mut arguments.clone()); - eval::eval_with_error(&all_arguments, state, variables, commands) + eval::eval_with_error(&all_arguments, state, variables, commands, env) } } @@ -106,6 +108,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { CommandResult::Error("Invalid alias provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs index decc1ffc..6f4b88e3 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::lib::alias::ALIAS_STATE_KEY; use crate::utils::pckg; use crate::utils::state::get_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() != 1 { CommandResult::Error("Invalid alias name provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs index 41d21018..5fcc3743 100755 --- a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,6 +44,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() != 1 { CommandResult::Error("Invalid command name provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/man/mod.rs b/duckscript_sdk/src/sdk/std/man/mod.rs index de9ac848..18a05f0e 100755 --- a/duckscript_sdk/src/sdk/std/man/mod.rs +++ b/duckscript_sdk/src/sdk/std/man/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -8,12 +9,12 @@ use std::collections::HashMap; #[path = "./mod_test.rs"] mod mod_test; -fn print_help(help_doc: String, name: &str) -> CommandResult { +fn print_help(env: &mut Env, help_doc: String, name: &str) -> CommandResult { if help_doc.is_empty() { - println!("No documentation found for command: {}", name); + writeln!(env.out, "No documentation found for command: {}", name).unwrap(); CommandResult::Continue(None) } else { - println!("{}", &help_doc); + writeln!(env.out, "{}", &help_doc).unwrap(); CommandResult::Continue(Some(help_doc)) } } @@ -53,22 +54,23 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { - print_help(self.help(), &self.name()) + print_help(env, self.help(), &self.name()) } else { let name = &arguments[0]; match commands.get(name) { Some(command) => { let help_doc = command.help(); - print_help(help_doc, name) + print_help(env, help_doc, name) } None => { if name == &self.name() || self.aliases().contains(name) { - print_help(self.help(), &self.name()) + print_help(env, self.help(), &self.name()) } else { - println!("Command: {} not found.", name); + writeln!(env.out, "Command: {} not found.", name).unwrap(); CommandResult::Continue(None) } } diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs index 67001e60..79928421 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::net::ftp::{validate_and_run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -46,6 +47,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { validate_and_run_with_connection( &arguments, diff --git a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs index 835e923f..66bb7ade 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::net::ftp::{run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -46,6 +47,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { run_with_connection(&arguments, &mut |_options: &Options, ftp_stream: &mut FtpStream| diff --git a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs index 96cefbfe..a81d212d 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::net::ftp::{run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -46,6 +47,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { run_with_connection(&arguments, &mut |_options: &Options, ftp_stream: &mut FtpStream| diff --git a/duckscript_sdk/src/sdk/std/not/mod.rs b/duckscript_sdk/src/sdk/std/not/mod.rs index 518df0f8..49b5678b 100755 --- a/duckscript_sdk/src/sdk/std/not/mod.rs +++ b/duckscript_sdk/src/sdk/std/not/mod.rs @@ -1,5 +1,6 @@ use crate::utils::{condition, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,11 +44,19 @@ impl Command for CommandImpl { instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { - match condition::eval_condition(arguments, instructions, state, variables, commands) { + match condition::eval_condition( + arguments, + instructions, + state, + variables, + commands, + env, + ) { Ok(passed) => { let output = !passed; CommandResult::Continue(Some(output.to_string())) diff --git a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs index ebeff19f..feeba8cb 100755 --- a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::on_error::{get_value, EXIT_ON_ERROR_KEY, STATE_KEY}; use crate::utils::state::get_core_sub_state_for_command; use crate::utils::{condition, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let exit_on_error = if arguments.is_empty() { let value_string = get_value(state, EXIT_ON_ERROR_KEY.to_string()); diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs index ca4b98ff..2ce353e3 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs @@ -1,6 +1,7 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let value = get_value(state, "error".to_string()); CommandResult::Continue(value) diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs index ef9b0fcd..60fa311b 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs @@ -1,6 +1,7 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let value = get_value(state, "line".to_string()); CommandResult::Continue(value) diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs index 86610192..62eceed6 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs @@ -1,6 +1,7 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let value = get_value(state, "source".to_string()); CommandResult::Continue(value) diff --git a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs index 860ae05d..1d2bb16b 100755 --- a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::on_error::{get_value, EXIT_ON_ERROR_KEY, STATE_KEY}; use crate::utils::state::get_core_sub_state_for_command; use crate::utils::{condition, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if !arguments.is_empty() { let error = arguments[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs index bebec0cb..e33d06e6 100755 --- a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs @@ -2,6 +2,7 @@ use crate::sdk::std::on_error::STATE_KEY; use crate::utils::pckg; use crate::utils::state::get_core_sub_state_for_command; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, line: usize, + _env: &mut Env, ) -> CommandResult { if !arguments.is_empty() { let error = arguments[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/print/mod.rs b/duckscript_sdk/src/sdk/std/print/mod.rs index 2d691751..839e5b2b 100755 --- a/duckscript_sdk/src/sdk/std/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/print/mod.rs @@ -1,6 +1,10 @@ use crate::utils::pckg; use colored::{Color, ColoredString, Colorize}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; +use duckscript::types::instruction::Instruction; +use duckscript::types::runtime::StateValue; +use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -134,7 +138,7 @@ fn add_color( } } -pub(crate) fn run_print(arguments: Vec) -> CommandResult { +pub(crate) fn run_print(env: &mut Env, arguments: Vec) -> CommandResult { // collect options let mut styles = vec![]; let mut text_color = None; @@ -187,9 +191,10 @@ pub(crate) fn run_print(arguments: Vec) -> CommandResult { styled_string = add_color(styled_string, background_color, true); styled_string = add_styles(styled_string, styles); - print!("{}", styled_string); - - CommandResult::Continue(Some(count.to_string())) + match write!(env.out, "{}", styled_string) { + Ok(_) => CommandResult::Continue(Some(count.to_string())), + Err(error) => CommandResult::Error(error.to_string()), + } } #[derive(Clone)] @@ -214,8 +219,22 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - run_print(arguments) + fn requires_context(&self) -> bool { + true + } + + fn run_with_context( + &self, + arguments: Vec, + _state: &mut HashMap, + _variables: &mut HashMap, + _output_variable: Option, + _instructions: &Vec, + _commands: &mut Commands, + _line: usize, + env: &mut Env, + ) -> CommandResult { + run_print(env, arguments) } } diff --git a/duckscript_sdk/src/sdk/std/println/mod.rs b/duckscript_sdk/src/sdk/std/println/mod.rs index 3800e766..e914d11e 100755 --- a/duckscript_sdk/src/sdk/std/println/mod.rs +++ b/duckscript_sdk/src/sdk/std/println/mod.rs @@ -1,6 +1,10 @@ use crate::sdk::std::print::run_print; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; +use duckscript::types::instruction::Instruction; +use duckscript::types::runtime::StateValue; +use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -28,15 +32,31 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let result = run_print(arguments); + fn requires_context(&self) -> bool { + true + } - match result { - CommandResult::Continue(_) => println!(""), - _ => (), - }; + fn run_with_context( + &self, + arguments: Vec, + _state: &mut HashMap, + _variables: &mut HashMap, + _output_variable: Option, + _instructions: &Vec, + _commands: &mut Commands, + _line: usize, + env: &mut Env, + ) -> CommandResult { + let result = run_print(env, arguments); - return result; + if let CommandResult::Continue(ref _value) = result { + match writeln!(env.out, "") { + Ok(_) => result, + Err(error) => CommandResult::Error(error.to_string()), + } + } else { + result + } } } diff --git a/duckscript_sdk/src/sdk/std/process/exec/mod.rs b/duckscript_sdk/src/sdk/std/process/exec/mod.rs index aa60c413..1025eaf7 100755 --- a/duckscript_sdk/src/sdk/std/process/exec/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/exec/mod.rs @@ -1,6 +1,7 @@ use crate::utils::exec::ExecInput; use crate::utils::{exec, pckg}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -49,6 +50,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let mut input = if output_variable.is_some() { ExecInput::External diff --git a/duckscript_sdk/src/sdk/std/release/mod.rs b/duckscript_sdk/src/sdk/std/release/mod.rs index 43b44e4e..ddc41e0c 100755 --- a/duckscript_sdk/src/sdk/std/release/mod.rs +++ b/duckscript_sdk/src/sdk/std/release/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{remove_handle, remove_handle_recursive}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Continue(Some("false".to_string())) diff --git a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs index 0134891e..c2a5e729 100755 --- a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs @@ -1,6 +1,7 @@ use crate::types::scope::clear; use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Scope name not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs index 794976e3..f24bc87a 100755 --- a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs @@ -1,5 +1,6 @@ use crate::utils::{pckg, scope}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,6 +44,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let copy = if arguments.is_empty() { &[] diff --git a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs index eafd652d..5e632956 100755 --- a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs @@ -1,5 +1,6 @@ use crate::utils::{pckg, scope}; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,6 +44,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let copy = if arguments.is_empty() { &[] diff --git a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs index e0482aed..3307abc9 100755 --- a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use semver::Version; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("No semver value provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs index 8977c0e3..6ac0a073 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs @@ -2,6 +2,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use base64::Engine; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Value not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs index 099ae4e7..3c4a2b61 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs @@ -2,6 +2,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use base64::Engine; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs index fce6ddde..eac19f5a 100755 --- a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -45,6 +46,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/string/split/mod.rs b/duckscript_sdk/src/sdk/std/string/split/mod.rs index 84bbf693..396e7ae4 100755 --- a/duckscript_sdk/src/sdk/std/string/split/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/split/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() < 2 { CommandResult::Error("Invalid input provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs index 9e791f51..970f17e7 100755 --- a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing input.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs index 00c1ff00..75035712 100755 --- a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use duckscript::runner; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::{Context, StateValue}; use std::collections::HashMap; @@ -55,6 +56,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Crash("Directory name not provided.".to_string()) @@ -89,7 +91,7 @@ assert result let mut context = Context::new(); context.commands = commands.clone(); - match runner::run_script(&script, context) { + match runner::run_script(&script, context, None) { Err(error) => CommandResult::Crash( format!("Error while running tests.\n{}", &error.to_string()).to_string(), ), diff --git a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs index 9166ce28..b40dd6a5 100755 --- a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::{Instruction, InstructionType}; use duckscript::types::runtime::{Context, StateValue}; use duckscript::{parser, runner}; @@ -55,6 +56,7 @@ impl Command for CommandImpl { _instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Crash("File name not provided.".to_string()) @@ -105,9 +107,14 @@ impl Command for CommandImpl { let mut context = Context::new(); context.commands = commands.clone(); - match runner::run_script(&script, context) { + match runner::run_script(&script, context, None) { Err(error) => { - println!("test: [{}][{}] ... failed", &file, &test_name); + writeln!( + env.out, + "test: [{}][{}] ... failed", + &file, &test_name + ) + .unwrap(); return CommandResult::Crash( format!( @@ -118,7 +125,12 @@ impl Command for CommandImpl { .to_string(), ); } - _ => println!("test: [{}][{}] ... ok", &file, &test_name), + _ => writeln!( + env.out, + "test: [{}][{}] ... ok", + &file, &test_name + ) + .unwrap(), } } } diff --git a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs index 9519fa24..2ffa8d25 100755 --- a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs @@ -1,6 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -44,6 +45,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let mut array = vec![]; diff --git a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs index ad578179..e10a6ea1 100755 --- a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -42,6 +43,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let output = if arguments.is_empty() { None diff --git a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs index 601c8433..fa408c47 100755 --- a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,6 +44,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Variable name not provided.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs index 997516aa..b05184da 100755 --- a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -42,6 +43,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Error("Missing variable name.".to_string()) diff --git a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs index 84417140..94b97724 100755 --- a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs @@ -1,5 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -43,6 +44,7 @@ impl Command for CommandImpl { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.len() > 1 && arguments[0] == "--prefix" { let prefix = &arguments[1]; diff --git a/duckscript_sdk/src/test/mod.rs b/duckscript_sdk/src/test/mod.rs index ee4e72d4..c024cfca 100644 --- a/duckscript_sdk/src/test/mod.rs +++ b/duckscript_sdk/src/test/mod.rs @@ -1,6 +1,7 @@ use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::runner; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::{Context, StateValue}; @@ -95,6 +96,7 @@ impl Command for SetHandleCommand { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Continue(None) @@ -131,6 +133,7 @@ impl Command for ArrayCommand { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { let mut array = vec![]; @@ -169,6 +172,7 @@ impl Command for OnErrorCommand { _instructions: &Vec, _commands: &mut Commands, _line: usize, + _env: &mut Env, ) -> CommandResult { println!("on error: {:#?}", &arguments); @@ -212,7 +216,7 @@ fn run_command(commands: Vec>, script: &str) -> Result>, script: &str) { diff --git a/duckscript_sdk/src/types/command.rs b/duckscript_sdk/src/types/command.rs index d623b570..433a7a85 100644 --- a/duckscript_sdk/src/types/command.rs +++ b/duckscript_sdk/src/types/command.rs @@ -4,6 +4,7 @@ use crate::utils::eval; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::parser; use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -92,6 +93,7 @@ impl Command for AliasCommand { _instructions: &Vec, commands: &mut Commands, _line: usize, + env: &mut Env, ) -> CommandResult { if arguments.len() < self.arguments_amount { CommandResult::Error("Invalid arguments provided.".to_string()) @@ -125,7 +127,7 @@ impl Command for AliasCommand { } let (flow_result, flow_output) = - eval::eval_instructions(&self.instructions, commands, state, variables, 0); + eval::eval_instructions(&self.instructions, commands, state, variables, env, 0); match handle_option { Some(handle) => { diff --git a/duckscript_sdk/src/utils/condition.rs b/duckscript_sdk/src/utils/condition.rs index 69088d2d..fd05eaab 100644 --- a/duckscript_sdk/src/utils/condition.rs +++ b/duckscript_sdk/src/utils/condition.rs @@ -1,5 +1,6 @@ use crate::utils::eval; use duckscript::types::command::{CommandResult, Commands}; +use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -33,6 +34,7 @@ pub(crate) fn eval_condition( state: &mut HashMap, variables: &mut HashMap, commands: &mut Commands, + env: &mut Env, ) -> Result { if arguments.is_empty() { Ok(is_true(None)) @@ -40,8 +42,14 @@ pub(crate) fn eval_condition( let eval_statement = commands.exists(&arguments[0]); if eval_statement { - match eval::eval_with_instructions(&arguments, instructions, state, variables, commands) - { + match eval::eval_with_instructions( + &arguments, + instructions, + state, + variables, + commands, + env, + ) { CommandResult::Continue(value) => { let passed = is_true(value); diff --git a/duckscript_sdk/src/utils/condition_test.rs b/duckscript_sdk/src/utils/condition_test.rs index 47871254..5fe640b3 100644 --- a/duckscript_sdk/src/utils/condition_test.rs +++ b/duckscript_sdk/src/utils/condition_test.rs @@ -65,6 +65,7 @@ fn eval_condition_empty() { &mut HashMap::new(), &mut HashMap::new(), &mut Commands::new(), + &mut Env::default(), ); assert!(result.is_ok()); @@ -82,6 +83,7 @@ fn eval_condition_value_true() { &mut HashMap::new(), &mut HashMap::new(), &mut Commands::new(), + &mut Env::default(), ); assert!(result.is_ok()); @@ -99,6 +101,7 @@ fn eval_condition_value_false() { &mut HashMap::new(), &mut HashMap::new(), &mut Commands::new(), + &mut Env::default(), ); assert!(result.is_ok()); @@ -122,6 +125,7 @@ fn eval_condition_command_true() { &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut Env::default(), ); assert!(result.is_ok()); @@ -145,6 +149,7 @@ fn eval_condition_command_false() { &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut Env::default(), ); assert!(result.is_ok()); @@ -168,6 +173,7 @@ fn eval_condition_command_error() { &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut Env::default(), ); assert!(result.is_err()); diff --git a/duckscript_sdk/src/utils/eval.rs b/duckscript_sdk/src/utils/eval.rs index 6736c11a..2f486aef 100644 --- a/duckscript_sdk/src/utils/eval.rs +++ b/duckscript_sdk/src/utils/eval.rs @@ -1,6 +1,7 @@ use duckscript::parser; use duckscript::runner; use duckscript::types::command::{CommandResult, Commands, GoToValue}; +use duckscript::types::env::Env; use duckscript::types::instruction::{Instruction, InstructionType}; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -46,14 +47,22 @@ pub(crate) fn eval( state: &mut HashMap, variables: &mut HashMap, commands: &mut Commands, + env: &mut Env, ) -> Result { if arguments.is_empty() { Ok(CommandResult::Continue(None)) } else { match parse(arguments) { Ok(instruction) => { - let (command_result, _) = - runner::run_instruction(commands, variables, state, &vec![], instruction, 0); + let (command_result, _) = runner::run_instruction( + commands, + variables, + state, + &vec![], + instruction, + 0, + env, + ); Ok(command_result) } @@ -67,8 +76,9 @@ pub(crate) fn eval_with_error( state: &mut HashMap, variables: &mut HashMap, commands: &mut Commands, + env: &mut Env, ) -> CommandResult { - match eval(arguments, state, variables, commands) { + match eval(arguments, state, variables, commands, env) { Ok(command_result) => match command_result.clone() { CommandResult::Crash(error) => CommandResult::Error(error), _ => command_result, @@ -83,6 +93,7 @@ pub(crate) fn eval_with_instructions( state: &mut HashMap, variables: &mut HashMap, commands: &mut Commands, + env: &mut Env, ) -> CommandResult { if arguments.is_empty() { CommandResult::Continue(None) @@ -96,6 +107,7 @@ pub(crate) fn eval_with_instructions( commands, state, variables, + env, all_instructions.len() - 1, ); @@ -117,6 +129,7 @@ pub(crate) fn eval_instructions( commands: &mut Commands, state: &mut HashMap, variables: &mut HashMap, + env: &mut Env, start_line: usize, ) -> (Option, Option) { let mut line = start_line; @@ -138,6 +151,7 @@ pub(crate) fn eval_instructions( &instructions, instruction.clone(), line, + env, ); match command_result { diff --git a/duckscript_sdk/src/utils/eval_test.rs b/duckscript_sdk/src/utils/eval_test.rs index 26bdd342..88b90673 100644 --- a/duckscript_sdk/src/utils/eval_test.rs +++ b/duckscript_sdk/src/utils/eval_test.rs @@ -5,12 +5,14 @@ use crate::test::SetCommand; #[test] fn eval_with_error_empty_arguments() { let mut commands = Commands::new(); + let mut env = Env::default(); let result = eval_with_error( &vec![], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -22,12 +24,14 @@ fn eval_with_error_empty_arguments() { #[test] fn eval_with_error_label_only() { let mut commands = Commands::new(); + let mut env = Env::default(); let result = eval_with_error( &vec![":label".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -43,12 +47,14 @@ fn eval_with_error_command_no_output() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec!["test_set".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -64,12 +70,14 @@ fn eval_with_error_command_with_output() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec!["test_set".to_string(), "test".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -85,12 +93,14 @@ fn eval_with_error_command_with_output_with_spaces() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec!["test_set".to_string(), "test 1 2 3".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -106,6 +116,7 @@ fn eval_with_error_command_with_output_with_spaces_and_all_line_types() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec![ @@ -120,6 +131,7 @@ fn eval_with_error_command_with_output_with_spaces_and_all_line_types() { &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -131,12 +143,14 @@ fn eval_with_error_command_with_output_with_spaces_and_all_line_types() { #[test] fn eval_with_error_parse_error() { let mut commands = Commands::new(); + let mut env = Env::default(); let result = eval_with_error( &vec![":label".to_string(), ":label".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -152,12 +166,14 @@ fn eval_with_eq_empty_args() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec!["eq".to_string(), "".to_string(), "".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -173,12 +189,14 @@ fn eval_with_eq_true_args() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec!["eq".to_string(), "true".to_string(), "true".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { @@ -194,12 +212,14 @@ fn eval_with_eq_true_and_false_args() { Err(error) => panic!("{}", error), _ => (), }; + let mut env = Env::default(); let result = eval_with_error( &vec!["eq".to_string(), "true".to_string(), "false".to_string()], &mut HashMap::new(), &mut HashMap::new(), &mut commands, + &mut env, ); match result { diff --git a/test/std/fs/gitignore_path_array_test.ds b/test/std/fs/gitignore_path_array_test.ds index a0e4eb80..6631a389 100644 --- a/test/std/fs/gitignore_path_array_test.ds +++ b/test/std/fs/gitignore_path_array_test.ds @@ -9,7 +9,7 @@ fn test_found handle = gitignore_path_array ./duckscript/src size = array_length ${handle} - assert_eq ${size} 36 + assert_eq ${size} 38 expected = map map_put ${expected} ./duckscript/src true From b7d9988f5a8ba48f342d4478298a5bdc0ceba584 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 14 Sep 2024 12:53:35 +0000 Subject: [PATCH 02/12] initial redesign command --- docs/_includes/content.md | 33 +++------ duckscript/src/runner.rs | 27 ++++---- duckscript/src/test/mod.rs | 67 +++++++------------ duckscript/src/types/command.rs | 54 ++++++--------- duckscript/src/types/command_test.rs | 31 ++++++--- .../src/sdk/internal/sdkdocs/mod.rs | 33 +++------ .../src/sdk/std/collections/array/mod.rs | 22 ++---- .../sdk/std/collections/array_clear/mod.rs | 22 ++---- .../src/sdk/std/collections/array_get/mod.rs | 26 ++----- .../sdk/std/collections/array_length/mod.rs | 22 ++---- .../src/sdk/std/collections/array_pop/mod.rs | 22 ++---- .../src/sdk/std/collections/array_push/mod.rs | 24 ++----- .../sdk/std/collections/array_remove/mod.rs | 26 ++----- .../src/sdk/std/collections/array_set/mod.rs | 28 ++------ .../src/sdk/std/collections/is_array/mod.rs | 22 ++---- .../src/sdk/std/collections/is_map/mod.rs | 22 ++---- .../src/sdk/std/collections/is_set/mod.rs | 22 ++---- .../src/sdk/std/collections/map/mod.rs | 18 +---- .../src/sdk/std/collections/map_clear/mod.rs | 22 ++---- .../src/sdk/std/collections/map_get/mod.rs | 28 ++------ .../src/sdk/std/collections/map_keys/mod.rs | 24 ++----- .../collections/map_load_properties/mod.rs | 47 +++++-------- .../src/sdk/std/collections/map_put/mod.rs | 28 ++------ .../src/sdk/std/collections/map_remove/mod.rs | 26 ++----- .../src/sdk/std/collections/map_size/mod.rs | 22 ++---- .../std/collections/map_to_properties/mod.rs | 26 ++----- .../src/sdk/std/collections/range/mod.rs | 28 ++------ .../std/collections/read_properties/mod.rs | 26 ++----- .../src/sdk/std/collections/set/mod.rs | 20 +----- .../src/sdk/std/collections/set_clear/mod.rs | 22 ++---- .../sdk/std/collections/set_contains/mod.rs | 26 ++----- .../src/sdk/std/collections/set_put/mod.rs | 24 ++----- .../src/sdk/std/collections/set_remove/mod.rs | 26 ++----- .../src/sdk/std/collections/set_size/mod.rs | 22 ++---- .../sdk/std/collections/set_to_array/mod.rs | 24 ++----- .../std/collections/write_properties/mod.rs | 33 +++------ .../std/debug/duckscript_sdk_version/mod.rs | 4 +- .../sdk/std/debug/duckscript_version/mod.rs | 4 +- .../sdk/std/debug/dump_instructions/mod.rs | 22 ++---- .../src/sdk/std/debug/dump_state/mod.rs | 22 ++---- .../src/sdk/std/debug/dump_variables/mod.rs | 22 ++---- duckscript_sdk/src/sdk/std/echo/mod.rs | 26 ++----- .../src/sdk/std/env/cpu_count/mod.rs | 4 +- .../src/sdk/std/env/env_to_map/mod.rs | 18 +---- duckscript_sdk/src/sdk/std/env/get_env/mod.rs | 8 +-- .../src/sdk/std/env/get_home_dir/mod.rs | 4 +- .../src/sdk/std/env/get_user_name/mod.rs | 4 +- .../src/sdk/std/env/os_family/mod.rs | 4 +- duckscript_sdk/src/sdk/std/env/os_name/mod.rs | 4 +- .../src/sdk/std/env/os_release/mod.rs | 4 +- .../src/sdk/std/env/os_version/mod.rs | 4 +- .../std/env/print_current_directory/mod.rs | 20 +----- .../sdk/std/env/set_current_directory/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/env/set_env/mod.rs | 32 +++------ duckscript_sdk/src/sdk/std/env/unset/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/env/which/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/eval/mod.rs | 26 +++---- .../src/sdk/std/flowcontrol/end/mod.rs | 22 ++---- .../src/sdk/std/flowcontrol/forin/mod.rs | 12 ++-- .../src/sdk/std/flowcontrol/function/mod.rs | 32 ++++----- .../src/sdk/std/flowcontrol/goto/mod.rs | 10 +-- .../src/sdk/std/flowcontrol/ifelse/mod.rs | 14 ++-- .../src/sdk/std/flowcontrol/while_mod/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/append/mod.rs | 10 +-- duckscript_sdk/src/sdk/std/fs/basename/mod.rs | 8 +-- .../src/sdk/std/fs/canonical/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/cp/mod.rs | 10 +-- duckscript_sdk/src/sdk/std/fs/dirname/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/exists/mod.rs | 8 +-- .../src/sdk/std/fs/get_file_size/mod.rs | 8 +-- .../sdk/std/fs/get_last_modified_time/mod.rs | 8 +-- .../sdk/std/fs/gitignore_path_array/mod.rs | 10 +-- .../src/sdk/std/fs/glob_array/mod.rs | 8 +-- .../src/sdk/std/fs/is_directory/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/is_file/mod.rs | 8 +-- .../src/sdk/std/fs/is_path_newer/mod.rs | 10 +-- .../src/sdk/std/fs/is_readonly/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/list/mod.rs | 24 +++---- duckscript_sdk/src/sdk/std/fs/mkdir/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/mv/mod.rs | 20 +++--- duckscript_sdk/src/sdk/std/fs/print/mod.rs | 8 +-- .../src/sdk/std/fs/read_bytes/mod.rs | 8 +-- .../src/sdk/std/fs/read_text/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/rm/mod.rs | 18 ++--- duckscript_sdk/src/sdk/std/fs/rmdir/mod.rs | 10 +-- duckscript_sdk/src/sdk/std/fs/set_mode/mod.rs | 12 ++-- duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs | 4 +- .../src/sdk/std/fs/temp_file/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/fs/touch/mod.rs | 8 +-- .../src/sdk/std/fs/write_bytes/mod.rs | 12 ++-- .../src/sdk/std/fs/write_text/mod.rs | 10 +-- .../src/sdk/std/fs/zip/unzip/mod.rs | 10 +-- duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs | 6 +- duckscript_sdk/src/sdk/std/hash/digest/mod.rs | 6 +- .../src/sdk/std/is_command_defined/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/json/encode/mod.rs | 21 +++--- duckscript_sdk/src/sdk/std/json/parse/mod.rs | 21 +++--- .../src/sdk/std/lib/alias/set/mod.rs | 16 ++--- .../src/sdk/std/lib/alias/unset/mod.rs | 8 +-- .../src/sdk/std/lib/command/remove/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/man/mod.rs | 19 ++++-- duckscript_sdk/src/sdk/std/math/calc/mod.rs | 8 +-- .../src/sdk/std/math/greater_than/mod.rs | 14 ++-- .../src/sdk/std/math/hex_decode/mod.rs | 8 +-- .../src/sdk/std/math/hex_encode/mod.rs | 8 +-- .../src/sdk/std/math/less_than/mod.rs | 14 ++-- duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs | 4 +- .../src/sdk/std/net/ftp/get_in_memory/mod.rs | 4 +- .../src/sdk/std/net/ftp/list/mod.rs | 4 +- .../src/sdk/std/net/ftp/nlst/mod.rs | 4 +- duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs | 4 +- .../src/sdk/std/net/ftp/put_in_memory/mod.rs | 4 +- .../src/sdk/std/net/hostname/mod.rs | 4 +- .../src/sdk/std/net/http_client/mod.rs | 12 ++-- duckscript_sdk/src/sdk/std/noop/mod.rs | 4 +- duckscript_sdk/src/sdk/std/not/mod.rs | 6 +- .../src/sdk/std/on_error/exit_on_error/mod.rs | 8 +-- .../sdk/std/on_error/get_last_error/mod.rs | 4 +- .../std/on_error/get_last_error_line/mod.rs | 4 +- .../std/on_error/get_last_error_source/mod.rs | 4 +- .../src/sdk/std/on_error/on_error/mod.rs | 16 ++--- .../src/sdk/std/on_error/set_error/mod.rs | 8 +-- .../src/sdk/std/on_error/trigger_error/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/print/mod.rs | 10 +-- duckscript_sdk/src/sdk/std/println/mod.rs | 6 +- .../src/sdk/std/process/exec/mod.rs | 4 +- .../src/sdk/std/process/exit/mod.rs | 16 ++--- .../src/sdk/std/process/process_id/mod.rs | 4 +- .../src/sdk/std/process/spawn/mod.rs | 4 +- .../src/sdk/std/process/watchdog/mod.rs | 6 +- .../src/sdk/std/random/range/mod.rs | 15 +++-- duckscript_sdk/src/sdk/std/random/text/mod.rs | 10 +-- duckscript_sdk/src/sdk/std/read/mod.rs | 4 +- duckscript_sdk/src/sdk/std/release/mod.rs | 19 +++--- duckscript_sdk/src/sdk/std/scope/clear/mod.rs | 8 +-- .../src/sdk/std/scope/pop_stack/mod.rs | 10 +-- .../src/sdk/std/scope/push_stack/mod.rs | 10 +-- .../src/sdk/std/semver/is_equal/mod.rs | 10 +-- .../src/sdk/std/semver/is_newer/mod.rs | 10 +-- .../src/sdk/std/semver/parse/mod.rs | 8 +-- .../src/sdk/std/string/base64_decode/mod.rs | 8 +-- .../src/sdk/std/string/base64_encode/mod.rs | 8 +-- .../src/sdk/std/string/bytes_to_string/mod.rs | 8 +-- .../src/sdk/std/string/camelcase/mod.rs | 8 +-- .../src/sdk/std/string/contains/mod.rs | 8 +-- .../src/sdk/std/string/ends_with/mod.rs | 8 +-- .../src/sdk/std/string/equals/mod.rs | 8 +-- .../src/sdk/std/string/indexof/mod.rs | 8 +-- .../src/sdk/std/string/is_empty/mod.rs | 8 +-- .../src/sdk/std/string/kebabcase/mod.rs | 8 +-- .../src/sdk/std/string/last_indexof/mod.rs | 8 +-- .../src/sdk/std/string/length/mod.rs | 8 +-- .../src/sdk/std/string/lowercase/mod.rs | 8 +-- .../src/sdk/std/string/replace/mod.rs | 8 +-- .../src/sdk/std/string/snakecase/mod.rs | 8 +-- .../src/sdk/std/string/split/mod.rs | 8 +-- .../src/sdk/std/string/starts_with/mod.rs | 8 +-- .../src/sdk/std/string/string_to_bytes/mod.rs | 8 +-- .../src/sdk/std/string/substring/mod.rs | 18 ++--- duckscript_sdk/src/sdk/std/string/trim/mod.rs | 8 +-- .../src/sdk/std/string/trim_end/mod.rs | 8 +-- .../src/sdk/std/string/trim_start/mod.rs | 8 +-- .../src/sdk/std/string/uppercase/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/test/assert/mod.rs | 14 ++-- .../src/sdk/std/test/assert_eq/mod.rs | 14 ++-- .../src/sdk/std/test/assert_error/mod.rs | 8 +-- .../src/sdk/std/test/assert_fail/mod.rs | 8 +-- .../src/sdk/std/test/assert_false/mod.rs | 14 ++-- .../src/sdk/std/test/test_directory/mod.rs | 12 ++-- .../src/sdk/std/test/test_file/mod.rs | 27 ++++---- .../src/sdk/std/thread/sleep/mod.rs | 10 +-- .../src/sdk/std/time/current_time/mod.rs | 4 +- .../src/sdk/std/var/get_all_var_names/mod.rs | 4 +- .../src/sdk/std/var/get_by_name/mod.rs | 8 +-- .../src/sdk/std/var/is_defined/mod.rs | 8 +-- duckscript_sdk/src/sdk/std/var/set/mod.rs | 10 +-- .../src/sdk/std/var/set_by_name/mod.rs | 14 ++-- .../src/sdk/std/var/unset_all_vars/mod.rs | 8 +-- duckscript_sdk/src/test/mod.rs | 25 ++++--- duckscript_sdk/src/types/command.rs | 10 +-- duckscript_sdk/src/utils/condition.rs | 12 ++-- duckscript_sdk/src/utils/eval.rs | 4 +- duckscript_sdk/src/utils/exec.rs | 8 +-- 183 files changed, 948 insertions(+), 1526 deletions(-) diff --git a/docs/_includes/content.md b/docs/_includes/content.md index ca756b2b..ec14f983 100755 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -420,11 +420,11 @@ impl Command for GetEnvCommand { "get_env".to_string() } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Missing environment variable name.".to_string()) } else { - match env::var(&arguments[0]) { + match env::var(&arguments.args[0]) { Ok(value) => CommandResult::Continue(Some(value)), Err(_) => CommandResult::Continue(None), } @@ -436,21 +436,14 @@ impl Command for GetEnvCommand { You can look at more examples in the duckscript_sdk folder. -## Context Commands -Context commands are exactly the same as standard commands except that they have access to the runtime context.
-Therefore they implement the same Command trait but this time instead of implementing the run function, they need to implement the following: - -* requires_context - Must return true -* run_with_context - The same logic you would put in the run function but now you have access to a lot more of the runtime context. - -The run_with_context signature is as follows: +## Access to Context +The duckscript runtime context is available in the CommandArgs struc.
```rust /// Run the instruction with access to the runtime context. /// -/// # Arguments -/// -/// * `arguments` - The command arguments array +/// The CommandArgs has the following members: +/// * `args` - The command arguments array /// * `state` - Internal state which is only used by commands to store/pull data /// * `variables` - All script variables /// * `output_variable` - The output variable name (if defined) @@ -458,17 +451,7 @@ The run_with_context signature is as follows: /// * `commands` - The currently known commands /// * `line` - The current instruction line number (global line number after including all scripts into one global script) /// * `env` - The current runtime env with access to out/err writers, etc... -fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - variables: &mut HashMap, - output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - line: usize, - env: &mut Env, -) -> CommandResult; +fn run(&self, arguments: CommandArgs) -> CommandResult; ``` With access to this context you can add/remove/switch commands in runtime, store/pull internal state, add/remove/change variables and so on... diff --git a/duckscript/src/runner.rs b/duckscript/src/runner.rs index 2b9c2ba0..eee7b973 100644 --- a/duckscript/src/runner.rs +++ b/duckscript/src/runner.rs @@ -9,7 +9,7 @@ mod runner_test; use crate::expansion::{self, ExpandedValue}; use crate::parser; -use crate::types::command::{CommandResult, Commands, GoToValue}; +use crate::types::command::{CommandArgs, CommandResult, Commands, GoToValue}; use crate::types::env::Env; use crate::types::error::ScriptError; use crate::types::instruction::{ @@ -325,20 +325,17 @@ pub fn run_instruction( &instruction.meta_info, ); - if command_instance.requires_context() { - command_instance.run_with_context( - command_arguments, - state, - variables, - output_variable.clone(), - instructions, - commands, - line, - env, - ) - } else { - command_instance.run(command_arguments) - } + let command_args = CommandArgs { + args: command_arguments, + state, + variables, + output_variable: output_variable.clone(), + instructions, + commands, + line, + env, + }; + command_instance.run(command_args) } None => CommandResult::Crash(format!("Command: {} not found.", &command)), }, diff --git a/duckscript/src/test/mod.rs b/duckscript/src/test/mod.rs index b1c05c41..b92d2553 100644 --- a/duckscript/src/test/mod.rs +++ b/duckscript/src/test/mod.rs @@ -1,10 +1,7 @@ -use crate::types::command::{Command, CommandResult, Commands, GoToValue}; -use crate::types::env::Env; +use crate::types::command::{Command, CommandArgs, CommandResult, GoToValue}; use crate::types::instruction::{ Instruction, InstructionType, PreProcessInstruction, ScriptInstruction, }; -use crate::types::runtime::StateValue; -use std::collections::HashMap; #[derive(Clone)] pub(crate) struct SetCommand {} @@ -18,11 +15,11 @@ impl Command for SetCommand { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let output = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let output = if arguments.args.is_empty() { None } else { - Some(arguments[0].clone()) + Some(arguments.args[0].clone()) }; CommandResult::Continue(output) @@ -41,11 +38,11 @@ impl Command for ExitCommand { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let output = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let output = if arguments.args.is_empty() { None } else { - Some(arguments[0].clone()) + Some(arguments.args[0].clone()) }; CommandResult::Exit(output) @@ -64,28 +61,16 @@ impl Command for OnErrorCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut index = 0; - for argument in arguments { + for argument in arguments.args { index = index + 1; - variables.insert(index.to_string(), argument.clone()); + arguments + .variables + .insert(index.to_string(), argument.clone()); } - writeln!(env.out, "{}", "test").unwrap(); + writeln!(arguments.env.out, "{}", "test").unwrap(); CommandResult::Continue(None) } @@ -103,7 +88,7 @@ impl Command for ErrorCommand { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Error("test".to_string()) } } @@ -120,7 +105,7 @@ impl Command for CrashCommand { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Crash("test".to_string()) } } @@ -137,11 +122,11 @@ impl Command for GoToLabelCommand { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let (output, label) = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let (output, label) = if arguments.args.is_empty() { (None, "target".to_string()) } else { - (Some(arguments[0].clone()), arguments[0].clone()) + (Some(arguments.args[0].clone()), arguments.args[0].clone()) }; CommandResult::GoTo(output, GoToValue::Label(label)) @@ -160,13 +145,13 @@ impl Command for GoToLineCommand { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let (output, line) = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let (output, line) = if arguments.args.is_empty() { (None, 900) } else { ( - Some(arguments[0].clone()), - arguments[0].clone().parse().unwrap(), + Some(arguments.args[0].clone()), + arguments.args[0].clone().parse().unwrap(), ) }; @@ -190,7 +175,7 @@ impl Command for TestCommand1 { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } @@ -211,7 +196,7 @@ impl Command for TestCommand2 { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } @@ -232,7 +217,7 @@ impl Command for TestCommand3 { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } @@ -253,7 +238,7 @@ impl Command for TestCommand4 { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } diff --git a/duckscript/src/types/command.rs b/duckscript/src/types/command.rs index 3134fe06..b52ab49b 100644 --- a/duckscript/src/types/command.rs +++ b/duckscript/src/types/command.rs @@ -13,6 +13,25 @@ use crate::types::instruction::Instruction; use crate::types::runtime::StateValue; use std::collections::HashMap; +pub struct CommandArgs<'a> { + /// The command arguments + pub args: Vec, + /// Internal state which is only used by commands to store/pull data + pub state: &'a mut HashMap, + /// All script variables + pub variables: &'a mut HashMap, + /// The output variable name (if defined) + pub output_variable: Option, + /// The entire list of instructions which make up the currently running script + pub instructions: &'a Vec, + /// The currently known commands + pub commands: &'a mut Commands, + /// The current instruction line number (global line number after including all scripts into one global script) + pub line: usize, + /// The current runtime env with access to out/err writers, etc... + pub env: &'a mut Env, +} + /// GoTo type value #[derive(Debug, Clone)] pub enum GoToValue { @@ -55,39 +74,8 @@ pub trait Command { /// Clones the command and returns a box reference. fn clone_and_box(&self) -> Box; - /// If true the run with the context will be invoked. - fn requires_context(&self) -> bool { - false - } - - /// Runs the given instruction - fn run(&self, _arguments: Vec) -> CommandResult { - CommandResult::Crash(format!("Not implemented for command: {}", &self.name()).to_string()) - } - - /// Run the instruction with access to the runtime context. - /// - /// # Arguments - /// - /// * `arguments` - The command arguments array - /// * `state` - Internal state which is only used by commands to store/pull data - /// * `variables` - All script variables - /// * `output_variable` - The output variable name (if defined) - /// * `instructions` - The entire list of instructions which make up the currently running script - /// * `commands` - The currently known commands - /// * `line` - The current instruction line number (global line number after including all scripts into one global script) - /// * `env` - The current runtime env with access to out/err writers, etc... - fn run_with_context( - &self, - _arguments: Vec, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + /// Run the instruction. + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Crash(format!("Not implemented for command: {}", &self.name()).to_string()) } } diff --git a/duckscript/src/types/command_test.rs b/duckscript/src/types/command_test.rs index fbd8976e..ab96900e 100644 --- a/duckscript/src/types/command_test.rs +++ b/duckscript/src/types/command_test.rs @@ -61,7 +61,16 @@ fn command_default_run() { } let command = InnerCommand {}; - let result = command.run(vec![]); + let result = command.run(CommandArgs { + args: vec![], + state: &mut HashMap::new(), + variables: &mut HashMap::new(), + output_variable: None, + instructions: &vec![], + commands: &mut Commands::new(), + line: 0, + env: &mut Env::default(), + }); test::validate_continue_result(&result, None); } @@ -84,16 +93,16 @@ fn command_default_run_with_context() { let mut context = Context::new(); let mut env = Env::default(); let command = InnerCommand {}; - let result = command.run_with_context( - vec![], - &mut HashMap::new(), - &mut HashMap::new(), - None, - &vec![], - &mut context.commands, - 0, - &mut env, - ); + let result = command.run(CommandArgs { + args: vec![], + state: &mut HashMap::new(), + variables: &mut HashMap::new(), + output_variable: None, + instructions: &vec![], + commands: &mut context.commands, + line: 0, + env: &mut env, + }); test::validate_continue_result(&result, None); } diff --git a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs index c968774b..dcd12c4b 100755 --- a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs +++ b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs @@ -1,7 +1,6 @@ use crate::utils::io; use crate::utils::pckg; -use duckscript::types::command::Commands; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -29,38 +28,24 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Documentation output directory not provided.".to_string()) } else { - let (file, prefix) = if arguments.len() == 1 { - (arguments[0].clone(), "".to_string()) + let (file, prefix) = if arguments.args.len() == 1 { + (arguments.args[0].clone(), "".to_string()) } else { - (arguments[1].clone(), arguments[0].clone()) + (arguments.args[1].clone(), arguments.args[0].clone()) }; - let names = commands.get_all_command_names(); + let names = arguments.commands.get_all_command_names(); let mut buffer = String::new(); // create ToC buffer.push_str("# Table of Contents\n"); for name in &names { if name.starts_with(&prefix) { - match commands.get(name) { + match arguments.commands.get(name) { Some(command) => { if !command.help().is_empty() { let aliases = command.aliases(); @@ -87,7 +72,7 @@ impl Command for CommandImpl { } }; } else { - if let Err(error) = writeln!(env.out, "Command: {} skipped.", &name) { + if let Err(error) = writeln!(arguments.env.out, "Command: {} skipped.", &name) { return CommandResult::Error(error.to_string()); } } diff --git a/duckscript_sdk/src/sdk/std/collections/array/mod.rs b/duckscript_sdk/src/sdk/std/collections/array/mod.rs index ce188012..d34ce45b 100755 --- a/duckscript_sdk/src/sdk/std/collections/array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,28 +32,14 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut array = vec![]; - for argument in arguments { + for argument in arguments.args { array.push(StateValue::String(argument)); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs index e3f5a03e..208d9b43 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_list(key, state, |list| { list.clear(); diff --git a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs index a2522e5b..8132e98a 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_list}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,32 +32,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Array handle or item index not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); - let index: usize = match arguments[1].parse() { + let key = arguments.args[0].clone(); + let index: usize = match arguments.args[1].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[1]).to_string(), ); } }; diff --git a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs index 96ad0ba9..9429bddc 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -36,27 +36,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs index e47f3d13..a88443b9 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_list}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_list(key, state, |list| { let list_item = list.pop(); diff --git a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs index 1c6eb1b5..a645cb33 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -36,30 +36,16 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_list(key, state, |list| { - for argument in &arguments[1..] { + for argument in &arguments.args[1..] { list.push(StateValue::String(argument.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs index 737e9bce..9267aef5 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,32 +32,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Invalid input provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); - let index: usize = match arguments[1].parse() { + let key = arguments.args[0].clone(); + let index: usize = match arguments.args[1].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[1]).to_string(), ); } }; diff --git a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs index b81a8095..e0e8dba7 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,32 +32,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 3 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 3 { CommandResult::Error("Invalid input provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); - let index: usize = match arguments[1].parse() { + let key = arguments.args[0].clone(); + let index: usize = match arguments.args[1].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[1]).to_string(), ); } }; @@ -66,7 +52,7 @@ impl Command for CommandImpl { let list_length = list.len(); if list_length > index { - list[index] = StateValue::String(arguments[2].clone()); + list[index] = StateValue::String(arguments.args[2].clone()); Ok(Some("true".to_string())) } else { diff --git a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs index d6568b23..046b4555 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs index 3994b0b1..840ca466 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs index 4d85b3f3..877adfb2 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/map/mod.rs b/duckscript_sdk/src/sdk/std/collections/map/mod.rs index 5b7ce46c..24a45215 100755 --- a/duckscript_sdk/src/sdk/std/collections/map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,21 +32,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { let map = HashMap::new(); let key = put_handle(state, StateValue::SubState(map)); diff --git a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs index 56d1c8c6..6d621179 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_map(key, state, |map| { map.clear(); diff --git a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs index dcbaee89..5efd5b7e 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_map}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,35 +32,21 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) - } else if arguments.len() < 2 { + } else if arguments.args.len() < 2 { CommandResult::Error("Key not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_map(key, state, |map| { - let item = match map.remove(&arguments[1]) { + let item = match map.remove(&arguments.args[1]) { Some(value) => { let value_clone = value.clone(); - map.insert(arguments[1].clone(), value); + map.insert(arguments.args[1].clone(), value); Some(value_clone) } None => None, diff --git a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs index 9b8b73be..d21c289a 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, put_handle}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -33,27 +33,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { let handles_state = get_handles_sub_state(state); - match handles_state.get(&arguments[0]) { + match handles_state.get(&arguments.args[0]) { Some(state_value) => match state_value { StateValue::SubState(ref map) => { let mut array = vec![]; @@ -69,7 +55,7 @@ impl Command for CommandImpl { _ => CommandResult::Error("Invalid handle provided.".to_string()), }, None => CommandResult::Error( - format!("Map for handle: {} not found.", &arguments[0]).to_string(), + format!("Map for handle: {} not found.", &arguments.args[0]).to_string(), ), } } diff --git a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs index f841801d..fada6abf 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -33,37 +33,24 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Map handle and/or properties text not provided.".to_string()) } else { - let (prefix, key, text) = if arguments.len() >= 4 && arguments[0] == "--prefix" { - ( - arguments[1].to_string(), - arguments[2].to_string(), - arguments[3].to_string(), - ) - } else { - ( - "".to_string(), - arguments[0].to_string(), - arguments[1].to_string(), - ) - }; + let (prefix, key, text) = + if arguments.args.len() >= 4 && arguments.args[0] == "--prefix" { + ( + arguments.args[1].to_string(), + arguments.args[2].to_string(), + arguments.args[3].to_string(), + ) + } else { + ( + "".to_string(), + arguments.args[0].to_string(), + arguments.args[1].to_string(), + ) + }; match read(text.as_bytes()) { Ok(data) => { diff --git a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs index 1c224957..1c4c13a5 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,33 +32,19 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) - } else if arguments.len() < 3 { + } else if arguments.args.len() < 3 { CommandResult::Error("Key/Value not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_map(key, state, |map| { - let item_key = arguments[1].clone(); - let value = arguments[2].clone(); + let item_key = arguments.args[1].clone(); + let value = arguments.args[2].clone(); map.insert(item_key, StateValue::String(value)); diff --git a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs index c4f31b22..a1c3c0f8 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_map}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,32 +32,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) - } else if arguments.len() < 2 { + } else if arguments.args.len() < 2 { CommandResult::Error("Key not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_map(key, state, |map| { - let item = map.remove(&arguments[1]); + let item = map.remove(&arguments.args[1]); get_optional_as_string(item) }); diff --git a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs index dcce577d..8d1d7adb 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs index ff99dafc..869c2475 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_as_string, get_handles_sub_state}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -34,28 +34,14 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { - let (prefix, key) = if arguments.len() >= 3 && arguments[0] == "--prefix" { - (arguments[1].to_string(), arguments[2].to_string()) + let (prefix, key) = if arguments.args.len() >= 3 && arguments.args[0] == "--prefix" { + (arguments.args[1].to_string(), arguments.args[2].to_string()) } else { - ("".to_string(), arguments[0].to_string()) + ("".to_string(), arguments.args[0].to_string()) }; let state = get_handles_sub_state(state); diff --git a/duckscript_sdk/src/sdk/std/collections/range/mod.rs b/duckscript_sdk/src/sdk/std/collections/range/mod.rs index 8fd845f0..9d0fa9ee 100755 --- a/duckscript_sdk/src/sdk/std/collections/range/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/range/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,38 +32,24 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Invalid arguments provided.".to_string()) } else { - let start: i64 = match arguments[0].parse() { + let start: i64 = match arguments.args[0].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[0]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[0]).to_string(), ); } }; - let end: i64 = match arguments[1].parse() { + let end: i64 = match arguments.args[1].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[1]).to_string(), ); } }; diff --git a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs index 0606c316..8c56aee2 100755 --- a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,28 +32,14 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 1 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 1 { CommandResult::Error("Missing properties text argument.".to_string()) } else { - let (prefix, text) = if arguments.len() >= 3 && arguments[0] == "--prefix" { - (arguments[1].to_string(), arguments[2].to_string()) + let (prefix, text) = if arguments.args.len() >= 3 && arguments.args[0] == "--prefix" { + (arguments.args[1].to_string(), arguments.args[2].to_string()) } else { - ("".to_string(), arguments[0].to_string()) + ("".to_string(), arguments.args[0].to_string()) }; match read(text.as_bytes()) { diff --git a/duckscript_sdk/src/sdk/std/collections/set/mod.rs b/duckscript_sdk/src/sdk/std/collections/set/mod.rs index aa747315..11001de1 100755 --- a/duckscript_sdk/src/sdk/std/collections/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,24 +32,10 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut set = HashSet::new(); - for argument in arguments { + for argument in arguments.args { set.insert(argument); } diff --git a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs index 786834ea..0565e614 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_set(key, state, |set| { set.clear(); diff --git a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs index 344eb92b..0dd25af3 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,32 +32,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) - } else if arguments.len() < 2 { + } else if arguments.args.len() < 2 { CommandResult::Error("Value not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_set(key, state, |set| { - let item = set.contains(&arguments[1]); + let item = set.contains(&arguments.args[1]); Ok(Some(item.to_string())) }); diff --git a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs index 6335ea28..aad0419f 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,30 +32,16 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_set(key, state, |set| { - for argument in &arguments[1..] { + for argument in &arguments.args[1..] { set.insert(argument.to_string()); } diff --git a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs index e608b31c..1b0192f4 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,32 +32,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) - } else if arguments.len() < 2 { + } else if arguments.args.len() < 2 { CommandResult::Error("Value not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = arguments[0].clone(); + let key = arguments.args[0].clone(); let result = mutate_set(key, state, |set| { - let item = set.remove(&arguments[1]); + let item = set.remove(&arguments.args[1]); Ok(Some(item.to_string())) }); diff --git a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs index b110f816..ecbed439 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs index 3e489c7b..31f04528 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, put_handle}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { let handles_state = get_handles_sub_state(state); - match handles_state.get(&arguments[0]) { + match handles_state.get(&arguments.args[0]) { Some(state_value) => match state_value { StateValue::Set(ref set) => { let mut array = vec![]; @@ -68,7 +54,7 @@ impl Command for CommandImpl { _ => CommandResult::Error("Invalid handle provided.".to_string()), }, None => CommandResult::Error( - format!("Set for handle: {} not found.", &arguments[0]).to_string(), + format!("Set for handle: {} not found.", &arguments.args[0]).to_string(), ), } } diff --git a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs index a5b951fd..6027c218 100755 --- a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -33,32 +33,19 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.len() < 1 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 1 { CommandResult::Error("Missing properties names.".to_string()) } else { - let (start_index, prefix) = if arguments.len() > 2 && arguments[0] == "--prefix" { - (2, arguments[1].as_str()) - } else { - (0, "") - }; + let (start_index, prefix) = + if arguments.args.len() > 2 && arguments.args[0] == "--prefix" { + (2, arguments.args[1].as_str()) + } else { + (0, "") + }; let mut data = HashMap::new(); - for argument in &arguments[start_index..] { + for argument in &arguments.args[start_index..] { match variables.get(argument) { Some(value) => { let mut key = argument.to_string(); diff --git a/duckscript_sdk/src/sdk/std/debug/duckscript_sdk_version/mod.rs b/duckscript_sdk/src/sdk/std/debug/duckscript_sdk_version/mod.rs index 91a72332..35dd9784 100755 --- a/duckscript_sdk/src/sdk/std/debug/duckscript_sdk_version/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/duckscript_sdk_version/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(Some(crate::version())) } } diff --git a/duckscript_sdk/src/sdk/std/debug/duckscript_version/mod.rs b/duckscript_sdk/src/sdk/std/debug/duckscript_version/mod.rs index 0bb2ab49..d8abe826 100755 --- a/duckscript_sdk/src/sdk/std/debug/duckscript_version/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/duckscript_version/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(Some(duckscript::version())) } } diff --git a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs index 7723effb..d9b145e6 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -31,25 +31,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - _state: &mut HashMap, - _variables: &mut HashMap, - output_variable: Option, - instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - let string_value = format!("{:#?}", instructions).to_string(); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let string_value = format!("{:#?}", arguments.instructions).to_string(); if output_variable.is_none() { - match writeln!(env.out, "{}", string_value) { + match writeln!(arguments.env.out, "{}", string_value) { Ok(_) => (), Err(error) => return CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs index c86ce94b..fd0dc60e 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -31,25 +31,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - let string_value = format!("{:#?}", state).to_string(); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let string_value = format!("{:#?}", arguments.state).to_string(); if output_variable.is_none() { - match writeln!(env.out, "{}", &string_value) { + match writeln!(arguments.env.out, "{}", &string_value) { Ok(_) => (), Err(error) => return CommandResult::Error(error.to_string()), }; diff --git a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs index a3549e7b..c0440474 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -31,25 +31,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - _state: &mut HashMap, - variables: &mut HashMap, - output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - let string_value = format!("{:#?}", variables).to_string(); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let string_value = format!("{:#?}", arguments.variables).to_string(); if output_variable.is_none() { - match writeln!(env.out, "{}", string_value) { + match writeln!(arguments.env.out, "{}", string_value) { Ok(_) => (), Err(error) => return CommandResult::Error(error.to_string()), }; diff --git a/duckscript_sdk/src/sdk/std/echo/mod.rs b/duckscript_sdk/src/sdk/std/echo/mod.rs index 80831dfc..0fabac44 100755 --- a/duckscript_sdk/src/sdk/std/echo/mod.rs +++ b/duckscript_sdk/src/sdk/std/echo/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -31,29 +31,15 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - for argument in &arguments { - if let Err(error) = write!(env.out, "{}", argument) { + fn run(&self, arguments: CommandArgs) -> CommandResult { + for argument in &arguments.args { + if let Err(error) = write!(arguments.env.out, "{}", argument) { return CommandResult::Error(error.to_string()); } } - match writeln!(env.out, "") { - Ok(_) => CommandResult::Continue(Some(arguments.len().to_string())), + match writeln!(arguments.env.out, "") { + Ok(_) => CommandResult::Continue(Some(arguments.args.len().to_string())), Err(error) => CommandResult::Error(error.to_string()), } } diff --git a/duckscript_sdk/src/sdk/std/env/cpu_count/mod.rs b/duckscript_sdk/src/sdk/std/env/cpu_count/mod.rs index 8d6f4557..128aa4e4 100755 --- a/duckscript_sdk/src/sdk/std/env/cpu_count/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/cpu_count/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { let num = num_cpus::get(); CommandResult::Continue(Some(num.to_string())) diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs index 8deaa867..57ab1b9c 100755 --- a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -33,21 +33,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let all_vars = env::vars(); let mut map = HashMap::new(); diff --git a/duckscript_sdk/src/sdk/std/env/get_env/mod.rs b/duckscript_sdk/src/sdk/std/env/get_env/mod.rs index 8b598e9a..c37d6f1c 100755 --- a/duckscript_sdk/src/sdk/std/env/get_env/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/get_env/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::env; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Missing environment variable name.".to_string()) } else { - match env::var(&arguments[0]) { + match env::var(&arguments.args[0]) { Ok(value) => CommandResult::Continue(Some(value)), Err(_) => CommandResult::Continue(None), } diff --git a/duckscript_sdk/src/sdk/std/env/get_home_dir/mod.rs b/duckscript_sdk/src/sdk/std/env/get_home_dir/mod.rs index 49f2eee0..c7b8ae7a 100755 --- a/duckscript_sdk/src/sdk/std/env/get_home_dir/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/get_home_dir/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::from_path::FromPath; #[cfg(test)] @@ -28,7 +28,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { match home::home_dir() { Some(directory) => { let directory_str = FromPath::from_path(&directory); diff --git a/duckscript_sdk/src/sdk/std/env/get_user_name/mod.rs b/duckscript_sdk/src/sdk/std/env/get_user_name/mod.rs index f9d4c5f3..bab8bcd1 100755 --- a/duckscript_sdk/src/sdk/std/env/get_user_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/get_user_name/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(Some(whoami::username())) } } diff --git a/duckscript_sdk/src/sdk/std/env/os_family/mod.rs b/duckscript_sdk/src/sdk/std/env/os_family/mod.rs index f2a971ae..333d6826 100755 --- a/duckscript_sdk/src/sdk/std/env/os_family/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_family/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { let value = if cfg!(windows) { "windows".to_string() } else if cfg!(target_os = "macos") || cfg!(target_os = "ios") { diff --git a/duckscript_sdk/src/sdk/std/env/os_name/mod.rs b/duckscript_sdk/src/sdk/std/env/os_name/mod.rs index c383cf9f..aa1d6de0 100755 --- a/duckscript_sdk/src/sdk/std/env/os_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_name/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -44,7 +44,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { match get_os_value() { Ok(value) => CommandResult::Continue(Some(value)), Err(error) => CommandResult::Error(error), diff --git a/duckscript_sdk/src/sdk/std/env/os_release/mod.rs b/duckscript_sdk/src/sdk/std/env/os_release/mod.rs index d5937011..84f62b89 100755 --- a/duckscript_sdk/src/sdk/std/env/os_release/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_release/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -44,7 +44,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { match get_os_value() { Ok(value) => CommandResult::Continue(Some(value)), Err(error) => CommandResult::Error(error), diff --git a/duckscript_sdk/src/sdk/std/env/os_version/mod.rs b/duckscript_sdk/src/sdk/std/env/os_version/mod.rs index f1a52f1a..b119ca1e 100755 --- a/duckscript_sdk/src/sdk/std/env/os_version/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/os_version/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -44,7 +44,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { match get_os_value() { Ok(value) => CommandResult::Continue(Some(value)), Err(error) => CommandResult::Error(error), diff --git a/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs b/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs index 1091376e..1c5525f1 100755 --- a/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -32,25 +32,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { match env::current_dir() { Ok(directory_path) => { let directory = directory_path.display(); - match writeln!(env.out, "{}", &directory) { + match writeln!(arguments.env.out, "{}", &directory) { Ok(_) => CommandResult::Continue(Some(directory.to_string())), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/env/set_current_directory/mod.rs b/duckscript_sdk/src/sdk/std/env/set_current_directory/mod.rs index 24bcedef..214645a4 100755 --- a/duckscript_sdk/src/sdk/std/env/set_current_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/set_current_directory/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::env; use std::path::Path; @@ -33,11 +33,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let directory_option = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let directory_option = if arguments.args.is_empty() { home::home_dir() } else { - let path = Path::new(&arguments[0]); + let path = Path::new(&arguments.args[0]); Some(path.to_path_buf()) }; diff --git a/duckscript_sdk/src/sdk/std/env/set_env/mod.rs b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs index 27929e5c..2d7b5aa0 100755 --- a/duckscript_sdk/src/sdk/std/env/set_env/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_as_string, get_handles_sub_state}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -33,32 +33,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Missing environment variable name and value.".to_string()) - } else if arguments.len() == 1 { + } else if arguments.args.len() == 1 { CommandResult::Error("Missing environment variable value.".to_string()) - } else if arguments[0].is_empty() { + } else if arguments.args[0].is_empty() { CommandResult::Error("Environment variable name is empty string.".to_string()) } else { - if arguments[0] == "--handle" { - let state = get_handles_sub_state(state); + if arguments.args[0] == "--handle" { + let state = get_handles_sub_state(arguments.state); - let key = &arguments[1]; + let key = &arguments.args[1]; match state.get(key) { Some(state_value) => match state_value { @@ -80,7 +66,7 @@ impl Command for CommandImpl { ), } } else { - env::set_var(&arguments[0], &arguments[1]); + env::set_var(&arguments.args[0], &arguments.args[1]); CommandResult::Continue(Some("true".to_string())) } diff --git a/duckscript_sdk/src/sdk/std/env/unset/mod.rs b/duckscript_sdk/src/sdk/std/env/unset/mod.rs index f870ef36..0de6ddb8 100755 --- a/duckscript_sdk/src/sdk/std/env/unset/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/unset/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::env; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Missing environment variable name.".to_string()) } else { - env::remove_var(&arguments[0]); + env::remove_var(&arguments.args[0]); CommandResult::Continue(None) } diff --git a/duckscript_sdk/src/sdk/std/env/which/mod.rs b/duckscript_sdk/src/sdk/std/env/which/mod.rs index e6764b1f..08a260cc 100755 --- a/duckscript_sdk/src/sdk/std/env/which/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/which/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::from_path::FromPath; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No executable name provided.".to_string()) } else { - match which::which(&arguments[0]) { + match which::which(&arguments.args[0]) { Ok(path) => { let path_string: String = FromPath::from_path(&path); CommandResult::Continue(Some(path_string)) diff --git a/duckscript_sdk/src/sdk/std/eval/mod.rs b/duckscript_sdk/src/sdk/std/eval/mod.rs index 41acab45..7c53d232 100755 --- a/duckscript_sdk/src/sdk/std/eval/mod.rs +++ b/duckscript_sdk/src/sdk/std/eval/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{eval, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -31,22 +31,14 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: Vec, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - eval::eval_with_error(&arguments, state, variables, commands, env) + fn run(&self, arguments: CommandArgs) -> CommandResult { + eval::eval_with_error( + &arguments.args, + &arguments.state, + &arguments.variables, + &arguments.commands, + &arguments.env, + ) } } diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs index e679e976..c0491020 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::flowcontrol::get_line_key; use crate::utils::state::get_core_sub_state_for_command; use duckscript::runner; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::{ Instruction, InstructionMetaInfo, InstructionType, ScriptInstruction, @@ -57,27 +57,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: Vec, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { match get_command(line, state) { Some(command) => { let mut script_instruction = ScriptInstruction::new(); - script_instruction.command = Some(command); + script_instruction.command = Some(arguments.command); let mut instruction_meta_info = InstructionMetaInfo::new(); - instruction_meta_info.line = Some(line); + instruction_meta_info.line = Some(arguments.line); let instruction = Instruction { meta_info: instruction_meta_info, instruction_type: InstructionType::Script(script_instruction), diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs index 17688f5a..8ff20301 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs @@ -4,7 +4,7 @@ use crate::utils::state::{ get_as_string, get_core_sub_state_for_command, get_handle, get_list, get_sub_state, }; use crate::utils::{instruction_query, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; @@ -316,7 +316,7 @@ impl Command for ForInCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -325,7 +325,7 @@ impl Command for ForInCommand { line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() != 3 || arguments[1] != "in" { + if arguments.args.len() != 3 || arguments.args[1] != "in" { CommandResult::Error("Invalid for/in statement".to_string()) } else { let call_info = match pop_call_info_for_line(line, state, false) { @@ -356,7 +356,7 @@ impl Command for ForInCommand { let iteration = call_info.iteration; let forin_meta_info = call_info.meta_info; - let handle = &arguments[2]; + let handle = &arguments.args[2]; match get_next_iteration(iteration, handle.to_string(), state) { Some(next_value) => { let line_context_name = get_line_context_name(state); @@ -370,7 +370,7 @@ impl Command for ForInCommand { state, ); - variables.insert(arguments[0].clone(), next_value); + variables.insert(arguments.args[0].clone(), next_value); CommandResult::Continue(None) } None => { @@ -419,7 +419,7 @@ impl Command for EndForInCommand { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs index b8693721..ec34fe4a 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs @@ -2,7 +2,7 @@ use crate::sdk::std::flowcontrol::{end, forin, ifelse, while_mod}; use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{annotation, instruction_query, pckg, scope}; -use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; @@ -212,7 +212,7 @@ fn pop_from_call_stack(state: &mut HashMap) -> Option, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, output_variable: Option, @@ -293,7 +293,7 @@ impl Command for FunctionCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -302,18 +302,18 @@ impl Command for FunctionCommand { line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing function name.".to_string()) } else { - let (function_name, scoped) = if arguments.len() == 1 { - (arguments[0].clone(), false) + let (function_name, scoped) = if arguments.args.len() == 1 { + (arguments.args[0].clone(), false) } else { - match annotation::parse(&arguments[0]) { + match annotation::parse(&arguments.args[0]) { Some(annotations) => ( - arguments[1].clone(), + arguments.args[1].clone(), annotations.contains(&"scope".to_string()), ), - None => (arguments[0].clone(), false), + None => (arguments.args[0].clone(), false), } }; @@ -412,7 +412,7 @@ impl Command for FunctionCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, output_variable: Option, @@ -495,7 +495,7 @@ impl Command for EndFunctionCommand { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -557,7 +557,7 @@ impl Command for ReturnCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -576,19 +576,19 @@ impl Command for ReturnCommand { { match call_info.output_variable { Some(ref name) => { - if arguments.is_empty() { + if arguments.args.is_empty() { variables.remove(name); } else { - variables.insert(name.to_string(), arguments[0].clone()); + variables.insert(name.to_string(), arguments.args[0].clone()); } } None => (), }; - let output = if arguments.is_empty() { + let output = if arguments.args.is_empty() { None } else { - Some(arguments[0].clone()) + Some(arguments.args[0].clone()) }; if call_info.scoped { diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/goto/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/goto/mod.rs index d75b1364..3e2c8d0b 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/goto/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/goto/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, GoToValue}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, GoToValue}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,13 +27,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Label not provided.".to_string()) - } else if arguments.len() > 1 { + } else if arguments.args.len() > 1 { CommandResult::Error("Multiple labels provided.".to_string()) } else { - let label = arguments[0].clone(); + let label = arguments.args[0].clone(); if label.starts_with(":") { CommandResult::GoTo(None, GoToValue::Label(label)) diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs index d85d03e3..e201cdda 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs @@ -2,7 +2,7 @@ use crate::sdk::std::flowcontrol::{end, forin, function, get_line_key, while_mod use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{condition, instruction_query, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; @@ -350,7 +350,7 @@ impl Command for IfCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -359,7 +359,7 @@ impl Command for IfCommand { line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match get_or_create_if_meta_info_for_line( @@ -456,7 +456,7 @@ impl Command for ElseIfCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -465,7 +465,7 @@ impl Command for ElseIfCommand { line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match pop_call_info_for_line(line, state) { @@ -555,7 +555,7 @@ impl Command for ElseCommand { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -612,7 +612,7 @@ impl Command for EndIfCommand { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs index 6aea076e..69164286 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs @@ -2,7 +2,7 @@ use crate::sdk::std::flowcontrol::{end, forin, function, get_line_key, ifelse}; use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{condition, instruction_query, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands, GoToValue}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; @@ -273,7 +273,7 @@ impl Command for WhileCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -282,7 +282,7 @@ impl Command for WhileCommand { line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match get_or_create_while_meta_info_for_line( @@ -363,7 +363,7 @@ impl Command for EndWhileCommand { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/fs/append/mod.rs b/duckscript_sdk/src/sdk/std/fs/append/mod.rs index a546c7af..e3dacb9c 100755 --- a/duckscript_sdk/src/sdk/std/fs/append/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/append/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,13 +27,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("File name and text not provided.".to_string()) - } else if arguments.len() == 1 { + } else if arguments.args.len() == 1 { CommandResult::Error("Text not provided.".to_string()) } else { - let result = io::write_to_text_file(&arguments[0], &arguments[1], true); + let result = io::write_to_text_file(&arguments.args[0], &arguments.args[1], true); match result { Ok(_) => CommandResult::Continue(Some("true".to_string())), diff --git a/duckscript_sdk/src/sdk/std/fs/basename/mod.rs b/duckscript_sdk/src/sdk/std/fs/basename/mod.rs index e995ce06..bc0d3e2e 100755 --- a/duckscript_sdk/src/sdk/std/fs/basename/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/basename/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::get_basename; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - let basename = get_basename(&arguments[0]); + let basename = get_basename(&arguments.args[0]); CommandResult::Continue(basename) } } diff --git a/duckscript_sdk/src/sdk/std/fs/canonical/mod.rs b/duckscript_sdk/src/sdk/std/fs/canonical/mod.rs index ec2e7a22..caae90bc 100755 --- a/duckscript_sdk/src/sdk/std/fs/canonical/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/canonical/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::canonicalize_or; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - let path = canonicalize_or(&arguments[0], &arguments[0]); + let path = canonicalize_or(&arguments.args[0], &arguments.args[0]); CommandResult::Continue(Some(path.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/fs/cp/mod.rs b/duckscript_sdk/src/sdk/std/fs/cp/mod.rs index 5f5916b5..5c41da40 100755 --- a/duckscript_sdk/src/sdk/std/fs/cp/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/cp/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fs_extra::dir; use fsio::directory::create_parent; use std::fs; @@ -31,18 +31,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Paths not provided.".to_string()) } else { - let source_path_str = &arguments[0]; + let source_path_str = &arguments.args[0]; let source_path = Path::new(source_path_str); if !source_path.exists() { CommandResult::Error("Path does not exist.".to_string()) } else { let source_file = source_path.is_file(); - let target_path_str = &arguments[1]; + let target_path_str = &arguments.args[1]; if source_file { match create_parent(target_path_str) { diff --git a/duckscript_sdk/src/sdk/std/fs/dirname/mod.rs b/duckscript_sdk/src/sdk/std/fs/dirname/mod.rs index f1ab2acc..4413bd09 100755 --- a/duckscript_sdk/src/sdk/std/fs/dirname/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/dirname/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::get_parent_directory; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - let parent_path = get_parent_directory(&arguments[0]); + let parent_path = get_parent_directory(&arguments.args[0]); CommandResult::Continue(parent_path) } } diff --git a/duckscript_sdk/src/sdk/std/fs/exists/mod.rs b/duckscript_sdk/src/sdk/std/fs/exists/mod.rs index d226b9ad..e65f6868 100755 --- a/duckscript_sdk/src/sdk/std/fs/exists/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/exists/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::as_path::AsPath; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - let path = &arguments[0].as_path(); + let path = &arguments.args[0].as_path(); CommandResult::Continue(Some(path.exists().to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/fs/get_file_size/mod.rs b/duckscript_sdk/src/sdk/std/fs/get_file_size/mod.rs index 66332857..291e9f01 100644 --- a/duckscript_sdk/src/sdk/std/fs/get_file_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/get_file_size/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - match io::get_file_size(&arguments[0]) { + match io::get_file_size(&arguments.args[0]) { Ok(size) => CommandResult::Continue(Some(size.to_string())), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/fs/get_last_modified_time/mod.rs b/duckscript_sdk/src/sdk/std/fs/get_last_modified_time/mod.rs index ab2c98f6..36ed36df 100755 --- a/duckscript_sdk/src/sdk/std/fs/get_last_modified_time/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/get_last_modified_time/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - match io::get_last_modified_time(&arguments[0]) { + match io::get_last_modified_time(&arguments.args[0]) { Ok(time) => CommandResult::Continue(Some(time.to_string())), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs index bd6c889d..02b5ed7f 100755 --- a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -40,7 +40,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -49,19 +49,19 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Root directory not provided.".to_string()) } else { let mut array = vec![]; let (path_index, include_hidden) = - if arguments.len() > 1 && arguments[0] == "--include-hidden" { + if arguments.args.len() > 1 && arguments.args[0] == "--include-hidden" { (1, true) } else { (0, false) }; - for entry in WalkBuilder::new(&arguments[path_index]) + for entry in WalkBuilder::new(&arguments.args[path_index]) .hidden(!include_hidden) .parents(true) .git_ignore(true) diff --git a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs index a662912e..08177daa 100755 --- a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -40,7 +40,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -49,10 +49,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Glob pattern not provided.".to_string()) } else { - match glob(&arguments[0]) { + match glob(&arguments.args[0]) { Ok(paths) => { let mut array = vec![]; diff --git a/duckscript_sdk/src/sdk/std/fs/is_directory/mod.rs b/duckscript_sdk/src/sdk/std/fs/is_directory/mod.rs index dc7de0be..b38d8598 100755 --- a/duckscript_sdk/src/sdk/std/fs/is_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/is_directory/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::as_path::AsPath; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - let path = &arguments[0].as_path(); + let path = &arguments.args[0].as_path(); CommandResult::Continue(Some(path.is_dir().to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/fs/is_file/mod.rs b/duckscript_sdk/src/sdk/std/fs/is_file/mod.rs index c46e832e..eac792d4 100755 --- a/duckscript_sdk/src/sdk/std/fs/is_file/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/is_file/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::as_path::AsPath; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - let path = &arguments[0].as_path(); + let path = &arguments.args[0].as_path(); CommandResult::Continue(Some(path.is_file().to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/fs/is_path_newer/mod.rs b/duckscript_sdk/src/sdk/std/fs/is_path_newer/mod.rs index df366859..c943e527 100755 --- a/duckscript_sdk/src/sdk/std/fs/is_path_newer/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/is_path_newer/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,16 +27,16 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Paths not provided.".to_string()) } else { - let newer = match io::get_last_modified_time(&arguments[0]) { + let newer = match io::get_last_modified_time(&arguments.args[0]) { Ok(time) => time, Err(error) => return CommandResult::Error(error), }; - let older = match io::get_last_modified_time(&arguments[1]) { + let older = match io::get_last_modified_time(&arguments.args[1]) { Ok(time) => time, Err(error) => return CommandResult::Error(error), }; diff --git a/duckscript_sdk/src/sdk/std/fs/is_readonly/mod.rs b/duckscript_sdk/src/sdk/std/fs/is_readonly/mod.rs index c322a34a..432935d5 100755 --- a/duckscript_sdk/src/sdk/std/fs/is_readonly/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/is_readonly/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::fs; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - match fs::metadata(&arguments[0]) { + match fs::metadata(&arguments.args[0]) { Ok(metadata) => { CommandResult::Continue(Some(metadata.permissions().readonly().to_string())) } diff --git a/duckscript_sdk/src/sdk/std/fs/list/mod.rs b/duckscript_sdk/src/sdk/std/fs/list/mod.rs index 6d0fc89f..f79360eb 100755 --- a/duckscript_sdk/src/sdk/std/fs/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/list/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{flags, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -54,7 +54,7 @@ fn print_entry(env: &mut Env, item: &HashMap, exten }; writeln!( - env.out, + arguments.env.out, "{}\t{}\t{}", get_u64_value(DirEntryAttr::FileSize, &item), directory_flag, @@ -63,7 +63,7 @@ fn print_entry(env: &mut Env, item: &HashMap, exten .unwrap(); } else { writeln!( - env.out, + arguments.env.out, "{} ", get_string_value(DirEntryAttr::FullName, &item) ) @@ -99,7 +99,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -108,18 +108,18 @@ impl Command for CommandImpl { _line: usize, env: &mut Env, ) -> CommandResult { - let (path_str, flags) = if arguments.is_empty() { + let (path_str, flags) = if arguments.args.is_empty() { (".", "") - } else if arguments.len() == 1 { - if flags::is_unix_flags_argument(&arguments[0]) { - (".", arguments[0].as_str()) + } else if arguments.args.len() == 1 { + if flags::is_unix_flags_argument(&arguments.args[0]) { + (".", arguments.args[0].as_str()) } else { - (arguments[0].as_str(), "") + (arguments.args[0].as_str(), "") } - } else if flags::is_unix_flags_argument(&arguments[0]) { - (arguments[1].as_str(), arguments[0].as_str()) + } else if flags::is_unix_flags_argument(&arguments.args[0]) { + (arguments.args[1].as_str(), arguments.args[0].as_str()) } else { - (arguments[0].as_str(), "") + (arguments.args[0].as_str(), "") }; let path = Path::new(path_str); diff --git a/duckscript_sdk/src/sdk/std/fs/mkdir/mod.rs b/duckscript_sdk/src/sdk/std/fs/mkdir/mod.rs index 76a33fa7..0b9fedd0 100755 --- a/duckscript_sdk/src/sdk/std/fs/mkdir/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/mkdir/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Directory name not provided.".to_string()) } else { - match fsio::directory::create(&arguments[0]) { + match fsio::directory::create(&arguments.args[0]) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/fs/mv/mod.rs b/duckscript_sdk/src/sdk/std/fs/mv/mod.rs index d193148f..90c19cb8 100755 --- a/duckscript_sdk/src/sdk/std/fs/mv/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/mv/mod.rs @@ -1,6 +1,6 @@ use crate::utils::io::ends_with_separator; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fs_extra::{dir, move_items}; use fsio::directory::create_parent; use std::fs::rename; @@ -32,20 +32,20 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Paths not provided.".to_string()) } else { - let source_path = Path::new(&arguments[0]); + let source_path = Path::new(&arguments.args[0]); if !source_path.exists() { CommandResult::Error("Path does not exist.".to_string()) } else { - let target_path = Path::new(&arguments[1]); - let source_ends_with_separator = ends_with_separator(&arguments[0]); + let target_path = Path::new(&arguments.args[1]); + let source_ends_with_separator = ends_with_separator(&arguments.args[0]); let source_file = source_path.is_file(); let target_exists = target_path.exists(); - let target_ends_with_separator = ends_with_separator(&arguments[1]); + let target_ends_with_separator = ends_with_separator(&arguments.args[1]); let target_file = if target_exists { target_path.is_file() } else { @@ -74,11 +74,11 @@ impl Command for CommandImpl { Err(error) => CommandResult::Error(error.to_string()), } } else { - match fsio::directory::create(&arguments[1]) { + match fsio::directory::create(&arguments.args[1]) { Ok(_) => { let options = dir::CopyOptions::new(); - let from_paths = vec![&arguments[0]]; - match move_items(&from_paths, &arguments[1], &options) { + let from_paths = vec![&arguments.args[0]]; + match move_items(&from_paths, &arguments.args[1], &options) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/fs/print/mod.rs b/duckscript_sdk/src/sdk/std/fs/print/mod.rs index 7c7c054d..27acf4fc 100755 --- a/duckscript_sdk/src/sdk/std/fs/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/print/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -46,7 +46,7 @@ impl Command for CommandImpl { _line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("File name not provided.".to_string()) } else { let mut all_text = String::new(); @@ -59,7 +59,7 @@ impl Command for CommandImpl { } } - match writeln!(env.out, "{}", &all_text) { + match writeln!(arguments.env.out, "{}", &all_text) { Ok(_) => CommandResult::Continue(Some(all_text)), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs index 6a557706..8c107f6b 100755 --- a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs @@ -1,6 +1,6 @@ use crate::utils::state::put_handle; use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -47,10 +47,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("File name not provided.".to_string()) } else { - let result = io::read_raw_file(&arguments[0]); + let result = io::read_raw_file(&arguments.args[0]); match result { Ok(binary) => { diff --git a/duckscript_sdk/src/sdk/std/fs/read_text/mod.rs b/duckscript_sdk/src/sdk/std/fs/read_text/mod.rs index ba1c4e93..c659c885 100755 --- a/duckscript_sdk/src/sdk/std/fs/read_text/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/read_text/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("File name not provided.".to_string()) } else { - let result = io::read_text_file(&arguments[0]); + let result = io::read_text_file(&arguments.args[0]); match result { Ok(text) => CommandResult::Continue(Some(text)), diff --git a/duckscript_sdk/src/sdk/std/fs/rm/mod.rs b/duckscript_sdk/src/sdk/std/fs/rm/mod.rs index 860d222b..97afecc7 100755 --- a/duckscript_sdk/src/sdk/std/fs/rm/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/rm/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{flags, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::fs; use std::path::Path; @@ -29,24 +29,24 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() - || (arguments.len() == 1 && flags::is_unix_flags_argument(&arguments[0])) + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() + || (arguments.args.len() == 1 && flags::is_unix_flags_argument(&arguments.args[0])) { CommandResult::Error("Path not provided.".to_string()) } else { - let (start_index, recursive) = if arguments.len() == 1 { + let (start_index, recursive) = if arguments.args.len() == 1 { (0, false) - } else if flags::is_unix_flags_argument(&arguments[0]) { - let recursive = flags::is_unix_flag_exists('r', &arguments[0]); + } else if flags::is_unix_flags_argument(&arguments.args[0]) { + let recursive = flags::is_unix_flag_exists('r', &arguments.args[0]); (1, recursive) } else { (0, false) }; - let end_index = arguments.len(); + let end_index = arguments.args.len(); for index in start_index..end_index { - let path = Path::new(&arguments[index]); + let path = Path::new(&arguments.args[index]); let result = if !path.exists() { Ok(()) diff --git a/duckscript_sdk/src/sdk/std/fs/rmdir/mod.rs b/duckscript_sdk/src/sdk/std/fs/rmdir/mod.rs index ff79b55a..692e0a0c 100755 --- a/duckscript_sdk/src/sdk/std/fs/rmdir/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/rmdir/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::fs; use std::path::Path; @@ -29,15 +29,15 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Directory path not provided.".to_string()) } else { - let path = Path::new(&arguments[0]); + let path = Path::new(&arguments.args[0]); if !path.exists() { CommandResult::Continue(Some("true".to_string())) } else { - let result = fs::remove_dir(&arguments[0]); + let result = fs::remove_dir(&arguments.args[0]); match result { Ok(_) => CommandResult::Continue(Some("true".to_string())), diff --git a/duckscript_sdk/src/sdk/std/fs/set_mode/mod.rs b/duckscript_sdk/src/sdk/std/fs/set_mode/mod.rs index 7e57547b..1644a20f 100755 --- a/duckscript_sdk/src/sdk/std/fs/set_mode/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/set_mode/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::as_path::AsPath; #[cfg(test)] @@ -58,15 +58,15 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Path/Mode not provided.".to_string()) } else { - let path = &arguments[1].as_path(); + let path = &arguments.args[1].as_path(); if path.exists() { - set_mode(&arguments[1], &arguments[0]) + set_mode(&arguments.args[1], &arguments.args[0]) } else { - CommandResult::Error(format!("Path: {} not found.", &arguments[1]).to_string()) + CommandResult::Error(format!("Path: {} not found.", &arguments.args[1]).to_string()) } } } diff --git a/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs b/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs index fd957fd1..189c2043 100755 --- a/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/temp_dir/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::from_path::FromPath; use std::env; @@ -29,7 +29,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { let directory_path = env::temp_dir(); let directory = FromPath::from_path(&directory_path); diff --git a/duckscript_sdk/src/sdk/std/fs/temp_file/mod.rs b/duckscript_sdk/src/sdk/std/fs/temp_file/mod.rs index 4a4ab37e..1d585682 100755 --- a/duckscript_sdk/src/sdk/std/fs/temp_file/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/temp_file/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::get_temporary_file_path; #[cfg(test)] @@ -28,11 +28,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let extension = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let extension = if arguments.args.is_empty() { "tmp" } else { - &arguments[0] + &arguments.args[0] }; let path = get_temporary_file_path(extension); diff --git a/duckscript_sdk/src/sdk/std/fs/touch/mod.rs b/duckscript_sdk/src/sdk/std/fs/touch/mod.rs index 97d5aced..732b0921 100755 --- a/duckscript_sdk/src/sdk/std/fs/touch/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/touch/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Path not provided.".to_string()) } else { - match io::create_empty_file(&arguments[0]) { + match io::create_empty_file(&arguments.args[0]) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(_) => CommandResult::Continue(Some("false".to_string())), } diff --git a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs index 49ffc5d1..ef5714ec 100755 --- a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs @@ -1,6 +1,6 @@ use crate::utils::state::get_handles_sub_state; use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -47,19 +47,19 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("File name and text not provided.".to_string()) - } else if arguments.len() == 1 { + } else if arguments.args.len() == 1 { CommandResult::Error("Binary data handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[1]; + let key = &arguments.args[1]; match state.get(key) { Some(state_value) => match state_value { StateValue::ByteArray(binary) => { - let result = io::write_to_file(&arguments[0], &binary, false); + let result = io::write_to_file(&arguments.args[0], &binary, false); match result { Ok(_) => CommandResult::Continue(Some("true".to_string())), diff --git a/duckscript_sdk/src/sdk/std/fs/write_text/mod.rs b/duckscript_sdk/src/sdk/std/fs/write_text/mod.rs index 2870a3df..a36b71ae 100755 --- a/duckscript_sdk/src/sdk/std/fs/write_text/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/write_text/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,13 +27,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("File name and text not provided.".to_string()) - } else if arguments.len() == 1 { + } else if arguments.args.len() == 1 { CommandResult::Error("Text not provided.".to_string()) } else { - let result = io::write_text_file(&arguments[0], &arguments[1]); + let result = io::write_text_file(&arguments.args[0], &arguments.args[1]); match result { Ok(_) => CommandResult::Continue(Some("true".to_string())), diff --git a/duckscript_sdk/src/sdk/std/fs/zip/unzip/mod.rs b/duckscript_sdk/src/sdk/std/fs/zip/unzip/mod.rs index f2b42cbe..7e0d1a63 100644 --- a/duckscript_sdk/src/sdk/std/fs/zip/unzip/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/zip/unzip/mod.rs @@ -3,7 +3,7 @@ use std::path::Path; use zip::ZipArchive; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use crate::utils::pckg; @@ -29,15 +29,15 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { return CommandResult::Error( "Paths to the ZIP file and/or target directory are not provided.".to_string(), ); } - let zipfile = Path::new(&arguments[0]); - let target_dir = Path::new(&arguments[1]); + let zipfile = Path::new(&arguments.args[0]); + let target_dir = Path::new(&arguments.args[1]); match std::fs::create_dir_all(target_dir) { Ok(_) => (), diff --git a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs index 7fe59946..975f26d9 100644 --- a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{pckg, state}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -45,7 +45,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -54,7 +54,7 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() < 2 { + if arguments.args.len() < 2 { return CommandResult::Error( "Paths to the ZIP file and/or files to pack are not provided.".to_string(), ); diff --git a/duckscript_sdk/src/sdk/std/hash/digest/mod.rs b/duckscript_sdk/src/sdk/std/hash/digest/mod.rs index 6207fd8d..abbab277 100755 --- a/duckscript_sdk/src/sdk/std/hash/digest/mod.rs +++ b/duckscript_sdk/src/sdk/std/hash/digest/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use core::fmt::Write; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use sha2::{Digest, Sha256, Sha512}; use std::fs::File; use std::io::Read; @@ -145,8 +145,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No input provided.".to_string()) } else { match parse_options(&arguments) { diff --git a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs index 15a325d4..2be5ce7a 100755 --- a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -46,10 +46,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Command name not provided.".to_string()) } else { - let result = commands.exists(&arguments[0]); + let result = commands.exists(&arguments.args[0]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/json/encode/mod.rs b/duckscript_sdk/src/sdk/std/json/encode/mod.rs index 29ba7f52..f094d92f 100755 --- a/duckscript_sdk/src/sdk/std/json/encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/encode/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::json::OBJECT_VALUE; use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -206,7 +206,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -215,24 +215,25 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("No JSON root variable name provided.".to_string()) } else { - let (start_index, as_state) = if arguments.len() > 1 && arguments[0] == "--collection" { - (1, true) - } else { - (0, false) - }; + let (start_index, as_state) = + if arguments.args.len() > 1 && arguments.args[0] == "--collection" { + (1, true) + } else { + (0, false) + }; if as_state { let state = get_handles_sub_state(state); - match encode_from_state(&arguments[start_index], state) { + match encode_from_state(&arguments.args[start_index], state) { Ok(output) => CommandResult::Continue(Some(output)), Err(error) => CommandResult::Error(error), } } else { - match encode_from_variables(&arguments[start_index], variables) { + match encode_from_variables(&arguments.args[start_index], variables) { Ok(output) => CommandResult::Continue(Some(output)), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/json/parse/mod.rs b/duckscript_sdk/src/sdk/std/json/parse/mod.rs index 15792085..b7bfd480 100755 --- a/duckscript_sdk/src/sdk/std/json/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/parse/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::json::OBJECT_VALUE; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -111,7 +111,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, output_variable: Option, @@ -120,16 +120,17 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("No JSON string provided.".to_string()) } else { - let (json_index, as_state) = if arguments.len() > 1 && arguments[0] == "--collection" { - (1, true) - } else { - (0, false) - }; - - match parse_json(&arguments[json_index]) { + let (json_index, as_state) = + if arguments.args.len() > 1 && arguments.args[0] == "--collection" { + (1, true) + } else { + (0, false) + }; + + match parse_json(&arguments.args[json_index]) { Ok(data) => { let output = match output_variable { Some(name) => { diff --git a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs index 95c9c4ea..f150b7cd 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::lib::alias::ALIAS_STATE_KEY; use crate::utils::state::get_sub_state; use crate::utils::{eval, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -13,14 +13,14 @@ mod mod_test; fn create_alias_command( name: String, - arguments: Vec, + arguments: CommandArgs, commands: &mut Commands, sub_state: &mut HashMap, ) -> Result<(), String> { #[derive(Clone)] struct AliasCommand { name: String, - arguments: Vec, + arguments: CommandArgs, } impl Command for AliasCommand { @@ -42,7 +42,7 @@ fn create_alias_command( fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -101,7 +101,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -110,14 +110,14 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() < 2 { + if arguments.args.len() < 2 { CommandResult::Error("Invalid alias provided.".to_string()) } else { - let name = arguments[0].clone(); + let name = arguments.args[0].clone(); let sub_state = get_sub_state(ALIAS_STATE_KEY.to_string(), state); - match create_alias_command(name, arguments[1..].to_vec(), commands, sub_state) { + match create_alias_command(name, arguments.args[1..].to_vec(), commands, sub_state) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs index 6f4b88e3..8557df10 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::lib::alias::ALIAS_STATE_KEY; use crate::utils::pckg; use crate::utils::state::get_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,12 +48,12 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() != 1 { + if arguments.args.len() != 1 { CommandResult::Error("Invalid alias name provided.".to_string()) } else { let sub_state = get_sub_state(ALIAS_STATE_KEY.to_string(), state); - let key = &arguments[0]; + let key = &arguments.args[0]; let removed = if sub_state.contains_key(key) { if commands.remove(key) { sub_state.remove(key); diff --git a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs index 5fcc3743..5d46e5ba 100755 --- a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -46,10 +46,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() != 1 { + if arguments.args.len() != 1 { CommandResult::Error("Invalid command name provided.".to_string()) } else { - let removed = commands.remove(&arguments[0]); + let removed = commands.remove(&arguments.args[0]); CommandResult::Continue(Some(removed.to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/man/mod.rs b/duckscript_sdk/src/sdk/std/man/mod.rs index 18a05f0e..9ba72ce2 100755 --- a/duckscript_sdk/src/sdk/std/man/mod.rs +++ b/duckscript_sdk/src/sdk/std/man/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -11,10 +11,15 @@ mod mod_test; fn print_help(env: &mut Env, help_doc: String, name: &str) -> CommandResult { if help_doc.is_empty() { - writeln!(env.out, "No documentation found for command: {}", name).unwrap(); + writeln!( + arguments.env.out, + "No documentation found for command: {}", + name + ) + .unwrap(); CommandResult::Continue(None) } else { - writeln!(env.out, "{}", &help_doc).unwrap(); + writeln!(arguments.env.out, "{}", &help_doc).unwrap(); CommandResult::Continue(Some(help_doc)) } } @@ -47,7 +52,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -56,10 +61,10 @@ impl Command for CommandImpl { _line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { print_help(env, self.help(), &self.name()) } else { - let name = &arguments[0]; + let name = &arguments.args[0]; match commands.get(name) { Some(command) => { @@ -70,7 +75,7 @@ impl Command for CommandImpl { if name == &self.name() || self.aliases().contains(name) { print_help(env, self.help(), &self.name()) } else { - writeln!(env.out, "Command: {} not found.", name).unwrap(); + writeln!(arguments.env.out, "Command: {} not found.", name).unwrap(); CommandResult::Continue(None) } } diff --git a/duckscript_sdk/src/sdk/std/math/calc/mod.rs b/duckscript_sdk/src/sdk/std/math/calc/mod.rs index b8849699..d6d0b75a 100755 --- a/duckscript_sdk/src/sdk/std/math/calc/mod.rs +++ b/duckscript_sdk/src/sdk/std/math/calc/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Missing input.".to_string()) } else { - let operation = arguments.join(" "); + let operation = arguments.args.join(" "); match evalexpr::eval_number(&operation) { Ok(value) => CommandResult::Continue(Some(value.to_string())), diff --git a/duckscript_sdk/src/sdk/std/math/greater_than/mod.rs b/duckscript_sdk/src/sdk/std/math/greater_than/mod.rs index c93d00fa..ae5d35a9 100755 --- a/duckscript_sdk/src/sdk/std/math/greater_than/mod.rs +++ b/duckscript_sdk/src/sdk/std/math/greater_than/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,23 +27,23 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() != 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() != 2 { CommandResult::Error("Invalid/Missing input.".to_string()) } else { - let left: f64 = match arguments[0].parse() { + let left: f64 = match arguments.args[0].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[0]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[0]).to_string(), ); } }; - let right: f64 = match arguments[1].parse() { + let right: f64 = match arguments.args[1].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[1]).to_string(), ); } }; diff --git a/duckscript_sdk/src/sdk/std/math/hex_decode/mod.rs b/duckscript_sdk/src/sdk/std/math/hex_decode/mod.rs index 27b48bb8..20ee356f 100644 --- a/duckscript_sdk/src/sdk/std/math/hex_decode/mod.rs +++ b/duckscript_sdk/src/sdk/std/math/hex_decode/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Value not provided.".to_string()) } else { - match u64::from_str_radix(arguments[0].trim_start_matches("0x"), 16) { + match u64::from_str_radix(arguments.args[0].trim_start_matches("0x"), 16) { Ok(num) => CommandResult::Continue(Some(num.to_string())), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/math/hex_encode/mod.rs b/duckscript_sdk/src/sdk/std/math/hex_encode/mod.rs index 7c0fed59..a3bf211c 100644 --- a/duckscript_sdk/src/sdk/std/math/hex_encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/math/hex_encode/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Value not provided.".to_string()) } else { - match &arguments[0].parse::() { + match &arguments.args[0].parse::() { Ok(num) => CommandResult::Continue(Some(format!("{:#x}", num))), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/math/less_than/mod.rs b/duckscript_sdk/src/sdk/std/math/less_than/mod.rs index f12ce020..ee149432 100755 --- a/duckscript_sdk/src/sdk/std/math/less_than/mod.rs +++ b/duckscript_sdk/src/sdk/std/math/less_than/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,23 +27,23 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() != 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() != 2 { CommandResult::Error("Invalid/Missing input.".to_string()) } else { - let left: f64 = match arguments[0].parse() { + let left: f64 = match arguments.args[0].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[0]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[0]).to_string(), ); } }; - let right: f64 = match arguments[1].parse() { + let right: f64 = match arguments.args[1].parse() { Ok(value) => value, Err(_) => { return CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[1]).to_string(), ); } }; diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs index 4704c664..dcd86278 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::net::ftp::{validate_and_run_with_connection, Options}; use crate::utils::io::create_empty_file; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::fs::OpenOptions; use std::io::{BufWriter, Error, Read, Write}; use suppaftp::{FtpError, FtpStream}; @@ -54,7 +54,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( &arguments, &|options: &Options| -> Result<(), String> { diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs index 79928421..b3318bfa 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::net::ftp::{validate_and_run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -40,7 +40,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs index 66bb7ade..9fb30866 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::net::ftp::{run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -40,7 +40,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs index a81d212d..400de7af 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::net::ftp::{run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -40,7 +40,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs index 68daa05b..bf2f03a6 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs @@ -1,6 +1,6 @@ use crate::sdk::std::net::ftp::{validate_and_run_with_connection, Options}; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::path::as_path::AsPath; use std::fs::File; use suppaftp::FtpStream; @@ -31,7 +31,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( &arguments, &|options: &Options| -> Result<(), String> { diff --git a/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs index 8b43bdc9..3968658f 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs @@ -1,6 +1,6 @@ use crate::sdk::std::net::ftp::{validate_and_run_with_connection, Options}; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::io::Cursor; use suppaftp::FtpStream; @@ -30,7 +30,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( &arguments, &|options: &Options| -> Result<(), String> { diff --git a/duckscript_sdk/src/sdk/std/net/hostname/mod.rs b/duckscript_sdk/src/sdk/std/net/hostname/mod.rs index 558160c8..2c989559 100755 --- a/duckscript_sdk/src/sdk/std/net/hostname/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/hostname/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { match whoami::fallible::hostname() { Ok(hostname) => CommandResult::Continue(Some(hostname)), Err(error) => CommandResult::Error(error.to_string()), diff --git a/duckscript_sdk/src/sdk/std/net/http_client/mod.rs b/duckscript_sdk/src/sdk/std/net/http_client/mod.rs index 73a8b6e3..457112df 100755 --- a/duckscript_sdk/src/sdk/std/net/http_client/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/http_client/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use fsio::directory::create_parent; use fsio::file::delete; use std::fs::File; @@ -149,18 +149,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("URL not provided.".to_string()) } else { - let len = arguments.len() - 1; - let url = arguments[len].to_string(); + let len = arguments.args.len() - 1; + let url = arguments.args[len].to_string(); let url_lowercase = url.to_lowercase(); if !url_lowercase.starts_with("http://") && !url_lowercase.starts_with("https://") { CommandResult::Error(format!("Invalid URL: {} provided.", &url).to_string()) } else { - match parse_options(&arguments[0..len].to_vec()) { + match parse_options(&arguments.args[0..len].to_vec()) { Ok(options) => do_request(url, options), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/noop/mod.rs b/duckscript_sdk/src/sdk/std/noop/mod.rs index d5211866..75434511 100755 --- a/duckscript_sdk/src/sdk/std/noop/mod.rs +++ b/duckscript_sdk/src/sdk/std/noop/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } diff --git a/duckscript_sdk/src/sdk/std/not/mod.rs b/duckscript_sdk/src/sdk/std/not/mod.rs index 49b5678b..3b010544 100755 --- a/duckscript_sdk/src/sdk/std/not/mod.rs +++ b/duckscript_sdk/src/sdk/std/not/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -46,7 +46,7 @@ impl Command for CommandImpl { _line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match condition::eval_condition( diff --git a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs index feeba8cb..8f98e259 100755 --- a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::on_error::{get_value, EXIT_ON_ERROR_KEY, STATE_KEY}; use crate::utils::state::get_core_sub_state_for_command; use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,11 +48,11 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - let exit_on_error = if arguments.is_empty() { + let exit_on_error = if arguments.args.is_empty() { let value_string = get_value(state, EXIT_ON_ERROR_KEY.to_string()); condition::is_true(value_string) } else { - let exit_on_error = condition::is_true(Some(arguments[0].clone())); + let exit_on_error = condition::is_true(Some(arguments.args[0].clone())); let sub_state = get_core_sub_state_for_command(state, STATE_KEY.to_string()); sub_state.insert( diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs index 2ce353e3..73842817 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs @@ -1,6 +1,6 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs index 60fa311b..9dc5d81e 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs @@ -1,6 +1,6 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs index 62eceed6..65105378 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs @@ -1,6 +1,6 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs index 1d2bb16b..b72e5e15 100755 --- a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::on_error::{get_value, EXIT_ON_ERROR_KEY, STATE_KEY}; use crate::utils::state::get_core_sub_state_for_command; use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,8 +48,8 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if !arguments.is_empty() { - let error = arguments[0].clone(); + if !arguments.args.is_empty() { + let error = arguments.args[0].clone(); let exit_on_error = get_value(state, EXIT_ON_ERROR_KEY.to_string()); let should_crash = condition::is_true(exit_on_error); @@ -57,10 +57,10 @@ impl Command for CommandImpl { if should_crash { CommandResult::Crash(error) } else { - let (line, source) = if arguments.len() > 1 { - let line = arguments[1].clone(); - let source = if arguments.len() > 2 { - arguments[2].clone() + let (line, source) = if arguments.args.len() > 1 { + let line = arguments.args[1].clone(); + let source = if arguments.args.len() > 2 { + arguments.args[2].clone() } else { "".to_string() }; diff --git a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs index e33d06e6..2b3b7885 100755 --- a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs @@ -1,7 +1,7 @@ use crate::sdk::std::on_error::STATE_KEY; use crate::utils::pckg; use crate::utils::state::get_core_sub_state_for_command; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,8 +48,8 @@ impl Command for CommandImpl { line: usize, _env: &mut Env, ) -> CommandResult { - if !arguments.is_empty() { - let error = arguments[0].clone(); + if !arguments.args.is_empty() { + let error = arguments.args[0].clone(); let sub_state = get_core_sub_state_for_command(state, STATE_KEY.to_string()); sub_state.insert("error".to_string(), StateValue::String(error)); diff --git a/duckscript_sdk/src/sdk/std/on_error/trigger_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/trigger_error/mod.rs index 8965660c..5bf469a6 100755 --- a/duckscript_sdk/src/sdk/std/on_error/trigger_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/trigger_error/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let message = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let message = if arguments.args.is_empty() { "Error".to_string() } else { - arguments[0].clone() + arguments.args[0].clone() }; CommandResult::Error(message) diff --git a/duckscript_sdk/src/sdk/std/print/mod.rs b/duckscript_sdk/src/sdk/std/print/mod.rs index 839e5b2b..8043d33e 100755 --- a/duckscript_sdk/src/sdk/std/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/print/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use colored::{Color, ColoredString, Colorize}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -138,7 +138,7 @@ fn add_color( } } -pub(crate) fn run_print(env: &mut Env, arguments: Vec) -> CommandResult { +pub(crate) fn run_print(env: &mut Env, arguments: CommandArgs) -> CommandResult { // collect options let mut styles = vec![]; let mut text_color = None; @@ -176,7 +176,7 @@ pub(crate) fn run_print(env: &mut Env, arguments: Vec) -> CommandResult // generate whole string let mut string = String::new(); let mut count = 0; - for argument in &arguments[index..] { + for argument in &arguments.args[index..] { count = count + 1; string.push_str(argument); string.push(' '); @@ -191,7 +191,7 @@ pub(crate) fn run_print(env: &mut Env, arguments: Vec) -> CommandResult styled_string = add_color(styled_string, background_color, true); styled_string = add_styles(styled_string, styles); - match write!(env.out, "{}", styled_string) { + match write!(arguments.env.out, "{}", styled_string) { Ok(_) => CommandResult::Continue(Some(count.to_string())), Err(error) => CommandResult::Error(error.to_string()), } @@ -225,7 +225,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/println/mod.rs b/duckscript_sdk/src/sdk/std/println/mod.rs index e914d11e..549190c6 100755 --- a/duckscript_sdk/src/sdk/std/println/mod.rs +++ b/duckscript_sdk/src/sdk/std/println/mod.rs @@ -1,6 +1,6 @@ use crate::sdk::std::print::run_print; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -50,7 +50,7 @@ impl Command for CommandImpl { let result = run_print(env, arguments); if let CommandResult::Continue(ref _value) = result { - match writeln!(env.out, "") { + match writeln!(arguments.env.out, "") { Ok(_) => result, Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/process/exec/mod.rs b/duckscript_sdk/src/sdk/std/process/exec/mod.rs index 1025eaf7..e9cb7b2f 100755 --- a/duckscript_sdk/src/sdk/std/process/exec/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/exec/mod.rs @@ -1,6 +1,6 @@ use crate::utils::exec::ExecInput; use crate::utils::{exec, pckg}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -43,7 +43,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/process/exit/mod.rs b/duckscript_sdk/src/sdk/std/process/exit/mod.rs index 31890072..fe18bcc2 100755 --- a/duckscript_sdk/src/sdk/std/process/exit/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/exit/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,15 +27,15 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Exit(Some("0".to_string())) } else { - match arguments[0].parse::() { - Ok(_) => CommandResult::Exit(Some(arguments[0].clone())), - Err(_) => { - CommandResult::Error(format!("Invalid exit code: {}", arguments[0]).to_string()) - } + match arguments.args[0].parse::() { + Ok(_) => CommandResult::Exit(Some(arguments.args[0].clone())), + Err(_) => CommandResult::Error( + format!("Invalid exit code: {}", arguments.args[0]).to_string(), + ), } } } diff --git a/duckscript_sdk/src/sdk/std/process/process_id/mod.rs b/duckscript_sdk/src/sdk/std/process/process_id/mod.rs index 7dddf8d6..cc394b0c 100755 --- a/duckscript_sdk/src/sdk/std/process/process_id/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/process_id/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::process; #[cfg(test)] @@ -28,7 +28,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { let id = process::id(); CommandResult::Continue(Some(id.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/process/spawn/mod.rs b/duckscript_sdk/src/sdk/std/process/spawn/mod.rs index e65ab959..b25f7c0b 100755 --- a/duckscript_sdk/src/sdk/std/process/spawn/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/spawn/mod.rs @@ -1,6 +1,6 @@ use crate::utils::exec::ExecInput; use crate::utils::{exec, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -33,7 +33,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut print_output = true; let mut input = ExecInput::None; let mut command_start_index = 0; diff --git a/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs b/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs index 97418305..efb3df25 100755 --- a/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs @@ -1,6 +1,6 @@ use crate::utils::exec::ExecInput; use crate::utils::{exec, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::thread; use std::time::Duration; @@ -37,8 +37,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("Command not provided.".to_string()) } else { let mut max_retries: isize = -1; diff --git a/duckscript_sdk/src/sdk/std/random/range/mod.rs b/duckscript_sdk/src/sdk/std/random/range/mod.rs index 37ce403a..5aa1d5b3 100755 --- a/duckscript_sdk/src/sdk/std/random/range/mod.rs +++ b/duckscript_sdk/src/sdk/std/random/range/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use rand::{thread_rng, Rng}; #[cfg(test)] @@ -28,12 +28,12 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Missing random min/max values.".to_string()) } else { - match arguments[0].parse() { - Ok(min) => match arguments[1].parse() { + match arguments.args[0].parse() { + Ok(min) => match arguments.args[1].parse() { Ok(max) => { if min > max { CommandResult::Error( @@ -51,11 +51,12 @@ impl Command for CommandImpl { } } Err(_) => CommandResult::Error( - format!("Non numeric max value: {} provided.", &arguments[1]).to_string(), + format!("Non numeric max value: {} provided.", &arguments.args[1]) + .to_string(), ), }, Err(_) => CommandResult::Error( - format!("Non numeric min value: {} provided.", &arguments[0]).to_string(), + format!("Non numeric min value: {} provided.", &arguments.args[0]).to_string(), ), } } diff --git a/duckscript_sdk/src/sdk/std/random/text/mod.rs b/duckscript_sdk/src/sdk/std/random/text/mod.rs index 75b9c864..7877b501 100755 --- a/duckscript_sdk/src/sdk/std/random/text/mod.rs +++ b/duckscript_sdk/src/sdk/std/random/text/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use rand::distributions::Alphanumeric; use rand::{thread_rng, Rng}; use std::iter; @@ -30,18 +30,18 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let length = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let length = if arguments.args.is_empty() { 1 } else { - match arguments[0].parse() { + match arguments.args[0].parse() { Ok(value) => { let value_usize: usize = value; value_usize } Err(_) => { return CommandResult::Error( - format!("Invalid length provided: {}", &arguments[0]).to_string(), + format!("Invalid length provided: {}", &arguments.args[0]).to_string(), ) } } diff --git a/duckscript_sdk/src/sdk/std/read/mod.rs b/duckscript_sdk/src/sdk/std/read/mod.rs index c1898f9d..263ef97a 100755 --- a/duckscript_sdk/src/sdk/std/read/mod.rs +++ b/duckscript_sdk/src/sdk/std/read/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::io::stdin; #[cfg(test)] @@ -28,7 +28,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { let mut text = String::new(); let value = match stdin().read_line(&mut text) { diff --git a/duckscript_sdk/src/sdk/std/release/mod.rs b/duckscript_sdk/src/sdk/std/release/mod.rs index ddc41e0c..21913b3b 100755 --- a/duckscript_sdk/src/sdk/std/release/mod.rs +++ b/duckscript_sdk/src/sdk/std/release/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{remove_handle, remove_handle_recursive}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -47,15 +47,16 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Continue(Some("false".to_string())) } else { - let (key, recursive) = - if arguments.len() > 1 && (arguments[0] == "-r" || arguments[0] == "--recursive") { - (arguments[1].to_string(), true) - } else { - (arguments[0].to_string(), false) - }; + let (key, recursive) = if arguments.args.len() > 1 + && (arguments.args[0] == "-r" || arguments.args[0] == "--recursive") + { + (arguments.args[1].to_string(), true) + } else { + (arguments.args[0].to_string(), false) + }; let removed = if recursive { remove_handle_recursive(state, key) diff --git a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs index c2a5e729..38b4dcf5 100755 --- a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs @@ -1,6 +1,6 @@ use crate::types::scope::clear; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -47,10 +47,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Scope name not provided.".to_string()) } else { - clear(&arguments[0], variables); + clear(&arguments.args[0], variables); CommandResult::Continue(None) } diff --git a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs index f24bc87a..9e75d438 100755 --- a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{pckg, scope}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -46,10 +46,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - let copy = if arguments.is_empty() { + let copy = if arguments.args.is_empty() { &[] - } else if arguments[0] == "--copy" { - &arguments[1..] + } else if arguments.args[0] == "--copy" { + &arguments.args[1..] } else { &[] }; diff --git a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs index 5e632956..64c42034 100755 --- a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{pckg, scope}; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -46,10 +46,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - let copy = if arguments.is_empty() { + let copy = if arguments.args.is_empty() { &[] - } else if arguments[0] == "--copy" { - &arguments[1..] + } else if arguments.args[0] == "--copy" { + &arguments.args[1..] } else { &[] }; diff --git a/duckscript_sdk/src/sdk/std/semver/is_equal/mod.rs b/duckscript_sdk/src/sdk/std/semver/is_equal/mod.rs index fd209196..cf301bdd 100755 --- a/duckscript_sdk/src/sdk/std/semver/is_equal/mod.rs +++ b/duckscript_sdk/src/sdk/std/semver/is_equal/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use semver::Version; #[cfg(test)] @@ -28,12 +28,12 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Missing semver values to compare.".to_string()) } else { - match Version::parse(&arguments[0]) { - Ok(version1) => match Version::parse(&arguments[1]) { + match Version::parse(&arguments.args[0]) { + Ok(version1) => match Version::parse(&arguments.args[1]) { Ok(version2) => { let result = if version1 == version2 { true } else { false }; diff --git a/duckscript_sdk/src/sdk/std/semver/is_newer/mod.rs b/duckscript_sdk/src/sdk/std/semver/is_newer/mod.rs index 20d4a2ca..0efb7b9f 100755 --- a/duckscript_sdk/src/sdk/std/semver/is_newer/mod.rs +++ b/duckscript_sdk/src/sdk/std/semver/is_newer/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use semver::Version; #[cfg(test)] @@ -28,12 +28,12 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Missing semver values to compare.".to_string()) } else { - match Version::parse(&arguments[0]) { - Ok(newer_version) => match Version::parse(&arguments[1]) { + match Version::parse(&arguments.args[0]) { + Ok(newer_version) => match Version::parse(&arguments.args[1]) { Ok(older_version) => { let result = if newer_version > older_version { true diff --git a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs index 3307abc9..43043be0 100755 --- a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, output_variable: Option, @@ -47,10 +47,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("No semver value provided.".to_string()) } else { - match Version::parse(&arguments[0]) { + match Version::parse(&arguments.args[0]) { Ok(version) => match output_variable { Some(name) => { variables.insert( diff --git a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs index 6ac0a073..007ca54c 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs @@ -1,7 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use base64::Engine; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,10 +48,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Value not provided.".to_string()) } else { - match base64::engine::general_purpose::STANDARD.decode(&arguments[0]) { + match base64::engine::general_purpose::STANDARD.decode(&arguments.args[0]) { Ok(binary) => { let key = put_handle(state, StateValue::ByteArray(binary)); diff --git a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs index 3c4a2b61..fbd7f057 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs @@ -1,7 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use base64::Engine; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,12 +48,12 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs index eac19f5a..c7fa63ec 100755 --- a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -39,7 +39,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -48,12 +48,12 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { let state = get_handles_sub_state(state); - let key = &arguments[0]; + let key = &arguments.args[0]; match state.get(key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/string/camelcase/mod.rs b/duckscript_sdk/src/sdk/std/string/camelcase/mod.rs index e41308b4..5ed00fb2 100755 --- a/duckscript_sdk/src/sdk/std/string/camelcase/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/camelcase/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No arguments provided.".to_string()) } else { - let value = heck::ToUpperCamelCase::to_upper_camel_case(arguments[0].as_str()); + let value = heck::ToUpperCamelCase::to_upper_camel_case(arguments.args[0].as_str()); CommandResult::Continue(Some(value)) } } diff --git a/duckscript_sdk/src/sdk/std/string/contains/mod.rs b/duckscript_sdk/src/sdk/std/string/contains/mod.rs index cb500428..754c8a9f 100755 --- a/duckscript_sdk/src/sdk/std/string/contains/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/contains/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Two arguments are required.".to_string()) } else { - let result = arguments[0].contains(&arguments[1]); + let result = arguments.args[0].contains(&arguments.args[1]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/string/ends_with/mod.rs b/duckscript_sdk/src/sdk/std/string/ends_with/mod.rs index b0a6c90d..89f101d4 100755 --- a/duckscript_sdk/src/sdk/std/string/ends_with/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/ends_with/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Two arguments are required.".to_string()) } else { - let result = arguments[0].ends_with(&arguments[1]); + let result = arguments.args[0].ends_with(&arguments.args[1]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/string/equals/mod.rs b/duckscript_sdk/src/sdk/std/string/equals/mod.rs index 5a289852..f3852237 100755 --- a/duckscript_sdk/src/sdk/std/string/equals/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/equals/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Two arguments are required.".to_string()) } else { - let result = arguments[0] == arguments[1]; + let result = arguments.args[0] == arguments.args[1]; CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/string/indexof/mod.rs b/duckscript_sdk/src/sdk/std/string/indexof/mod.rs index 37ca41af..10dec53b 100755 --- a/duckscript_sdk/src/sdk/std/string/indexof/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/indexof/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Two arguments are required.".to_string()) } else { - let result = arguments[0].find(&arguments[1]); + let result = arguments.args[0].find(&arguments.args[1]); let result_string = match result { Some(value) => Some(value.to_string()), diff --git a/duckscript_sdk/src/sdk/std/string/is_empty/mod.rs b/duckscript_sdk/src/sdk/std/string/is_empty/mod.rs index e8bf4c3f..31cd8d45 100755 --- a/duckscript_sdk/src/sdk/std/string/is_empty/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/is_empty/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Continue(Some("true".to_string())) } else { - let result = arguments[0].is_empty(); + let result = arguments.args[0].is_empty(); CommandResult::Continue(Some(result.to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/string/kebabcase/mod.rs b/duckscript_sdk/src/sdk/std/string/kebabcase/mod.rs index 58f0a5ac..a2e9797a 100755 --- a/duckscript_sdk/src/sdk/std/string/kebabcase/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/kebabcase/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No arguments provided.".to_string()) } else { - let value = heck::ToKebabCase::to_kebab_case(arguments[0].as_str()); + let value = heck::ToKebabCase::to_kebab_case(arguments.args[0].as_str()); CommandResult::Continue(Some(value)) } } diff --git a/duckscript_sdk/src/sdk/std/string/last_indexof/mod.rs b/duckscript_sdk/src/sdk/std/string/last_indexof/mod.rs index 50f02f39..e42a991f 100755 --- a/duckscript_sdk/src/sdk/std/string/last_indexof/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/last_indexof/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Two arguments are required.".to_string()) } else { - let result = arguments[0].rfind(&arguments[1]); + let result = arguments.args[0].rfind(&arguments.args[1]); let result_string = match result { Some(value) => Some(value.to_string()), diff --git a/duckscript_sdk/src/sdk/std/string/length/mod.rs b/duckscript_sdk/src/sdk/std/string/length/mod.rs index dda570b6..869933c7 100755 --- a/duckscript_sdk/src/sdk/std/string/length/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/length/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No argument provided.".to_string()) } else { - let string_len = arguments[0].len(); + let string_len = arguments.args[0].len(); CommandResult::Continue(Some(string_len.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/string/lowercase/mod.rs b/duckscript_sdk/src/sdk/std/string/lowercase/mod.rs index 2c3283d2..21cccb94 100755 --- a/duckscript_sdk/src/sdk/std/string/lowercase/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/lowercase/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No arguments provided.".to_string()) } else { - let value = arguments[0].to_lowercase(); + let value = arguments.args[0].to_lowercase(); CommandResult::Continue(Some(value)) } } diff --git a/duckscript_sdk/src/sdk/std/string/replace/mod.rs b/duckscript_sdk/src/sdk/std/string/replace/mod.rs index 6b63796c..263212b2 100755 --- a/duckscript_sdk/src/sdk/std/string/replace/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/replace/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 3 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 3 { CommandResult::Error("Three arguments are required.".to_string()) } else { - let result = arguments[0].replace(&arguments[1], &arguments[2]); + let result = arguments.args[0].replace(&arguments.args[1], &arguments.args[2]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/string/snakecase/mod.rs b/duckscript_sdk/src/sdk/std/string/snakecase/mod.rs index ccbb81bc..7e94abc7 100755 --- a/duckscript_sdk/src/sdk/std/string/snakecase/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/snakecase/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No arguments provided.".to_string()) } else { - let value = heck::ToSnakeCase::to_snake_case(arguments[0].as_str()); + let value = heck::ToSnakeCase::to_snake_case(arguments.args[0].as_str()); CommandResult::Continue(Some(value)) } } diff --git a/duckscript_sdk/src/sdk/std/string/split/mod.rs b/duckscript_sdk/src/sdk/std/string/split/mod.rs index 396e7ae4..39dc1358 100755 --- a/duckscript_sdk/src/sdk/std/string/split/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/split/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -47,10 +47,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() < 2 { + if arguments.args.len() < 2 { CommandResult::Error("Invalid input provided.".to_string()) } else { - let split = arguments[0].split(&arguments[1]); + let split = arguments.args[0].split(&arguments.args[1]); let values = split.collect::>(); let mut array = vec![]; diff --git a/duckscript_sdk/src/sdk/std/string/starts_with/mod.rs b/duckscript_sdk/src/sdk/std/string/starts_with/mod.rs index bdc7ba08..f9b79190 100755 --- a/duckscript_sdk/src/sdk/std/string/starts_with/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/starts_with/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Error("Two arguments are required.".to_string()) } else { - let result = arguments[0].starts_with(&arguments[1]); + let result = arguments.args[0].starts_with(&arguments.args[1]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs index 970f17e7..dbf614e2 100755 --- a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -47,10 +47,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing input.".to_string()) } else { - let array = arguments[0].clone().into_bytes(); + let array = arguments.args[0].clone().into_bytes(); let key = put_handle(state, StateValue::ByteArray(array)); diff --git a/duckscript_sdk/src/sdk/std/string/substring/mod.rs b/duckscript_sdk/src/sdk/std/string/substring/mod.rs index cc6649e2..d1a9d4b8 100755 --- a/duckscript_sdk/src/sdk/std/string/substring/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/substring/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -34,17 +34,17 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No arguments provided.".to_string()) } else { - let string_value = arguments[0].clone(); + let string_value = arguments.args[0].clone(); let string_len = string_value.len() as isize; - let (start, end) = if arguments.len() == 1 { + let (start, end) = if arguments.args.len() == 1 { (0, string_len) - } else if arguments.len() == 2 { - match parse_number(&arguments[1]) { + } else if arguments.args.len() == 2 { + match parse_number(&arguments.args[1]) { Ok(value) => { if value >= 0 { if value > (string_len - 1) { @@ -71,7 +71,7 @@ impl Command for CommandImpl { Err(error) => return CommandResult::Error(error.to_string()), } } else { - let start = match parse_number(&arguments[1]) { + let start = match parse_number(&arguments.args[1]) { Ok(value) => { if value > (string_len - 1) { return CommandResult::Error( @@ -83,7 +83,7 @@ impl Command for CommandImpl { } Err(error) => return CommandResult::Error(error.to_string()), }; - let end = match parse_number(&arguments[2]) { + let end = match parse_number(&arguments.args[2]) { Ok(value) => { if value >= start { if value > (string_len - 1) { diff --git a/duckscript_sdk/src/sdk/std/string/trim/mod.rs b/duckscript_sdk/src/sdk/std/string/trim/mod.rs index a80e6507..9b994c56 100755 --- a/duckscript_sdk/src/sdk/std/string/trim/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/trim/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Continue(None) } else { - let result = arguments[0].trim(); + let result = arguments.args[0].trim(); CommandResult::Continue(Some(result.to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/string/trim_end/mod.rs b/duckscript_sdk/src/sdk/std/string/trim_end/mod.rs index 3c704c4b..eb333a34 100755 --- a/duckscript_sdk/src/sdk/std/string/trim_end/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/trim_end/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Continue(None) } else { - let result = arguments[0].trim_end(); + let result = arguments.args[0].trim_end(); CommandResult::Continue(Some(result.to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/string/trim_start/mod.rs b/duckscript_sdk/src/sdk/std/string/trim_start/mod.rs index 8e55e20d..572ce90c 100755 --- a/duckscript_sdk/src/sdk/std/string/trim_start/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/trim_start/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Continue(None) } else { - let result = arguments[0].trim_start(); + let result = arguments.args[0].trim_start(); CommandResult::Continue(Some(result.to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/string/uppercase/mod.rs b/duckscript_sdk/src/sdk/std/string/uppercase/mod.rs index 11d2a2f5..a183c8dc 100755 --- a/duckscript_sdk/src/sdk/std/string/uppercase/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/uppercase/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Error("No arguments provided.".to_string()) } else { - let value = arguments[0].to_uppercase(); + let value = arguments.args[0].to_uppercase(); CommandResult::Continue(Some(value)) } } diff --git a/duckscript_sdk/src/sdk/std/test/assert/mod.rs b/duckscript_sdk/src/sdk/std/test/assert/mod.rs index 0bd58acc..dc0e40b0 100755 --- a/duckscript_sdk/src/sdk/std/test/assert/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/assert/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,19 +27,19 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Crash("Assert failed, empty value.".to_string()) } else { - let passed = condition::is_true(Some(arguments[0].clone())); + let passed = condition::is_true(Some(arguments.args[0].clone())); if passed { CommandResult::Continue(Some("true".to_string())) } else { - let error_message = if arguments.len() == 1 { - format!("Assert failed, value is falsy: {}", &arguments[0]).to_string() + let error_message = if arguments.args.len() == 1 { + format!("Assert failed, value is falsy: {}", &arguments.args[0]).to_string() } else { - arguments[1].clone() + arguments.args[1].clone() }; CommandResult::Crash(error_message) diff --git a/duckscript_sdk/src/sdk/std/test/assert_eq/mod.rs b/duckscript_sdk/src/sdk/std/test/assert_eq/mod.rs index b56093cd..0d874dea 100755 --- a/duckscript_sdk/src/sdk/std/test/assert_eq/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/assert_eq/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,23 +27,23 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.len() < 2 { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.len() < 2 { CommandResult::Crash("Assert failed, two arguments are required.".to_string()) } else { - let passed = arguments[0] == arguments[1]; + let passed = arguments.args[0] == arguments.args[1]; if passed { CommandResult::Continue(Some("true".to_string())) } else { - let error_message = if arguments.len() == 2 { + let error_message = if arguments.args.len() == 2 { format!( "Assert failed, value: {} does not match: {}", - &arguments[0], &arguments[1] + &arguments.args[0], &arguments.args[1] ) .to_string() } else { - arguments[2].clone() + arguments.args[2].clone() }; CommandResult::Crash(error_message) diff --git a/duckscript_sdk/src/sdk/std/test/assert_error/mod.rs b/duckscript_sdk/src/sdk/std/test/assert_error/mod.rs index a7b004de..ab8958a8 100755 --- a/duckscript_sdk/src/sdk/std/test/assert_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/assert_error/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let error_message = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let error_message = if arguments.args.is_empty() { "Assert failed.".to_string() } else { - arguments[0].clone() + arguments.args[0].clone() }; CommandResult::Error(error_message) diff --git a/duckscript_sdk/src/sdk/std/test/assert_fail/mod.rs b/duckscript_sdk/src/sdk/std/test/assert_fail/mod.rs index e5793fd3..414373cc 100755 --- a/duckscript_sdk/src/sdk/std/test/assert_fail/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/assert_fail/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,11 +27,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let error_message = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let error_message = if arguments.args.is_empty() { "Assert failed.".to_string() } else { - arguments[0].clone() + arguments.args[0].clone() }; CommandResult::Crash(error_message) diff --git a/duckscript_sdk/src/sdk/std/test/assert_false/mod.rs b/duckscript_sdk/src/sdk/std/test/assert_false/mod.rs index f2cfa4e2..a8cf187c 100755 --- a/duckscript_sdk/src/sdk/std/test/assert_false/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/assert_false/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -27,17 +27,17 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Crash("Assert failed, empty value.".to_string()) } else { - let passed = condition::is_true(Some(arguments[0].clone())); + let passed = condition::is_true(Some(arguments.args[0].clone())); if passed { - let error_message = if arguments.len() == 1 { - format!("Assert failed, value is true: {}", &arguments[0]).to_string() + let error_message = if arguments.args.len() == 1 { + format!("Assert failed, value is true: {}", &arguments.args[0]).to_string() } else { - arguments[1].clone() + arguments.args[1].clone() }; CommandResult::Crash(error_message) diff --git a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs index 75035712..d3df8031 100755 --- a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use duckscript::runner; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::{Context, StateValue}; @@ -49,7 +49,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -58,18 +58,18 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Crash("Directory name not provided.".to_string()) } else { let mut script = String::new(); - let test_name = if arguments.len() > 1 { - arguments[1].clone() + let test_name = if arguments.args.len() > 1 { + arguments.args[1].clone() } else { "".to_string() }; - let walker = WalkDir::new(&arguments[0]) + let walker = WalkDir::new(&arguments.args[0]) .sort_by(|entry1, entry2| entry1.file_name().cmp(entry2.file_name())) .into_iter(); for entry in walker { diff --git a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs index b40dd6a5..3fb482bb 100755 --- a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::{Instruction, InstructionType}; use duckscript::types::runtime::{Context, StateValue}; @@ -49,7 +49,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -58,17 +58,17 @@ impl Command for CommandImpl { _line: usize, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Crash("File name not provided.".to_string()) } else { - let file = arguments[0].clone(); - let requested_test_name = if arguments.len() > 1 { - arguments[1].clone() + let file = arguments.args[0].clone(); + let requested_test_name = if arguments.args.len() > 1 { + arguments.args[1].clone() } else { "".to_string() }; - match parser::parse_file(&arguments[0]) { + match parser::parse_file(&arguments.args[0]) { Ok(instructions) => match commands.get("function") { Some(function_command) => { let mut command_names = function_command.aliases(); @@ -83,11 +83,12 @@ impl Command for CommandImpl { script_instruction.arguments.as_ref(), ) { (Some(current_command), Some(current_arguments)) => { - if !current_arguments.is_empty() + if !current_arguments.args.is_empty() && command_names.contains(¤t_command) { - if current_arguments[0].starts_with("test_") { - test_names.push(current_arguments[0].clone()); + if current_arguments.args[0].starts_with("test_") { + test_names + .push(current_arguments.args[0].clone()); } } } @@ -110,7 +111,7 @@ impl Command for CommandImpl { match runner::run_script(&script, context, None) { Err(error) => { writeln!( - env.out, + arguments.env.out, "test: [{}][{}] ... failed", &file, &test_name ) @@ -126,7 +127,7 @@ impl Command for CommandImpl { ); } _ => writeln!( - env.out, + arguments.env.out, "test: [{}][{}] ... ok", &file, &test_name ) @@ -144,7 +145,7 @@ impl Command for CommandImpl { Err(error) => CommandResult::Crash( format!( "Error while parsing file: {}\n{}", - &arguments[0], + &arguments.args[0], &error.to_string() ) .to_string(), diff --git a/duckscript_sdk/src/sdk/std/thread/sleep/mod.rs b/duckscript_sdk/src/sdk/std/thread/sleep/mod.rs index e5ce8d75..5d308950 100755 --- a/duckscript_sdk/src/sdk/std/thread/sleep/mod.rs +++ b/duckscript_sdk/src/sdk/std/thread/sleep/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::thread; use std::time::Duration; @@ -29,11 +29,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Continue(Some("0".to_string())) } else { - match arguments[0].parse() { + match arguments.args[0].parse() { Ok(value) => { if value == 0 { CommandResult::Continue(Some("0".to_string())) @@ -48,7 +48,7 @@ impl Command for CommandImpl { } } Err(_) => CommandResult::Error( - format!("Non numeric value: {} provided.", &arguments[0]).to_string(), + format!("Non numeric value: {} provided.", &arguments.args[0]).to_string(), ), } } diff --git a/duckscript_sdk/src/sdk/std/time/current_time/mod.rs b/duckscript_sdk/src/sdk/std/time/current_time/mod.rs index a4e6a5bd..a1c97c45 100755 --- a/duckscript_sdk/src/sdk/std/time/current_time/mod.rs +++ b/duckscript_sdk/src/sdk/std/time/current_time/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::time::{SystemTime, UNIX_EPOCH}; #[cfg(test)] @@ -28,7 +28,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { match SystemTime::now().duration_since(UNIX_EPOCH) { Ok(value) => CommandResult::Continue(Some(value.as_millis().to_string())), Err(error) => CommandResult::Error(error.to_string()), diff --git a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs index 2ffa8d25..b3910ab9 100755 --- a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs @@ -1,6 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -38,7 +38,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - _arguments: Vec, + _arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs index e10a6ea1..dd75fc25 100755 --- a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -36,7 +36,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -45,10 +45,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - let output = if arguments.is_empty() { + let output = if arguments.args.is_empty() { None } else { - match variables.get(&arguments[0]) { + match variables.get(&arguments.args[0]) { Some(ref value) => Some(value.to_string()), None => None, } diff --git a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs index fa408c47..2a76aad7 100755 --- a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -46,10 +46,10 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Variable name not provided.".to_string()) } else { - let result = variables.contains_key(&arguments[0]); + let result = variables.contains_key(&arguments.args[0]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/var/set/mod.rs b/duckscript_sdk/src/sdk/std/var/set/mod.rs index 33c49243..9330493e 100755 --- a/duckscript_sdk/src/sdk/std/var/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/set/mod.rs @@ -1,5 +1,5 @@ use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandResult}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -53,11 +53,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - let output = if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let output = if arguments.args.is_empty() { None - } else if arguments.len() == 1 { - Some(arguments[0].clone()) + } else if arguments.args.len() == 1 { + Some(arguments.args[0].clone()) } else { match get_output(&arguments) { Ok(output) => output, diff --git a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs index b05184da..c63e7fb6 100755 --- a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -36,7 +36,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -45,14 +45,14 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Error("Missing variable name.".to_string()) } else { - let output = if arguments.len() > 1 { - variables.insert(arguments[0].clone(), arguments[1].clone()); - Some(arguments[1].clone()) + let output = if arguments.args.len() > 1 { + variables.insert(arguments.args[0].clone(), arguments.args[1].clone()); + Some(arguments.args[1].clone()) } else { - variables.remove(&arguments[0]); + variables.remove(&arguments.args[0]); None }; diff --git a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs index 94b97724..0d5a2e22 100755 --- a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs @@ -1,5 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -37,7 +37,7 @@ impl Command for CommandImpl { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -46,8 +46,8 @@ impl Command for CommandImpl { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.len() > 1 && arguments[0] == "--prefix" { - let prefix = &arguments[1]; + if arguments.args.len() > 1 && arguments.args[0] == "--prefix" { + let prefix = &arguments.args[1]; variables.retain(|key, _| !key.starts_with(prefix)); } else { diff --git a/duckscript_sdk/src/test/mod.rs b/duckscript_sdk/src/test/mod.rs index c024cfca..a50178c8 100644 --- a/duckscript_sdk/src/test/mod.rs +++ b/duckscript_sdk/src/test/mod.rs @@ -1,6 +1,6 @@ use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::runner; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; @@ -24,7 +24,7 @@ impl Command for EmptyCommand { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Continue(None) } } @@ -41,7 +41,7 @@ impl Command for ErrorCommand { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Error("test".to_string()) } } @@ -62,11 +62,11 @@ impl Command for SetCommand { Box::new((*self).clone()) } - fn run(&self, arguments: Vec) -> CommandResult { - if arguments.is_empty() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + if arguments.args.is_empty() { CommandResult::Continue(None) } else { - CommandResult::Continue(Some(arguments[0].clone())) + CommandResult::Continue(Some(arguments.args[0].clone())) } } } @@ -89,7 +89,7 @@ impl Command for SetHandleCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -98,11 +98,14 @@ impl Command for SetHandleCommand { _line: usize, _env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Continue(None) } else { let state = get_handles_sub_state(state); - state.insert(arguments[0].clone(), StateValue::String("test".to_string())); + state.insert( + arguments.args[0].clone(), + StateValue::String("test".to_string()), + ); CommandResult::Continue(None) } } @@ -126,7 +129,7 @@ impl Command for ArrayCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, _variables: &mut HashMap, _output_variable: Option, @@ -165,7 +168,7 @@ impl Command for OnErrorCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, _state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, diff --git a/duckscript_sdk/src/types/command.rs b/duckscript_sdk/src/types/command.rs index 433a7a85..57188aba 100644 --- a/duckscript_sdk/src/types/command.rs +++ b/duckscript_sdk/src/types/command.rs @@ -3,7 +3,7 @@ use crate::types::scope::set_line_context_name; use crate::utils::eval; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::parser; -use duckscript::types::command::{Command, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; @@ -86,7 +86,7 @@ impl Command for AliasCommand { fn run_with_context( &self, - arguments: Vec, + arguments: CommandArgs, state: &mut HashMap, variables: &mut HashMap, _output_variable: Option, @@ -95,7 +95,7 @@ impl Command for AliasCommand { _line: usize, env: &mut Env, ) -> CommandResult { - if arguments.len() < self.arguments_amount { + if arguments.args.len() < self.arguments_amount { CommandResult::Error("Invalid arguments provided.".to_string()) } else { let start_count = variables.len(); @@ -103,7 +103,7 @@ impl Command for AliasCommand { // define script arguments let mut handle_option = None; - if !arguments.is_empty() { + if !arguments.args.is_empty() { let mut index = 0; let mut array = vec![]; for argument in arguments { @@ -179,7 +179,7 @@ impl Command for DocOnlyCommand { Box::new((*self).clone()) } - fn run(&self, _arguments: Vec) -> CommandResult { + fn run(&self, _arguments: CommandArgs) -> CommandResult { CommandResult::Error("Documentation only commands should not be executed.".to_string()) } } diff --git a/duckscript_sdk/src/utils/condition.rs b/duckscript_sdk/src/utils/condition.rs index fd05eaab..bf67270e 100644 --- a/duckscript_sdk/src/utils/condition.rs +++ b/duckscript_sdk/src/utils/condition.rs @@ -29,17 +29,17 @@ pub(crate) fn is_true(value: Option) -> bool { } pub(crate) fn eval_condition( - arguments: Vec, + arguments: CommandArgs, instructions: &Vec, state: &mut HashMap, variables: &mut HashMap, commands: &mut Commands, env: &mut Env, ) -> Result { - if arguments.is_empty() { + if arguments.args.is_empty() { Ok(is_true(None)) } else { - let eval_statement = commands.exists(&arguments[0]); + let eval_statement = commands.exists(&arguments.args[0]); if eval_statement { match eval::eval_with_instructions( @@ -59,13 +59,13 @@ pub(crate) fn eval_condition( _ => Err("Invalid condition evaluation result.".to_string()), } } else { - eval_condition_for_slice(&arguments[..]) + eval_condition_for_slice(&arguments.args[..]) } } } pub(crate) fn eval_condition_for_slice(arguments: &[String]) -> Result { - if arguments.is_empty() { + if arguments.args.is_empty() { Ok(is_true(None)) } else { let mut searching_block_end = false; @@ -88,7 +88,7 @@ pub(crate) fn eval_condition_for_slice(arguments: &[String]) -> Result { start_block = 0; diff --git a/duckscript_sdk/src/utils/eval.rs b/duckscript_sdk/src/utils/eval.rs index 2f486aef..1d686859 100644 --- a/duckscript_sdk/src/utils/eval.rs +++ b/duckscript_sdk/src/utils/eval.rs @@ -49,7 +49,7 @@ pub(crate) fn eval( commands: &mut Commands, env: &mut Env, ) -> Result { - if arguments.is_empty() { + if arguments.args.is_empty() { Ok(CommandResult::Continue(None)) } else { match parse(arguments) { @@ -95,7 +95,7 @@ pub(crate) fn eval_with_instructions( commands: &mut Commands, env: &mut Env, ) -> CommandResult { - if arguments.is_empty() { + if arguments.args.is_empty() { CommandResult::Continue(None) } else { match parse(arguments) { diff --git a/duckscript_sdk/src/utils/exec.rs b/duckscript_sdk/src/utils/exec.rs index 49237441..b6fc3286 100644 --- a/duckscript_sdk/src/utils/exec.rs +++ b/duckscript_sdk/src/utils/exec.rs @@ -29,7 +29,7 @@ pub(crate) fn exec( None => { return Err(format!( "Unable to extract exit code for command: {}", - &arguments[0] + &arguments.args[0] ) .to_string()); } @@ -78,13 +78,13 @@ fn create_command( input: &ExecInput, start_index: usize, ) -> Result { - if arguments.len() <= start_index { + if arguments.args.len() <= start_index { Err("Command not provided.".to_string()) } else { - let mut command = Command::new(&arguments[start_index]); + let mut command = Command::new(&arguments.args[start_index]); let argument_index = start_index + 1; - for argument in &arguments[argument_index..] { + for argument in &arguments.args[argument_index..] { command.arg(argument); } From e3cfcd0332ef72575cc7b171a6b51dd7f8b0380f Mon Sep 17 00:00:00 2001 From: Nick Heyer Date: Mon, 23 Sep 2024 22:09:36 -0700 Subject: [PATCH 03/12] Adding halt interupt to env --- duckscript/src/runner.rs | 7 +++++++ duckscript/src/types/env.rs | 18 +++++++++--------- duckscript/src/types/env_test.rs | 4 ++-- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/duckscript/src/runner.rs b/duckscript/src/runner.rs index 2b9c2ba0..1660674d 100644 --- a/duckscript/src/runner.rs +++ b/duckscript/src/runner.rs @@ -18,12 +18,14 @@ use crate::types::instruction::{ use crate::types::runtime::{Context, Runtime, StateValue}; use std::collections::HashMap; use std::io::stdin; +use std::sync::atomic::Ordering; #[derive(Debug)] enum EndReason { ExitCalled, ReachedEnd, Crash(ScriptError), + Halted } /// Executes the provided script with the given context @@ -135,6 +137,11 @@ fn run_instructions( let mut end_reason = EndReason::ReachedEnd; loop { + if runtime.env.halt.load(Ordering::SeqCst) { + end_reason = EndReason::Halted; + break; + } + let (instruction, meta_info) = if instructions.len() > line { let instruction = instructions[line].clone(); let meta_info = instruction.meta_info.clone(); diff --git a/duckscript/src/types/env.rs b/duckscript/src/types/env.rs index 340b53e6..a93575b1 100644 --- a/duckscript/src/types/env.rs +++ b/duckscript/src/types/env.rs @@ -8,6 +8,8 @@ mod env_test; use std::io::{stderr, stdout, Write}; +use std::sync::Arc; +use std::sync::atomic::AtomicBool; /// The runtime env pub struct Env { @@ -15,6 +17,8 @@ pub struct Env { pub out: Box, /// The error writer pub err: Box, + /// The halt token - Set to true to exit after current instruction + pub halt: Arc, } impl Env { @@ -23,20 +27,16 @@ impl Env { Env { out: Box::new(stdout()), err: Box::new(stderr()), + halt: Arc::new(AtomicBool::new(false)), } } /// Creates and returns a new instance. - pub fn new(out: Option>, err: Option>) -> Env { + pub fn new(out: Option>, err: Option>, halt: Option>) -> Env { Env { - out: match out { - Some(value) => value, - None => Box::new(stdout()), - }, - err: match err { - Some(value) => value, - None => Box::new(stderr()), - }, + out: out.unwrap_or_else(|| Box::new(stdout())), + err: err.unwrap_or_else(|| Box::new(stderr())), + halt: halt.unwrap_or_else(|| Arc::new(AtomicBool::new(false))), } } } diff --git a/duckscript/src/types/env_test.rs b/duckscript/src/types/env_test.rs index c66ef5fc..471602e3 100644 --- a/duckscript/src/types/env_test.rs +++ b/duckscript/src/types/env_test.rs @@ -13,14 +13,14 @@ fn env_default() { #[test] fn env_new_none() { - let mut env = Env::new(None, None); + let mut env = Env::new(None, None, None); validate_env(&mut env); } #[test] fn env_new_with_values() { - let mut env = Env::new(Some(Box::new(stdout())), Some(Box::new(stdout()))); + let mut env = Env::new(Some(Box::new(stdout())), Some(Box::new(stdout())), None); validate_env(&mut env); } From 562a455e55fcfe81305fa4b5b2dfcc343cad904f Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 28 Sep 2024 15:14:05 +0000 Subject: [PATCH 04/12] fixing publish flow --- .github/workflows/publish.yml | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index e9f76a8e..93180a4d 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -25,19 +25,11 @@ jobs: run: sudo apt-get install musl-tools - name: Checkout uses: actions/checkout@v2 - - name: Install rust - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - profile: minimal - override: true - - name: Install rust windows msvc target - if: matrix.os == 'windows-latest' - uses: actions-rs/toolchain@v1 - with: - toolchain: stable-x86_64-pc-windows-msvc - profile: minimal - override: true + - name: Update rust + run: | + rustup override set stable + rustup update stable + rustup target add ${{ matrix.binary_target }} - name: Install cargo-make uses: actions-rs/cargo@v1 with: From a6a42a2c4511be3d69c4f67bffc1001aa1f0fe89 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 28 Sep 2024 15:41:44 +0000 Subject: [PATCH 05/12] dev --- .../src/sdk/std/flowcontrol/forin/mod.rs | 36 +----- .../src/sdk/std/flowcontrol/function/mod.rs | 103 +++++------------- .../src/sdk/std/flowcontrol/ifelse/mod.rs | 86 ++++----------- .../src/sdk/std/flowcontrol/while_mod/mod.rs | 58 +++------- .../sdk/std/fs/gitignore_path_array/mod.rs | 16 +-- .../src/sdk/std/fs/glob_array/mod.rs | 18 +-- duckscript_sdk/src/sdk/std/fs/list/mod.rs | 16 +-- duckscript_sdk/src/sdk/std/fs/print/mod.rs | 18 +-- .../src/sdk/std/fs/read_bytes/mod.rs | 18 +-- .../src/sdk/std/fs/write_bytes/mod.rs | 18 +-- duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs | 18 +-- .../src/sdk/std/is_command_defined/mod.rs | 18 +-- duckscript_sdk/src/sdk/std/json/encode/mod.rs | 22 +--- duckscript_sdk/src/sdk/std/json/parse/mod.rs | 22 +--- .../src/sdk/std/lib/alias/set/mod.rs | 30 ++--- .../src/sdk/std/lib/alias/unset/mod.rs | 24 +--- 16 files changed, 104 insertions(+), 417 deletions(-) diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs index 8ff20301..9d97e8fc 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs @@ -310,21 +310,7 @@ impl Command for ForInCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() != 3 || arguments.args[1] != "in" { CommandResult::Error("Invalid for/in statement".to_string()) } else { @@ -413,25 +399,11 @@ impl Command for EndForInCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { - match pop_call_info_for_line(line, state, true) { + fn run(&self, arguments: CommandArgs) -> CommandResult { + match pop_call_info_for_line(line, arguments.state, true) { Some(call_info) => { let next_line = call_info.meta_info.start; - store_call_info(&call_info, state); + store_call_info(&call_info, arguments.state); CommandResult::GoTo(None, GoToValue::Line(next_line)) } None => CommandResult::Error( diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs index ec34fe4a..4ee1c0c5 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs @@ -287,21 +287,7 @@ impl Command for FunctionCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing function name.".to_string()) } else { @@ -406,29 +392,14 @@ impl Command for FunctionCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult - { + fn run(&self, arguments: CommandArgs) -> CommandResult { run_call( self.name(), - arguments, - state, - variables, - output_variable, - line, + arguments.args, + arguments.state, + arguments.variables, + arguments.output_variable, + arguments.line, ) } } @@ -489,30 +460,18 @@ impl Command for EndFunctionCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { - let line_context_name = get_line_context_name(state); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let line_context_name = get_line_context_name(arguments.state); - match pop_from_call_stack(state) { + match pop_from_call_stack(arguments.state) { Some(call_info) => { - if call_info.end_line == line && call_info.line_context_name == line_context_name { + if call_info.end_line == arguments.line + && call_info.line_context_name == line_context_name + { let next_line = call_info.call_line + 1; if call_info.scoped { - match scope::pop(variables, state, &vec![]) { + match scope::pop(arguments.variables, arguments.state, &vec![]) { Err(error) => return CommandResult::Error(error), _ => (), } @@ -520,7 +479,7 @@ impl Command for EndFunctionCommand { CommandResult::GoTo(None, GoToValue::Line(next_line)) } else { - push_to_call_stack(state, &call_info); + push_to_call_stack(arguments.state, &call_info); CommandResult::Continue(None) } } @@ -551,35 +510,23 @@ impl Command for ReturnCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { - let line_context_name = get_line_context_name(state); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let line_context_name = get_line_context_name(arguments.state); match pop_from_call_stack(state) { Some(call_info) => { - if call_info.start_line < line - && call_info.end_line > line + if call_info.start_line < arguments.line + && call_info.end_line > arguments.line && call_info.line_context_name == line_context_name { match call_info.output_variable { Some(ref name) => { if arguments.args.is_empty() { - variables.remove(name); + arguments.variables.remove(name); } else { - variables.insert(name.to_string(), arguments.args[0].clone()); + arguments + .variables + .insert(name.to_string(), arguments.args[0].clone()); } } None => (), @@ -597,7 +544,7 @@ impl Command for ReturnCommand { None => vec![], }; - match scope::pop(variables, state, ©) { + match scope::pop(arguments.variables, arguments.state, ©) { Err(error) => return CommandResult::Error(error), _ => (), } @@ -606,7 +553,7 @@ impl Command for ReturnCommand { let next_line = call_info.call_line + 1; CommandResult::GoTo(output, GoToValue::Line(next_line)) } else { - push_to_call_stack(state, &call_info); + push_to_call_stack(arguments.state, &call_info); CommandResult::Continue(None) } } diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs index e201cdda..06ca7ed1 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs @@ -344,38 +344,24 @@ impl Command for IfCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match get_or_create_if_meta_info_for_line( - line, - state, - instructions, + arguments.line, + arguments.state, + arguments.instructions, self.package.clone(), ) { Ok(if_else_info) => { match condition::eval_condition( - arguments, - instructions, - state, - variables, - commands, - env, + arguments.args, + arguments.instructions, + arguments.state, + arguments.variables, + arguments.commands, + arguments.env, ) { Ok(passed) => { if passed { @@ -385,7 +371,7 @@ impl Command for IfCommand { if_else_info.else_lines[0] }; - let line_context_name = get_line_context_name(state); + let line_context_name = get_line_context_name(arguments.state); let call_info = CallInfo { current: next_line, @@ -395,7 +381,7 @@ impl Command for IfCommand { line_context_name, }; - store_call_info(&call_info, state); + store_call_info(&call_info, arguments.state); CommandResult::Continue(None) } else if if_else_info.else_lines.is_empty() { @@ -404,7 +390,7 @@ impl Command for IfCommand { } else { let next_line = if_else_info.else_lines[0]; - let line_context_name = get_line_context_name(state); + let line_context_name = get_line_context_name(arguments.state); let call_info = CallInfo { current: next_line, @@ -414,7 +400,7 @@ impl Command for IfCommand { line_context_name, }; - store_call_info(&call_info, state); + store_call_info(&call_info, arguments.state); CommandResult::GoTo(None, GoToValue::Line(next_line)) } @@ -450,33 +436,19 @@ impl Command for ElseIfCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { - match pop_call_info_for_line(line, state) { + match pop_call_info_for_line(arguments.line, arguments.state) { Some(call_info) => { if call_info.passed { let next_line = call_info.meta_info.end + 1; CommandResult::GoTo(None, GoToValue::Line(next_line)) } else { let if_else_info = call_info.meta_info.clone(); - let line_context_name = get_line_context_name(state); - match condition::eval_condition(arguments, instructions, state, variables, commands, env) { + let line_context_name = get_line_context_name(arguments.state); + match condition::eval_condition(arguments.args, arguments.instructions, arguments.state, arguments.variables, arguments.commands, arguments.env) { Ok(passed) => { if passed { let next_line = if call_info.else_line_index + 1 < if_else_info.else_lines.len() { @@ -493,7 +465,7 @@ impl Command for ElseIfCommand { line_context_name }; - store_call_info(&else_call_info, state); + store_call_info(&else_call_info, arguments.state); CommandResult::Continue(None) } else if call_info.else_line_index + 1 < if_else_info.else_lines.len() { @@ -508,7 +480,7 @@ impl Command for ElseIfCommand { line_context_name }; - store_call_info(&call_info, state); + store_call_info(&call_info, arguments.state); CommandResult::GoTo(None, GoToValue::Line(next_line)) } else { @@ -549,22 +521,8 @@ impl Command for ElseCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { - match pop_call_info_for_line(line, state) { + fn run(&self, arguments: CommandArgs) -> CommandResult { + match pop_call_info_for_line(arguments.line, arguments.state) { Some(call_info) => { if call_info.passed { let next_line = call_info.meta_info.end + 1; diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs index 69164286..b38e1b53 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs @@ -267,49 +267,35 @@ impl Command for WhileCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match get_or_create_while_meta_info_for_line( - line, - state, - instructions, + arguments.line, + arguments.state, + arguments.instructions, self.package.clone(), ) { Ok(while_info) => { match condition::eval_condition( - arguments, - instructions, - state, - variables, - commands, - env, + arguments.args, + arguments.instructions, + arguments.state, + arguments.variables, + arguments.commands, + arguments.env, ) { Ok(passed) => { if passed { - let line_context_name = get_line_context_name(state); + let line_context_name = get_line_context_name(arguments.state); let call_info = CallInfo { meta_info: while_info.clone(), line_context_name, }; - store_call_info(&call_info, state); + store_call_info(&call_info, arguments.state); CommandResult::Continue(None) } else { @@ -357,25 +343,11 @@ impl Command for EndWhileCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { - match pop_call_info_for_line(line, state) { + fn run(&self, arguments: CommandArgs) -> CommandResult { + match pop_call_info_for_line(arguments.line, arguments.state) { Some(call_info) => { let next_line = call_info.meta_info.start; - store_call_info(&call_info, state); + store_call_info(&call_info, arguments.state); CommandResult::GoTo(None, GoToValue::Line(next_line)) } None => CommandResult::Error( diff --git a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs index 02b5ed7f..f462fbf5 100755 --- a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs @@ -34,21 +34,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Root directory not provided.".to_string()) } else { diff --git a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs index 08177daa..14e228f4 100755 --- a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs @@ -34,21 +34,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Glob pattern not provided.".to_string()) } else { @@ -68,7 +54,7 @@ impl Command for CommandImpl { } } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/fs/list/mod.rs b/duckscript_sdk/src/sdk/std/fs/list/mod.rs index f79360eb..98116b5b 100755 --- a/duckscript_sdk/src/sdk/std/fs/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/list/mod.rs @@ -93,21 +93,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let (path_str, flags) = if arguments.args.is_empty() { (".", "") } else if arguments.args.len() == 1 { diff --git a/duckscript_sdk/src/sdk/std/fs/print/mod.rs b/duckscript_sdk/src/sdk/std/fs/print/mod.rs index 27acf4fc..392a8bb5 100755 --- a/duckscript_sdk/src/sdk/std/fs/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/print/mod.rs @@ -31,26 +31,12 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("File name not provided.".to_string()) } else { let mut all_text = String::new(); - for argument in &arguments { + for argument in &arguments.args { let result = io::read_text_file(&argument); match result { diff --git a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs index 8c107f6b..483bce52 100755 --- a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs @@ -32,21 +32,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("File name not provided.".to_string()) } else { @@ -54,7 +40,7 @@ impl Command for CommandImpl { match result { Ok(binary) => { - let key = put_handle(state, StateValue::ByteArray(binary)); + let key = put_handle(arguments.state, StateValue::ByteArray(binary)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs index ef5714ec..3e184cc0 100755 --- a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("File name and text not provided.".to_string()) } else if arguments.args.len() == 1 { CommandResult::Error("Binary data handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[1]; diff --git a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs index 975f26d9..feceb6f8 100644 --- a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs @@ -39,21 +39,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() < 2 { return CommandResult::Error( "Paths to the ZIP file and/or files to pack are not provided.".to_string(), @@ -71,7 +57,7 @@ impl Command for CommandImpl { Err(err) => return CommandResult::Error(err), }; - let files = match collect_files_from_arrays(&file_args, state) { + let files = match collect_files_from_arrays(&file_args, arguments.state) { Ok(files) => files, Err(err) => return CommandResult::Error(err), }; diff --git a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs index 2be5ce7a..90321df3 100755 --- a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs @@ -31,25 +31,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Command name not provided.".to_string()) } else { - let result = commands.exists(&arguments.args[0]); + let result = arguments.commands.exists(&arguments.args[0]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/json/encode/mod.rs b/duckscript_sdk/src/sdk/std/json/encode/mod.rs index f094d92f..04090465 100755 --- a/duckscript_sdk/src/sdk/std/json/encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/encode/mod.rs @@ -200,21 +200,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("No JSON root variable name provided.".to_string()) } else { @@ -226,14 +212,14 @@ impl Command for CommandImpl { }; if as_state { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); - match encode_from_state(&arguments.args[start_index], state) { + match encode_from_state(&arguments.args[start_index], arguments.state) { Ok(output) => CommandResult::Continue(Some(output)), Err(error) => CommandResult::Error(error), } } else { - match encode_from_variables(&arguments.args[start_index], variables) { + match encode_from_variables(&arguments.args[start_index], arguments.variables) { Ok(output) => CommandResult::Continue(Some(output)), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/json/parse/mod.rs b/duckscript_sdk/src/sdk/std/json/parse/mod.rs index b7bfd480..07f52c1e 100755 --- a/duckscript_sdk/src/sdk/std/json/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/parse/mod.rs @@ -105,21 +105,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("No JSON string provided.".to_string()) } else { @@ -135,11 +121,11 @@ impl Command for CommandImpl { let output = match output_variable { Some(name) => { if as_state { - create_structure(data, state) + create_structure(data, arguments.state) } else { - create_variables(data, &name, variables); + create_variables(data, &name, arguments.variables); - match variables.get(&name) { + match arguments.variables.get(&name) { Some(value) => Some(value.to_string()), None => None, } diff --git a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs index f150b7cd..562da74e 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs @@ -36,26 +36,18 @@ fn create_alias_command( Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut all_arguments = vec![]; - all_arguments.append(&mut self.arguments.clone()); - all_arguments.append(&mut arguments.clone()); - - eval::eval_with_error(&all_arguments, state, variables, commands, env) + all_arguments.append(&mut self.arguments.args.clone()); + all_arguments.append(&mut arguments.args.clone()); + + eval::eval_with_error( + &all_arguments, + arguments.state, + arguments.variables, + arguments.commands, + arguments.env, + ) } } diff --git a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs index 8557df10..2efb4ffc 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs @@ -33,36 +33,22 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() != 1 { CommandResult::Error("Invalid alias name provided.".to_string()) } else { - let sub_state = get_sub_state(ALIAS_STATE_KEY.to_string(), state); + let sub_state = get_sub_state(ALIAS_STATE_KEY.to_string(), arguments.state); let key = &arguments.args[0]; let removed = if sub_state.contains_key(key) { - if commands.remove(key) { + if arguments.commands.remove(key) { sub_state.remove(key); true } else { false } - } else if commands.aliases.contains_key(key) { - commands.aliases.remove(key); + } else if arguments.commands.aliases.contains_key(key) { + arguments.commands.aliases.remove(key); true } else { false From 7062bd70e124dd6b66318d24d11d2075cabfadaa Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Sat, 28 Sep 2024 15:41:55 +0000 Subject: [PATCH 06/12] dev --- duckscript/src/runner.rs | 2 +- duckscript/src/types/env.rs | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/duckscript/src/runner.rs b/duckscript/src/runner.rs index 785f5a19..e321f16c 100644 --- a/duckscript/src/runner.rs +++ b/duckscript/src/runner.rs @@ -25,7 +25,7 @@ enum EndReason { ExitCalled, ReachedEnd, Crash(ScriptError), - Halted + Halted, } /// Executes the provided script with the given context diff --git a/duckscript/src/types/env.rs b/duckscript/src/types/env.rs index a93575b1..5033ab64 100644 --- a/duckscript/src/types/env.rs +++ b/duckscript/src/types/env.rs @@ -8,8 +8,8 @@ mod env_test; use std::io::{stderr, stdout, Write}; -use std::sync::Arc; use std::sync::atomic::AtomicBool; +use std::sync::Arc; /// The runtime env pub struct Env { @@ -32,7 +32,11 @@ impl Env { } /// Creates and returns a new instance. - pub fn new(out: Option>, err: Option>, halt: Option>) -> Env { + pub fn new( + out: Option>, + err: Option>, + halt: Option>, + ) -> Env { Env { out: out.unwrap_or_else(|| Box::new(stdout())), err: err.unwrap_or_else(|| Box::new(stderr())), From 545e76ea481f5fec8413b30fd436a84a7676265c Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Tue, 1 Oct 2024 18:04:45 +0000 Subject: [PATCH 07/12] dev --- .../src/sdk/internal/sdkdocs/mod.rs | 2 +- .../sdk/std/collections/array_clear/mod.rs | 2 +- .../src/sdk/std/collections/array_get/mod.rs | 2 +- .../sdk/std/collections/array_length/mod.rs | 2 +- .../src/sdk/std/collections/array_pop/mod.rs | 2 +- .../src/sdk/std/collections/array_push/mod.rs | 2 +- .../sdk/std/collections/array_remove/mod.rs | 2 +- .../src/sdk/std/collections/array_set/mod.rs | 2 +- .../src/sdk/std/collections/is_array/mod.rs | 2 +- .../src/sdk/std/collections/is_map/mod.rs | 2 +- .../src/sdk/std/collections/is_set/mod.rs | 2 +- .../src/sdk/std/collections/map/mod.rs | 4 +- .../src/sdk/std/collections/map_clear/mod.rs | 2 +- .../src/sdk/std/collections/map_get/mod.rs | 2 +- .../src/sdk/std/collections/map_keys/mod.rs | 4 +- .../collections/map_load_properties/mod.rs | 2 +- .../src/sdk/std/collections/map_put/mod.rs | 2 +- .../src/sdk/std/collections/map_remove/mod.rs | 2 +- .../src/sdk/std/collections/map_size/mod.rs | 2 +- .../std/collections/map_to_properties/mod.rs | 2 +- .../src/sdk/std/collections/range/mod.rs | 2 +- .../std/collections/read_properties/mod.rs | 2 +- .../src/sdk/std/collections/set/mod.rs | 2 +- .../src/sdk/std/collections/set_clear/mod.rs | 2 +- .../sdk/std/collections/set_contains/mod.rs | 2 +- .../src/sdk/std/collections/set_put/mod.rs | 2 +- .../src/sdk/std/collections/set_remove/mod.rs | 2 +- .../src/sdk/std/collections/set_size/mod.rs | 2 +- .../sdk/std/collections/set_to_array/mod.rs | 4 +- .../std/collections/write_properties/mod.rs | 2 +- .../sdk/std/debug/dump_instructions/mod.rs | 2 +- .../src/sdk/std/debug/dump_state/mod.rs | 2 +- .../src/sdk/std/debug/dump_variables/mod.rs | 2 +- .../src/sdk/std/env/env_to_map/mod.rs | 2 +- .../src/sdk/std/flowcontrol/end/mod.rs | 16 ++--- .../src/sdk/std/flowcontrol/forin/mod.rs | 22 ++++--- .../src/sdk/std/flowcontrol/function/mod.rs | 24 +++---- .../sdk/std/fs/gitignore_path_array/mod.rs | 4 +- duckscript_sdk/src/sdk/std/fs/list/mod.rs | 4 +- .../src/sdk/std/lib/alias/set/mod.rs | 29 +++------ .../src/sdk/std/lib/command/remove/mod.rs | 16 +---- duckscript_sdk/src/sdk/std/man/mod.rs | 20 +----- .../src/sdk/std/net/ftp/get_in_memory/mod.rs | 19 +----- .../src/sdk/std/net/ftp/list/mod.rs | 18 +----- .../src/sdk/std/net/ftp/nlst/mod.rs | 18 +----- duckscript_sdk/src/sdk/std/not/mod.rs | 28 ++------ .../src/sdk/std/on_error/exit_on_error/mod.rs | 18 +----- .../sdk/std/on_error/get_last_error/mod.rs | 18 +----- .../std/on_error/get_last_error_line/mod.rs | 18 +----- .../std/on_error/get_last_error_source/mod.rs | 18 +----- .../src/sdk/std/on_error/on_error/mod.rs | 18 +----- .../src/sdk/std/on_error/set_error/mod.rs | 18 +----- duckscript_sdk/src/sdk/std/print/mod.rs | 18 +----- duckscript_sdk/src/sdk/std/println/mod.rs | 18 +----- .../src/sdk/std/process/exec/mod.rs | 36 ++++------- duckscript_sdk/src/sdk/std/release/mod.rs | 20 +----- duckscript_sdk/src/sdk/std/scope/clear/mod.rs | 18 +----- .../src/sdk/std/scope/pop_stack/mod.rs | 18 +----- .../src/sdk/std/scope/push_stack/mod.rs | 18 +----- .../src/sdk/std/semver/parse/mod.rs | 24 ++----- .../src/sdk/std/string/base64_decode/mod.rs | 18 +----- .../src/sdk/std/string/base64_encode/mod.rs | 18 +----- .../src/sdk/std/string/bytes_to_string/mod.rs | 18 +----- .../src/sdk/std/string/split/mod.rs | 18 +----- .../src/sdk/std/string/string_to_bytes/mod.rs | 18 +----- .../src/sdk/std/test/test_directory/mod.rs | 18 +----- .../src/sdk/std/test/test_file/mod.rs | 18 +----- .../src/sdk/std/var/get_all_var_names/mod.rs | 20 +----- .../src/sdk/std/var/get_by_name/mod.rs | 18 +----- .../src/sdk/std/var/is_defined/mod.rs | 18 +----- .../src/sdk/std/var/set_by_name/mod.rs | 22 ++----- .../src/sdk/std/var/unset_all_vars/mod.rs | 22 ++----- duckscript_sdk/src/test/mod.rs | 64 ++++--------------- duckscript_sdk/src/types/command.rs | 40 +++++------- 74 files changed, 204 insertions(+), 696 deletions(-) diff --git a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs index dcd12c4b..70cb9657 100755 --- a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs +++ b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs @@ -82,7 +82,7 @@ impl Command for CommandImpl { buffer.push_str("\n"); for name in &names { if name.starts_with(&prefix) { - let command = match commands.get(name) { + let command = match arguments.commands.get(name) { Some(command) => command, None => { return CommandResult::Error(format!("Command: {} not found", name)); diff --git a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs index 208d9b43..f450c9b0 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs index 8132e98a..93e25cde 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.len() < 2 { CommandResult::Error("Array handle or item index not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); let index: usize = match arguments.args[1].parse() { diff --git a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs index 9429bddc..cd53eea6 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs @@ -40,7 +40,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; diff --git a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs index a88443b9..3b589bb6 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs index a645cb33..f9888ffa 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs @@ -40,7 +40,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs index 9267aef5..4f76d3ba 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.len() < 2 { CommandResult::Error("Invalid input provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); let index: usize = match arguments.args[1].parse() { diff --git a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs index e0e8dba7..a12b4230 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.len() < 3 { CommandResult::Error("Invalid input provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); let index: usize = match arguments.args[1].parse() { diff --git a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs index 046b4555..46e84707 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; diff --git a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs index 840ca466..b4ffc2a3 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; diff --git a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs index 877adfb2..44fe4fd9 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; diff --git a/duckscript_sdk/src/sdk/std/collections/map/mod.rs b/duckscript_sdk/src/sdk/std/collections/map/mod.rs index 24a45215..19af4363 100755 --- a/duckscript_sdk/src/sdk/std/collections/map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map/mod.rs @@ -32,10 +32,10 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, _arguments: CommandArgs) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let map = HashMap::new(); - let key = put_handle(state, StateValue::SubState(map)); + let key = put_handle(arguments.state, StateValue::SubState(map)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs index 6d621179..774dd052 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs index 5efd5b7e..64e597fc 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs @@ -38,7 +38,7 @@ impl Command for CommandImpl { } else if arguments.args.len() < 2 { CommandResult::Error("Key not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs index d21c289a..e631151a 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs @@ -37,7 +37,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { - let handles_state = get_handles_sub_state(state); + let handles_state = get_handles_sub_state(arguments.state); match handles_state.get(&arguments.args[0]) { Some(state_value) => match state_value { @@ -48,7 +48,7 @@ impl Command for CommandImpl { array.push(StateValue::String(map_key.to_string())); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs index fada6abf..daf239a4 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs @@ -54,7 +54,7 @@ impl Command for CommandImpl { match read(text.as_bytes()) { Ok(data) => { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let result = mutate_map(key, state, |map| { for (property_key, property_value) in &data { diff --git a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs index 1c4c13a5..d3bca898 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs @@ -38,7 +38,7 @@ impl Command for CommandImpl { } else if arguments.args.len() < 3 { CommandResult::Error("Key/Value not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs index a1c3c0f8..ebb33ea1 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs @@ -38,7 +38,7 @@ impl Command for CommandImpl { } else if arguments.args.len() < 2 { CommandResult::Error("Key not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs index 8d1d7adb..56ac05c8 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Map handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; diff --git a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs index 869c2475..f56259a7 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs @@ -44,7 +44,7 @@ impl Command for CommandImpl { ("".to_string(), arguments.args[0].to_string()) }; - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); match state.get(&key) { Some(state_value) => match state_value { diff --git a/duckscript_sdk/src/sdk/std/collections/range/mod.rs b/duckscript_sdk/src/sdk/std/collections/range/mod.rs index 9d0fa9ee..d9f34e23 100755 --- a/duckscript_sdk/src/sdk/std/collections/range/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/range/mod.rs @@ -61,7 +61,7 @@ impl Command for CommandImpl { .map(|value| StateValue::Number64Bit(value)) .collect(); - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs index 8c56aee2..319d2aec 100755 --- a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs @@ -51,7 +51,7 @@ impl Command for CommandImpl { var_key.insert_str(0, &prefix); } - variables.insert(var_key, value.to_string()); + arguments.variables.insert(var_key, value.to_string()); } CommandResult::Continue(Some(data.len().to_string())) diff --git a/duckscript_sdk/src/sdk/std/collections/set/mod.rs b/duckscript_sdk/src/sdk/std/collections/set/mod.rs index 11001de1..d2cf34eb 100755 --- a/duckscript_sdk/src/sdk/std/collections/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set/mod.rs @@ -39,7 +39,7 @@ impl Command for CommandImpl { set.insert(argument); } - let key = put_handle(state, StateValue::Set(set)); + let key = put_handle(arguments.state, StateValue::Set(set)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs index 0565e614..54254628 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs index 0dd25af3..dc78d576 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs @@ -38,7 +38,7 @@ impl Command for CommandImpl { } else if arguments.args.len() < 2 { CommandResult::Error("Value not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs index aad0419f..995a9bec 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs index 1b0192f4..73e983c4 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs @@ -38,7 +38,7 @@ impl Command for CommandImpl { } else if arguments.args.len() < 2 { CommandResult::Error("Value not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = arguments.args[0].clone(); diff --git a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs index ecbed439..1f749e9f 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; diff --git a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs index 31f04528..4a4b5651 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs @@ -36,7 +36,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Set handle not provided.".to_string()) } else { - let handles_state = get_handles_sub_state(state); + let handles_state = get_handles_sub_state(arguments.state); match handles_state.get(&arguments.args[0]) { Some(state_value) => match state_value { @@ -47,7 +47,7 @@ impl Command for CommandImpl { array.push(StateValue::String(value.to_string())); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs index 6027c218..bb1a9ff4 100755 --- a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs @@ -46,7 +46,7 @@ impl Command for CommandImpl { let mut data = HashMap::new(); for argument in &arguments.args[start_index..] { - match variables.get(argument) { + match arguments.variables.get(argument) { Some(value) => { let mut key = argument.to_string(); if !prefix.is_empty() { diff --git a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs index d9b145e6..07836e6a 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs @@ -34,7 +34,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { let string_value = format!("{:#?}", arguments.instructions).to_string(); - if output_variable.is_none() { + if arguments.output_variable.is_none() { match writeln!(arguments.env.out, "{}", string_value) { Ok(_) => (), Err(error) => return CommandResult::Error(error.to_string()), diff --git a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs index fd0dc60e..314a7eca 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs @@ -34,7 +34,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { let string_value = format!("{:#?}", arguments.state).to_string(); - if output_variable.is_none() { + if arguments.output_variable.is_none() { match writeln!(arguments.env.out, "{}", &string_value) { Ok(_) => (), Err(error) => return CommandResult::Error(error.to_string()), diff --git a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs index c0440474..0f39ebb6 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs @@ -34,7 +34,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { let string_value = format!("{:#?}", arguments.variables).to_string(); - if output_variable.is_none() { + if arguments.output_variable.is_none() { match writeln!(arguments.env.out, "{}", string_value) { Ok(_) => (), Err(error) => return CommandResult::Error(error.to_string()), diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs index 57ab1b9c..dd885d6f 100755 --- a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs @@ -41,7 +41,7 @@ impl Command for CommandImpl { map.insert(var_key, StateValue::String(var_value.to_string())); } - let key = put_handle(state, StateValue::SubState(map)); + let key = put_handle(arguments.state, StateValue::SubState(map)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs index c0491020..fd9e65f9 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs @@ -58,7 +58,7 @@ impl Command for CommandImpl { } fn run(&self, arguments: CommandArgs) -> CommandResult { - match get_command(line, state) { + match get_command(arguments.line, arguments.state) { Some(command) => { let mut script_instruction = ScriptInstruction::new(); script_instruction.command = Some(arguments.command); @@ -70,13 +70,13 @@ impl Command for CommandImpl { }; let (command_result, _) = runner::run_instruction( - commands, - variables, - state, - instructions, - instruction, - line, - env, + arguments.commands, + arguments.variables, + arguments.state, + arguments.instructions, + arguments.instruction, + arguments.line, + arguments.env, ); command_result diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs index 9d97e8fc..2cc17e8c 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs @@ -314,19 +314,19 @@ impl Command for ForInCommand { if arguments.args.len() != 3 || arguments.args[1] != "in" { CommandResult::Error("Invalid for/in statement".to_string()) } else { - let call_info = match pop_call_info_for_line(line, state, false) { + let call_info = match pop_call_info_for_line(arguments.line, arguments.state, false) { Some(call_info) => call_info, None => { let forin_meta_info_result = get_or_create_forin_meta_info_for_line( - line, - state, - instructions, + arguments.line, + arguments.state, + arguments.instructions, self.package.clone(), ); match forin_meta_info_result { Ok(forin_meta_info) => { - let line_context_name = get_line_context_name(state); + let line_context_name = get_line_context_name(arguments.state); CallInfo { iteration: 0, @@ -343,9 +343,9 @@ impl Command for ForInCommand { let forin_meta_info = call_info.meta_info; let handle = &arguments.args[2]; - match get_next_iteration(iteration, handle.to_string(), state) { + match get_next_iteration(iteration, handle.to_string(), arguments.state) { Some(next_value) => { - let line_context_name = get_line_context_name(state); + let line_context_name = get_line_context_name(arguments.state); store_call_info( &CallInfo { @@ -353,10 +353,12 @@ impl Command for ForInCommand { meta_info: forin_meta_info, line_context_name, }, - state, + arguments.state, ); - variables.insert(arguments.args[0].clone(), next_value); + arguments + .variables + .insert(arguments.args[0].clone(), next_value); CommandResult::Continue(None) } None => { @@ -400,7 +402,7 @@ impl Command for EndForInCommand { } fn run(&self, arguments: CommandArgs) -> CommandResult { - match pop_call_info_for_line(line, arguments.state, true) { + match pop_call_info_for_line(arguments.line, arguments.state, true) { Some(call_info) => { let next_line = call_info.meta_info.start; store_call_info(&call_info, arguments.state); diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs index 4ee1c0c5..d32e1020 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs @@ -303,9 +303,9 @@ impl Command for FunctionCommand { } }; - match get_fn_info_from_state(state, &function_name) { + match get_fn_info_from_state(arguments.state, &function_name) { Some(fn_info) => { - if fn_info.start != line { + if fn_info.start != arguments.line { CommandResult::Error( format!( "Function: {} already defined at: {} to: {}", @@ -349,11 +349,11 @@ impl Command for FunctionCommand { end_blocks.push(end::END_COMMAND_NAME.to_string()); match instruction_query::find_commands( - instructions, + arguments.instructions, &start_names, &vec![], &end_names, - Some(line + 1), + Some(arguments.line + 1), None, false, &start_blocks, @@ -365,14 +365,14 @@ impl Command for FunctionCommand { let fn_info = FunctionMetaInfo { name: function_name.clone(), - start: line, + start: arguments.line, end: fn_end_line, scoped, }; - end::set_command(fn_end_line, state, end_command.name()); + end::set_command(fn_end_line, arguments.state, end_command.name()); - match store_fn_info_in_state(state, &fn_info) { + match store_fn_info_in_state(arguments.state, &fn_info) { Ok(_) => { #[derive(Clone)] pub(crate) struct CallFunctionCommand { @@ -404,9 +404,11 @@ impl Command for FunctionCommand { } } - match commands.set(Box::new(CallFunctionCommand { - name: function_name.clone(), - })) { + match arguments.commands.set(Box::new( + CallFunctionCommand { + name: function_name.clone(), + }, + )) { Ok(_) => CommandResult::GoTo( None, GoToValue::Line(fn_end_line + 1), @@ -513,7 +515,7 @@ impl Command for ReturnCommand { fn run(&self, arguments: CommandArgs) -> CommandResult { let line_context_name = get_line_context_name(arguments.state); - match pop_from_call_stack(state) { + match pop_from_call_stack(arguments.state) { Some(call_info) => { if call_info.start_line < arguments.line && call_info.end_line > arguments.line diff --git a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs index f462fbf5..64d46449 100755 --- a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs @@ -59,13 +59,13 @@ impl Command for CommandImpl { let value_string: String = FromPath::from_path(&path.path()); let state_value = StateValue::String(value_string); - array.push(state_value); + array.push(arguments.state_value); } Err(error) => return CommandResult::Error(error.to_string()), } } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/fs/list/mod.rs b/duckscript_sdk/src/sdk/std/fs/list/mod.rs index 98116b5b..292969bc 100755 --- a/duckscript_sdk/src/sdk/std/fs/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/list/mod.rs @@ -54,7 +54,7 @@ fn print_entry(env: &mut Env, item: &HashMap, exten }; writeln!( - arguments.env.out, + env.out, "{}\t{}\t{}", get_u64_value(DirEntryAttr::FileSize, &item), directory_flag, @@ -63,7 +63,7 @@ fn print_entry(env: &mut Env, item: &HashMap, exten .unwrap(); } else { writeln!( - arguments.env.out, + env.out, "{} ", get_string_value(DirEntryAttr::FullName, &item) ) diff --git a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs index 562da74e..fe32b3f9 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs @@ -13,14 +13,14 @@ mod mod_test; fn create_alias_command( name: String, - arguments: CommandArgs, + arguments: Vec, commands: &mut Commands, sub_state: &mut HashMap, ) -> Result<(), String> { #[derive(Clone)] struct AliasCommand { name: String, - arguments: CommandArgs, + arguments: Vec, } impl Command for AliasCommand { @@ -87,29 +87,20 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() < 2 { CommandResult::Error("Invalid alias provided.".to_string()) } else { let name = arguments.args[0].clone(); - let sub_state = get_sub_state(ALIAS_STATE_KEY.to_string(), state); + let sub_state = get_sub_state(ALIAS_STATE_KEY.to_string(), arguments.state); - match create_alias_command(name, arguments.args[1..].to_vec(), commands, sub_state) { + match create_alias_command( + name, + arguments.args[1..].to_vec(), + arguments.commands, + sub_state, + ) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(error) => CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs index 5d46e5ba..f4b7f84e 100755 --- a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs @@ -31,21 +31,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() != 1 { CommandResult::Error("Invalid command name provided.".to_string()) } else { diff --git a/duckscript_sdk/src/sdk/std/man/mod.rs b/duckscript_sdk/src/sdk/std/man/mod.rs index 9ba72ce2..7f4b6cc2 100755 --- a/duckscript_sdk/src/sdk/std/man/mod.rs +++ b/duckscript_sdk/src/sdk/std/man/mod.rs @@ -46,30 +46,16 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { print_help(env, self.help(), &self.name()) } else { let name = &arguments.args[0]; - match commands.get(name) { + match arguments.commands.get(name) { Some(command) => { let help_doc = command.help(); - print_help(env, help_doc, name) + print_help(arguments.env, help_doc, name) } None => { if name == &self.name() || self.aliases().contains(name) { diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs index b3318bfa..8595c156 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs @@ -34,21 +34,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( &arguments, &|options: &Options| -> Result<(), String> { @@ -64,7 +50,8 @@ impl Command for CommandImpl { match ftp_stream.retr_as_buffer(&remote_file) { Ok(binary) => { - let key = put_handle(state, StateValue::ByteArray(binary.into_inner())); + let key = + put_handle(arguments.state, StateValue::ByteArray(binary.into_inner())); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs index 9fb30866..10e21348 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs @@ -34,21 +34,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { run_with_connection(&arguments, &mut |_options: &Options, ftp_stream: &mut FtpStream| -> CommandResult { @@ -60,7 +46,7 @@ impl Command for CommandImpl { array.push(StateValue::String(item)); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs index 400de7af..499e45f3 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs @@ -34,21 +34,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { run_with_connection(&arguments, &mut |_options: &Options, ftp_stream: &mut FtpStream| -> CommandResult { @@ -60,7 +46,7 @@ impl Command for CommandImpl { array.push(StateValue::String(item)); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/not/mod.rs b/duckscript_sdk/src/sdk/std/not/mod.rs index 3b010544..88e9f163 100755 --- a/duckscript_sdk/src/sdk/std/not/mod.rs +++ b/duckscript_sdk/src/sdk/std/not/mod.rs @@ -31,31 +31,17 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing condition".to_string()) } else { match condition::eval_condition( - arguments, - instructions, - state, - variables, - commands, - env, + arguments.args, + arguments.instructions, + arguments.state, + arguments.variables, + arguments.commands, + arguments.env, ) { Ok(passed) => { let output = !passed; diff --git a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs index 8f98e259..c94e6e3f 100755 --- a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs @@ -33,28 +33,14 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let exit_on_error = if arguments.args.is_empty() { let value_string = get_value(state, EXIT_ON_ERROR_KEY.to_string()); condition::is_true(value_string) } else { let exit_on_error = condition::is_true(Some(arguments.args[0].clone())); - let sub_state = get_core_sub_state_for_command(state, STATE_KEY.to_string()); + let sub_state = get_core_sub_state_for_command(arguments.state, STATE_KEY.to_string()); sub_state.insert( EXIT_ON_ERROR_KEY.to_string(), StateValue::Boolean(exit_on_error), diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs index 73842817..e4622fbd 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs @@ -32,22 +32,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - let value = get_value(state, "error".to_string()); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let value = get_value(arguments.state, "error".to_string()); CommandResult::Continue(value) } } diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs index 9dc5d81e..24f8ea3a 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs @@ -32,22 +32,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - let value = get_value(state, "line".to_string()); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let value = get_value(arguments.state, "line".to_string()); CommandResult::Continue(value) } } diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs index 65105378..2f986356 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs @@ -32,22 +32,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - let value = get_value(state, "source".to_string()); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let value = get_value(arguments.state, "source".to_string()); CommandResult::Continue(value) } } diff --git a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs index b72e5e15..b93a65c7 100755 --- a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs @@ -33,25 +33,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if !arguments.args.is_empty() { let error = arguments.args[0].clone(); - let exit_on_error = get_value(state, EXIT_ON_ERROR_KEY.to_string()); + let exit_on_error = get_value(arguments.state, EXIT_ON_ERROR_KEY.to_string()); let should_crash = condition::is_true(exit_on_error); if should_crash { diff --git a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs index 2b3b7885..5e7ab825 100755 --- a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs @@ -33,25 +33,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if !arguments.args.is_empty() { let error = arguments.args[0].clone(); - let sub_state = get_core_sub_state_for_command(state, STATE_KEY.to_string()); + let sub_state = get_core_sub_state_for_command(arguments.state, STATE_KEY.to_string()); sub_state.insert("error".to_string(), StateValue::String(error)); sub_state.insert("line".to_string(), StateValue::String(line.to_string())); sub_state.remove("source"); diff --git a/duckscript_sdk/src/sdk/std/print/mod.rs b/duckscript_sdk/src/sdk/std/print/mod.rs index 8043d33e..1c5f21df 100755 --- a/duckscript_sdk/src/sdk/std/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/print/mod.rs @@ -219,22 +219,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - run_print(env, arguments) + fn run(&self, arguments: CommandArgs) -> CommandResult { + run_print(arguments.env, arguments.args) } } diff --git a/duckscript_sdk/src/sdk/std/println/mod.rs b/duckscript_sdk/src/sdk/std/println/mod.rs index 549190c6..45370bd4 100755 --- a/duckscript_sdk/src/sdk/std/println/mod.rs +++ b/duckscript_sdk/src/sdk/std/println/mod.rs @@ -32,22 +32,8 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { - let result = run_print(env, arguments); + fn run(&self, arguments: CommandArgs) -> CommandResult { + let result = run_print(arguments.env, arguments.args); if let CommandResult::Continue(ref _value) = result { match writeln!(arguments.env.out, "") { diff --git a/duckscript_sdk/src/sdk/std/process/exec/mod.rs b/duckscript_sdk/src/sdk/std/process/exec/mod.rs index e9cb7b2f..615387fb 100755 --- a/duckscript_sdk/src/sdk/std/process/exec/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/exec/mod.rs @@ -37,40 +37,26 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { - let mut input = if output_variable.is_some() { + fn run(&self, arguments: CommandArgs) -> CommandResult { + let mut input = if arguments.output_variable.is_some() { ExecInput::External } else { ExecInput::None }; let mut command_start_index = 0; - let mut print_output = output_variable.is_none(); + let mut print_output = arguments.output_variable.is_none(); let mut fail_on_error = false; let mut exit_code_output = false; let mut index = 0; let mut looking_for = LookingFor::Flag; - for argument in &arguments { + for argument in &arguments.args { index = index + 1; match looking_for { LookingFor::Flag => match argument.as_str() { "--fail-on-error" => { - fail_on_error = output_variable.is_none(); + fail_on_error = argument.output_variable.is_none(); command_start_index = command_start_index + 1; } "--get-exit-code" => { @@ -93,23 +79,25 @@ impl Command for CommandImpl { } } - match exec::exec(&arguments, print_output, input, command_start_index) { - Ok((stdout, stderr, exit_code)) => match output_variable { + match exec::exec(&arguments.args, print_output, input, command_start_index) { + Ok((stdout, stderr, exit_code)) => match arguments.output_variable { Some(name) => { if exit_code_output { CommandResult::Continue(Some(exit_code.to_string())) } else { let mut key = String::from(&name); key.push_str(".stdout"); - variables.insert(key.clone(), stdout); + arguments.variables.insert(key.clone(), stdout); key = String::from(&name); key.push_str(".stderr"); - variables.insert(key.clone(), stderr); + arguments.variables.insert(key.clone(), stderr); key = String::from(&name); key.push_str(".code"); - variables.insert(key.clone(), exit_code.to_string()); + arguments + .variables + .insert(key.clone(), exit_code.to_string()); CommandResult::Continue(None) } diff --git a/duckscript_sdk/src/sdk/std/release/mod.rs b/duckscript_sdk/src/sdk/std/release/mod.rs index 21913b3b..d9b69d7e 100755 --- a/duckscript_sdk/src/sdk/std/release/mod.rs +++ b/duckscript_sdk/src/sdk/std/release/mod.rs @@ -32,21 +32,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Continue(Some("false".to_string())) } else { @@ -59,9 +45,9 @@ impl Command for CommandImpl { }; let removed = if recursive { - remove_handle_recursive(state, key) + remove_handle_recursive(arguments.state, key) } else { - let old_value = remove_handle(state, key); + let old_value = remove_handle(arguments.state, key); old_value.is_some() }; diff --git a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs index 38b4dcf5..7899fc70 100755 --- a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs @@ -32,25 +32,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Scope name not provided.".to_string()) } else { - clear(&arguments.args[0], variables); + clear(&arguments.args[0], arguments.variables); CommandResult::Continue(None) } diff --git a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs index 9e75d438..3e20fc52 100755 --- a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs @@ -31,21 +31,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let copy = if arguments.args.is_empty() { &[] } else if arguments.args[0] == "--copy" { @@ -54,7 +40,7 @@ impl Command for CommandImpl { &[] }; - match scope::pop(variables, state, ©) { + match scope::pop(arguments.variables, arguments.state, ©) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs index 64c42034..17771b9e 100755 --- a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs @@ -31,21 +31,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let copy = if arguments.args.is_empty() { &[] } else if arguments.args[0] == "--copy" { @@ -54,7 +40,7 @@ impl Command for CommandImpl { &[] }; - match scope::push(variables, state, ©) { + match scope::push(arguments.variables, arguments.state, ©) { Ok(_) => CommandResult::Continue(Some("true".to_string())), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs index 43043be0..1e4fe014 100755 --- a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs @@ -32,36 +32,22 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("No semver value provided.".to_string()) } else { match Version::parse(&arguments.args[0]) { - Ok(version) => match output_variable { + Ok(version) => match arguments.output_variable { Some(name) => { - variables.insert( + arguments.variables.insert( format!("{}.major", &name).to_string(), version.major.to_string(), ); - variables.insert( + arguments.variables.insert( format!("{}.minor", &name).to_string(), version.minor.to_string(), ); - variables.insert( + arguments.variables.insert( format!("{}.patch", &name).to_string(), version.patch.to_string(), ); diff --git a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs index 007ca54c..6972a1fc 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs @@ -33,27 +33,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Value not provided.".to_string()) } else { match base64::engine::general_purpose::STANDARD.decode(&arguments.args[0]) { Ok(binary) => { - let key = put_handle(state, StateValue::ByteArray(binary)); + let key = put_handle(arguments.state, StateValue::ByteArray(binary)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs index fbd7f057..04899382 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs @@ -33,21 +33,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { @@ -55,7 +41,7 @@ impl Command for CommandImpl { let key = &arguments.args[0]; - match state.get(key) { + match arguments.state.get(key) { Some(state_value) => match state_value { StateValue::ByteArray(binary) => { let encoded = base64::engine::general_purpose::STANDARD.encode(binary); diff --git a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs index c7fa63ec..8f3855eb 100755 --- a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs @@ -33,21 +33,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { @@ -55,7 +41,7 @@ impl Command for CommandImpl { let key = &arguments.args[0]; - match state.get(key) { + match arguments.state.get(key) { Some(state_value) => match state_value { StateValue::ByteArray(binary) => match str::from_utf8(&binary) { Ok(text) => CommandResult::Continue(Some(text.to_string())), diff --git a/duckscript_sdk/src/sdk/std/string/split/mod.rs b/duckscript_sdk/src/sdk/std/string/split/mod.rs index 39dc1358..eba2a1e7 100755 --- a/duckscript_sdk/src/sdk/std/string/split/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/split/mod.rs @@ -32,21 +32,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() < 2 { CommandResult::Error("Invalid input provided.".to_string()) } else { @@ -58,7 +44,7 @@ impl Command for CommandImpl { array.push(StateValue::String(value.to_string())); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs index dbf614e2..a4396be7 100755 --- a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs @@ -32,27 +32,13 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing input.".to_string()) } else { let array = arguments.args[0].clone().into_bytes(); - let key = put_handle(state, StateValue::ByteArray(array)); + let key = put_handle(arguments.state, StateValue::ByteArray(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs index d3df8031..269c67c0 100755 --- a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs @@ -43,21 +43,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Crash("Directory name not provided.".to_string()) } else { @@ -89,7 +75,7 @@ assert result } let mut context = Context::new(); - context.commands = commands.clone(); + context.commands = arguments.commands.clone(); match runner::run_script(&script, context, None) { Err(error) => CommandResult::Crash( diff --git a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs index 3fb482bb..f895cce7 100755 --- a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs @@ -43,21 +43,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Crash("File name not provided.".to_string()) } else { @@ -69,7 +55,7 @@ impl Command for CommandImpl { }; match parser::parse_file(&arguments.args[0]) { - Ok(instructions) => match commands.get("function") { + Ok(instructions) => match arguments.commands.get("function") { Some(function_command) => { let mut command_names = function_command.aliases(); command_names.push(function_command.name()); diff --git a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs index b3910ab9..a02e50be 100755 --- a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs @@ -32,28 +32,14 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - _arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut array = vec![]; - for key in variables.keys() { + for key in arguments.variables.keys() { array.push(StateValue::String(key.to_string())); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } diff --git a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs index dd75fc25..21fe63b2 100755 --- a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs @@ -30,25 +30,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let output = if arguments.args.is_empty() { None } else { - match variables.get(&arguments.args[0]) { + match arguments.variables.get(&arguments.args[0]) { Some(ref value) => Some(value.to_string()), None => None, } diff --git a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs index 2a76aad7..717be008 100755 --- a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs @@ -31,25 +31,11 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Variable name not provided.".to_string()) } else { - let result = variables.contains_key(&arguments.args[0]); + let result = arguments.variables.contains_key(&arguments.args[0]); CommandResult::Continue(Some(result.to_string())) } diff --git a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs index c63e7fb6..6cf0369a 100755 --- a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs @@ -30,29 +30,17 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing variable name.".to_string()) } else { let output = if arguments.args.len() > 1 { - variables.insert(arguments.args[0].clone(), arguments.args[1].clone()); + arguments + .variables + .insert(arguments.args[0].clone(), arguments.args[1].clone()); Some(arguments.args[1].clone()) } else { - variables.remove(&arguments.args[0]); + arguments.variables.remove(&arguments.args[0]); None }; diff --git a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs index 0d5a2e22..64856d2e 100755 --- a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs @@ -31,27 +31,15 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() > 1 && arguments.args[0] == "--prefix" { let prefix = &arguments.args[1]; - variables.retain(|key, _| !key.starts_with(prefix)); + arguments + .variables + .retain(|key, _| !key.starts_with(prefix)); } else { - variables.clear(); + arguments.variables.clear(); } CommandResult::Continue(None) diff --git a/duckscript_sdk/src/test/mod.rs b/duckscript_sdk/src/test/mod.rs index a50178c8..04b75562 100644 --- a/duckscript_sdk/src/test/mod.rs +++ b/duckscript_sdk/src/test/mod.rs @@ -83,25 +83,11 @@ impl Command for SetHandleCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Continue(None) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); state.insert( arguments.args[0].clone(), StateValue::String("test".to_string()), @@ -123,28 +109,14 @@ impl Command for ArrayCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - _variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { let mut array = vec![]; - for argument in arguments { + for argument in arguments.args { array.push(StateValue::String(argument)); } - let key = put_handle(state, StateValue::List(array)); + let key = put_handle(argument.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } @@ -162,30 +134,20 @@ impl Command for OnErrorCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - _state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - _commands: &mut Commands, - _line: usize, - _env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { println!("on error: {:#?}", &arguments); let mut index = 0; - for argument in arguments { + for argument in arguments.args { index = index + 1; - variables.insert(index.to_string(), argument.clone()); + arguments + .variables + .insert(index.to_string(), argument.clone()); } - variables.insert("on_error_invoked".to_string(), "true".to_string()); + argument + .variables + .insert("on_error_invoked".to_string(), "true".to_string()); CommandResult::Continue(None) } diff --git a/duckscript_sdk/src/types/command.rs b/duckscript_sdk/src/types/command.rs index 57188aba..c018a827 100644 --- a/duckscript_sdk/src/types/command.rs +++ b/duckscript_sdk/src/types/command.rs @@ -80,21 +80,7 @@ impl Command for AliasCommand { Box::new((*self).clone()) } - fn requires_context(&self) -> bool { - true - } - - fn run_with_context( - &self, - arguments: CommandArgs, - state: &mut HashMap, - variables: &mut HashMap, - _output_variable: Option, - _instructions: &Vec, - commands: &mut Commands, - _line: usize, - env: &mut Env, - ) -> CommandResult { + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.len() < self.arguments_amount { CommandResult::Error("Invalid arguments provided.".to_string()) } else { @@ -106,18 +92,18 @@ impl Command for AliasCommand { if !arguments.args.is_empty() { let mut index = 0; let mut array = vec![]; - for argument in arguments { + for argument in arguments.args { index = index + 1; let mut key = self.scope_name.clone(); key.push_str("::argument::"); key.push_str(&index.to_string()); - variables.insert(key, argument.clone()); + arguments.variables.insert(key, argument.clone()); array.push(StateValue::String(argument.clone())); } - let handle = put_handle(state, StateValue::List(array)); + let handle = put_handle(argument.state, StateValue::List(array)); let mut key = self.scope_name.clone(); key.push_str("::arguments"); @@ -126,22 +112,28 @@ impl Command for AliasCommand { handle_option = Some(handle); } - let (flow_result, flow_output) = - eval::eval_instructions(&self.instructions, commands, state, variables, env, 0); + let (flow_result, flow_output) = eval::eval_instructions( + &self.instructions, + arguments.commands, + arguments.state, + arguments.variables, + env, + 0, + ); match handle_option { Some(handle) => { - let handle_state = get_handles_sub_state(state); + let handle_state = get_handles_sub_state(arguments.state); match handle_state.remove(&handle) { _ => (), } } None => (), } - clear(&self.scope_name, variables); - set_line_context_name(&line_context_name, state); + clear(&self.scope_name, arguments.variables); + set_line_context_name(&line_context_name, arguments.state); - let end_count = variables.len(); + let end_count = arguments.variables.len(); if start_count < end_count { CommandResult::Crash( format!( From a1a652725b9acf6cccda2f4e96a3756f65a46033 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Thu, 3 Oct 2024 14:42:12 +0000 Subject: [PATCH 08/12] dev --- duckscript/src/types/command.rs | 2 +- duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs | 4 ---- .../src/sdk/std/collections/array/mod.rs | 3 --- .../src/sdk/std/collections/array_clear/mod.rs | 4 ---- .../src/sdk/std/collections/array_get/mod.rs | 4 ---- .../sdk/std/collections/array_length/mod.rs | 3 --- .../src/sdk/std/collections/array_pop/mod.rs | 4 ---- .../src/sdk/std/collections/array_push/mod.rs | 3 --- .../sdk/std/collections/array_remove/mod.rs | 4 ---- .../src/sdk/std/collections/array_set/mod.rs | 3 --- .../src/sdk/std/collections/is_array/mod.rs | 3 --- .../src/sdk/std/collections/is_map/mod.rs | 3 --- .../src/sdk/std/collections/is_set/mod.rs | 3 --- .../src/sdk/std/collections/map/mod.rs | 2 -- .../src/sdk/std/collections/map_clear/mod.rs | 4 ---- .../src/sdk/std/collections/map_get/mod.rs | 4 ---- .../src/sdk/std/collections/map_keys/mod.rs | 3 --- .../std/collections/map_load_properties/mod.rs | 3 --- .../src/sdk/std/collections/map_put/mod.rs | 3 --- .../src/sdk/std/collections/map_remove/mod.rs | 4 ---- .../src/sdk/std/collections/map_size/mod.rs | 3 --- .../std/collections/map_to_properties/mod.rs | 2 -- .../src/sdk/std/collections/range/mod.rs | 3 --- .../sdk/std/collections/read_properties/mod.rs | 4 ---- .../src/sdk/std/collections/set/mod.rs | 4 +--- .../src/sdk/std/collections/set_clear/mod.rs | 4 ---- .../sdk/std/collections/set_contains/mod.rs | 4 ---- .../src/sdk/std/collections/set_put/mod.rs | 4 ---- .../src/sdk/std/collections/set_remove/mod.rs | 4 ---- .../src/sdk/std/collections/set_size/mod.rs | 3 --- .../sdk/std/collections/set_to_array/mod.rs | 3 --- .../std/collections/write_properties/mod.rs | 3 --- .../src/sdk/std/debug/dump_instructions/mod.rs | 6 +----- .../src/sdk/std/debug/dump_state/mod.rs | 6 +----- .../src/sdk/std/debug/dump_variables/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/echo/mod.rs | 4 ---- .../src/sdk/std/env/env_to_map/mod.rs | 2 -- .../sdk/std/env/print_current_directory/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/env/set_env/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/eval/mod.rs | 14 +++++--------- .../src/sdk/std/flowcontrol/end/mod.rs | 7 +++---- .../src/sdk/std/flowcontrol/forin/mod.rs | 1 - .../src/sdk/std/flowcontrol/function/mod.rs | 8 +++----- .../src/sdk/std/flowcontrol/ifelse/mod.rs | 3 +-- .../src/sdk/std/flowcontrol/while_mod/mod.rs | 3 +-- .../src/sdk/std/fs/gitignore_path_array/mod.rs | 5 +---- .../src/sdk/std/fs/glob_array/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/fs/list/mod.rs | 8 +++----- duckscript_sdk/src/sdk/std/fs/print/mod.rs | 6 +----- .../src/sdk/std/fs/read_bytes/mod.rs | 5 +---- .../src/sdk/std/fs/write_bytes/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs | 4 +--- .../src/sdk/std/is_command_defined/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/json/encode/mod.rs | 6 ++---- duckscript_sdk/src/sdk/std/json/parse/mod.rs | 6 ++---- .../src/sdk/std/lib/alias/set/mod.rs | 2 -- .../src/sdk/std/lib/alias/unset/mod.rs | 6 +----- .../src/sdk/std/lib/command/remove/mod.rs | 8 ++------ duckscript_sdk/src/sdk/std/man/mod.rs | 18 +++++------------- .../src/sdk/std/net/ftp/get_in_memory/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/not/mod.rs | 6 +----- .../src/sdk/std/on_error/exit_on_error/mod.rs | 7 ++----- .../src/sdk/std/on_error/get_last_error/mod.rs | 6 +----- .../std/on_error/get_last_error_line/mod.rs | 6 +----- .../std/on_error/get_last_error_source/mod.rs | 6 +----- .../src/sdk/std/on_error/on_error/mod.rs | 8 +++----- .../src/sdk/std/on_error/set_error/mod.rs | 10 +++++----- duckscript_sdk/src/sdk/std/print/mod.rs | 5 +---- duckscript_sdk/src/sdk/std/println/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/process/exec/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/release/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/scope/clear/mod.rs | 6 +----- .../src/sdk/std/scope/pop_stack/mod.rs | 6 +----- .../src/sdk/std/scope/push_stack/mod.rs | 6 +----- duckscript_sdk/src/sdk/std/semver/parse/mod.rs | 6 +----- .../src/sdk/std/string/base64_decode/mod.rs | 5 +---- .../src/sdk/std/string/base64_encode/mod.rs | 9 +++------ .../src/sdk/std/string/bytes_to_string/mod.rs | 9 +++------ duckscript_sdk/src/sdk/std/string/split/mod.rs | 5 +---- .../src/sdk/std/string/string_to_bytes/mod.rs | 5 +---- .../src/sdk/std/test/test_directory/mod.rs | 7 ++----- .../src/sdk/std/test/test_file/mod.rs | 17 +++++++---------- .../src/sdk/std/var/get_all_var_names/mod.rs | 5 +---- .../src/sdk/std/var/get_by_name/mod.rs | 6 +----- .../src/sdk/std/var/is_defined/mod.rs | 6 +----- .../src/sdk/std/var/set_by_name/mod.rs | 6 +----- .../src/sdk/std/var/unset_all_vars/mod.rs | 6 +----- duckscript_sdk/src/types/command.rs | 14 ++++++-------- duckscript_sdk/src/utils/condition.rs | 2 +- 91 files changed, 97 insertions(+), 384 deletions(-) diff --git a/duckscript/src/types/command.rs b/duckscript/src/types/command.rs index b52ab49b..a748c85e 100644 --- a/duckscript/src/types/command.rs +++ b/duckscript/src/types/command.rs @@ -75,7 +75,7 @@ pub trait Command { fn clone_and_box(&self) -> Box; /// Run the instruction. - fn run(&self, _arguments: CommandArgs) -> CommandResult { + fn run(&self, mut _arguments: CommandArgs) -> CommandResult { CommandResult::Crash(format!("Not implemented for command: {}", &self.name()).to_string()) } } diff --git a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs index 70cb9657..aeb53297 100755 --- a/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs +++ b/duckscript_sdk/src/sdk/internal/sdkdocs/mod.rs @@ -1,10 +1,6 @@ use crate::utils::io; use crate::utils::pckg; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array/mod.rs b/duckscript_sdk/src/sdk/std/collections/array/mod.rs index d34ce45b..3e6bdb03 100755 --- a/duckscript_sdk/src/sdk/std/collections/array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs index f450c9b0..47c741fc 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_clear/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs index 93e25cde..0f31b540 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_get/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_list}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs index cd53eea6..e2c17a10 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_length/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs index 3b589bb6..da1edbf6 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_pop/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_list}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs index f9888ffa..db6525e9 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_push/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs index 4f76d3ba..27f512c3 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_remove/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs index a12b4230..b319de8b 100755 --- a/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/array_set/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_list}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs index 46e84707..1458cf12 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_array/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs index b4ffc2a3..fc629684 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_map/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs index 44fe4fd9..010a8db4 100755 --- a/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/is_set/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map/mod.rs b/duckscript_sdk/src/sdk/std/collections/map/mod.rs index 19af4363..02501809 100755 --- a/duckscript_sdk/src/sdk/std/collections/map/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map/mod.rs @@ -1,8 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; diff --git a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs index 774dd052..665dccae 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_clear/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs index 64e597fc..e183297d 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_get/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_map}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs index e631151a..744ffd90 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_keys/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; use std::str; #[cfg(test)] diff --git a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs index daf239a4..bd355668 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_load_properties/mod.rs @@ -1,11 +1,8 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use java_properties::read; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs index d3bca898..92b4a4c4 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_put/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_map}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs index ebb33ea1..8a8e8df3 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_remove/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, get_optional_as_string, mutate_map}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs index 56ac05c8..dc0d56d0 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_size/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs index f56259a7..0af7384f 100755 --- a/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/map_to_properties/mod.rs @@ -1,8 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_as_string, get_handles_sub_state}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use java_properties::write; use std::collections::HashMap; diff --git a/duckscript_sdk/src/sdk/std/collections/range/mod.rs b/duckscript_sdk/src/sdk/std/collections/range/mod.rs index d9f34e23..ca94b7a7 100755 --- a/duckscript_sdk/src/sdk/std/collections/range/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/range/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs index 319d2aec..22dc7a33 100755 --- a/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/read_properties/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; use java_properties::read; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set/mod.rs b/duckscript_sdk/src/sdk/std/collections/set/mod.rs index d2cf34eb..df83878c 100755 --- a/duckscript_sdk/src/sdk/std/collections/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set/mod.rs @@ -1,10 +1,8 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::{HashMap, HashSet}; +use std::collections::HashSet; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs index 54254628..161b561b 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_clear/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs index dc78d576..2a98cf48 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_contains/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs index 995a9bec..00c60393 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_put/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs index 73e983c4..90575af5 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_remove/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, mutate_set}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs index 1f749e9f..33c34127 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_size/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs index 4a4b5651..6e961e94 100755 --- a/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/set_to_array/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs index bb1a9ff4..4b5b2369 100755 --- a/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs +++ b/duckscript_sdk/src/sdk/std/collections/write_properties/mod.rs @@ -1,8 +1,5 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; use java_properties::write; use std::collections::HashMap; use std::str; diff --git a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs index 07836e6a..d05c4ee4 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs index 314a7eca..87dc02d8 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs index 0f39ebb6..8b8d2a7f 100755 --- a/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs +++ b/duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/echo/mod.rs b/duckscript_sdk/src/sdk/std/echo/mod.rs index 0fabac44..ff2eded6 100755 --- a/duckscript_sdk/src/sdk/std/echo/mod.rs +++ b/duckscript_sdk/src/sdk/std/echo/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs index dd885d6f..00229ff9 100755 --- a/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/env_to_map/mod.rs @@ -1,8 +1,6 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use duckscript::types::command::{Command, CommandArgs, CommandResult}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; use std::env; diff --git a/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs b/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs index 1c5525f1..3b8f8049 100755 --- a/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/print_current_directory/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use std::env; #[cfg(test)] diff --git a/duckscript_sdk/src/sdk/std/env/set_env/mod.rs b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs index 2d7b5aa0..33a0b70b 100755 --- a/duckscript_sdk/src/sdk/std/env/set_env/mod.rs +++ b/duckscript_sdk/src/sdk/std/env/set_env/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::{get_as_string, get_handles_sub_state}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; use std::env; #[cfg(test)] diff --git a/duckscript_sdk/src/sdk/std/eval/mod.rs b/duckscript_sdk/src/sdk/std/eval/mod.rs index 7c53d232..5884ec47 100755 --- a/duckscript_sdk/src/sdk/std/eval/mod.rs +++ b/duckscript_sdk/src/sdk/std/eval/mod.rs @@ -1,9 +1,5 @@ use crate::utils::{eval, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -34,10 +30,10 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { eval::eval_with_error( &arguments.args, - &arguments.state, - &arguments.variables, - &arguments.commands, - &arguments.env, + &mut arguments.state, + &mut arguments.variables, + &mut arguments.commands, + &mut arguments.env, ) } } diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs index fd9e65f9..91b02cc6 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/end/mod.rs @@ -1,8 +1,7 @@ use crate::sdk::std::flowcontrol::get_line_key; use crate::utils::state::get_core_sub_state_for_command; use duckscript::runner; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::instruction::{ Instruction, InstructionMetaInfo, InstructionType, ScriptInstruction, }; @@ -61,7 +60,7 @@ impl Command for CommandImpl { match get_command(arguments.line, arguments.state) { Some(command) => { let mut script_instruction = ScriptInstruction::new(); - script_instruction.command = Some(arguments.command); + script_instruction.command = Some(command); let mut instruction_meta_info = InstructionMetaInfo::new(); instruction_meta_info.line = Some(arguments.line); let instruction = Instruction { @@ -74,7 +73,7 @@ impl Command for CommandImpl { arguments.variables, arguments.state, arguments.instructions, - arguments.instruction, + instruction, arguments.line, arguments.env, ); diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs index 2cc17e8c..465a8ae5 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/forin/mod.rs @@ -5,7 +5,6 @@ use crate::utils::state::{ }; use crate::utils::{instruction_query, pckg}; use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; -use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs index d32e1020..9a1b7a9e 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/function/mod.rs @@ -3,9 +3,7 @@ use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{annotation, instruction_query, pckg, scope}; use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; -use duckscript::types::env::Env; use duckscript::types::error::ScriptError; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; @@ -212,7 +210,7 @@ fn pop_from_call_stack(state: &mut HashMap) -> Option, state: &mut HashMap, variables: &mut HashMap, output_variable: Option, @@ -232,7 +230,7 @@ fn run_call( for argument in arguments { index = index + 1; - variables.insert(index.to_string(), argument); + variables.insert(index.to_string(), argument.to_string()); } let line_context_name = get_line_context_name(state); @@ -395,7 +393,7 @@ impl Command for FunctionCommand { fn run(&self, arguments: CommandArgs) -> CommandResult { run_call( self.name(), - arguments.args, + &arguments.args, arguments.state, arguments.variables, arguments.output_variable, diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs index 06ca7ed1..9f373e63 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs @@ -3,7 +3,6 @@ use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{condition, instruction_query, pckg}; use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; -use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -356,7 +355,7 @@ impl Command for IfCommand { ) { Ok(if_else_info) => { match condition::eval_condition( - arguments.args, + &arguments.args, arguments.instructions, arguments.state, arguments.variables, diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs index b38e1b53..53f655a1 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/while_mod/mod.rs @@ -3,7 +3,6 @@ use crate::types::scope::get_line_context_name; use crate::utils::state::{get_core_sub_state_for_command, get_list, get_sub_state}; use crate::utils::{condition, instruction_query, pckg}; use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands, GoToValue}; -use duckscript::types::env::Env; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; @@ -279,7 +278,7 @@ impl Command for WhileCommand { ) { Ok(while_info) => { match condition::eval_condition( - arguments.args, + &arguments.args, arguments.instructions, arguments.state, arguments.variables, diff --git a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs index 64d46449..13fd0877 100755 --- a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs @@ -1,12 +1,9 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; use fsio::path::from_path::FromPath; use ignore::WalkBuilder; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs index 14e228f4..7a297bd2 100755 --- a/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/glob_array/mod.rs @@ -1,12 +1,9 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; use fsio::path::from_path::FromPath; use glob::glob; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/fs/list/mod.rs b/duckscript_sdk/src/sdk/std/fs/list/mod.rs index 292969bc..c5e3bee6 100755 --- a/duckscript_sdk/src/sdk/std/fs/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/list/mod.rs @@ -1,8 +1,6 @@ use crate::utils::{flags, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; use fs_extra::dir::{ls, DirEntryAttr, DirEntryValue}; use fsio::path::{get_basename, get_parent_directory}; use std::collections::{HashMap, HashSet}; @@ -148,13 +146,13 @@ impl Command for CommandImpl { let item_name = get_string_value(DirEntryAttr::FullName, &item); if item_name == file_name { - print_entry(env, &item, extended_details); + print_entry(arguments.env, &item, extended_details); break; } } } else { for item in items { - print_entry(env, &item, extended_details); + print_entry(arguments.env, &item, extended_details); } } diff --git a/duckscript_sdk/src/sdk/std/fs/print/mod.rs b/duckscript_sdk/src/sdk/std/fs/print/mod.rs index 392a8bb5..98e77644 100755 --- a/duckscript_sdk/src/sdk/std/fs/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/print/mod.rs @@ -1,9 +1,5 @@ use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs index 483bce52..8f8292ab 100755 --- a/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/read_bytes/mod.rs @@ -1,10 +1,7 @@ use crate::utils::state::put_handle; use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs index 3e184cc0..516e43de 100755 --- a/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/write_bytes/mod.rs @@ -1,10 +1,7 @@ use crate::utils::state::get_handles_sub_state; use crate::utils::{io, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs index feceb6f8..45b66733 100644 --- a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs @@ -1,7 +1,5 @@ use crate::utils::{pckg, state}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; use std::collections::HashMap; use std::fs::{File, OpenOptions}; diff --git a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs index 90321df3..5c24a810 100755 --- a/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/is_command_defined/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/json/encode/mod.rs b/duckscript_sdk/src/sdk/std/json/encode/mod.rs index 04090465..21860db3 100755 --- a/duckscript_sdk/src/sdk/std/json/encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/encode/mod.rs @@ -1,9 +1,7 @@ use crate::sdk::std::json::OBJECT_VALUE; use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; use serde_json::map::Map; use serde_json::{Number, Value}; @@ -214,7 +212,7 @@ impl Command for CommandImpl { if as_state { let state = get_handles_sub_state(arguments.state); - match encode_from_state(&arguments.args[start_index], arguments.state) { + match encode_from_state(&arguments.args[start_index], state) { Ok(output) => CommandResult::Continue(Some(output)), Err(error) => CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/json/parse/mod.rs b/duckscript_sdk/src/sdk/std/json/parse/mod.rs index 07f52c1e..e0d85f39 100755 --- a/duckscript_sdk/src/sdk/std/json/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/json/parse/mod.rs @@ -1,9 +1,7 @@ use crate::sdk::std::json::OBJECT_VALUE; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; use serde_json::{Result, Value}; use std::collections::HashMap; @@ -118,7 +116,7 @@ impl Command for CommandImpl { match parse_json(&arguments.args[json_index]) { Ok(data) => { - let output = match output_variable { + let output = match arguments.output_variable { Some(name) => { if as_state { create_structure(data, arguments.state) diff --git a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs index fe32b3f9..85d74a9f 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs @@ -2,8 +2,6 @@ use crate::sdk::std::lib::alias::ALIAS_STATE_KEY; use crate::utils::state::get_sub_state; use crate::utils::{eval, pckg}; use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; use std::collections::HashMap; diff --git a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs index 2efb4ffc..fd1ed1cd 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/unset/mod.rs @@ -1,11 +1,7 @@ use crate::sdk::std::lib::alias::ALIAS_STATE_KEY; use crate::utils::pckg; use crate::utils::state::get_sub_state; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs index f4b7f84e..f63cb724 100755 --- a/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/command/remove/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] @@ -35,7 +31,7 @@ impl Command for CommandImpl { if arguments.args.len() != 1 { CommandResult::Error("Invalid command name provided.".to_string()) } else { - let removed = commands.remove(&arguments.args[0]); + let removed = arguments.commands.remove(&arguments.args[0]); CommandResult::Continue(Some(removed.to_string())) } } diff --git a/duckscript_sdk/src/sdk/std/man/mod.rs b/duckscript_sdk/src/sdk/std/man/mod.rs index 7f4b6cc2..a60d4ec4 100755 --- a/duckscript_sdk/src/sdk/std/man/mod.rs +++ b/duckscript_sdk/src/sdk/std/man/mod.rs @@ -1,9 +1,6 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -11,15 +8,10 @@ mod mod_test; fn print_help(env: &mut Env, help_doc: String, name: &str) -> CommandResult { if help_doc.is_empty() { - writeln!( - arguments.env.out, - "No documentation found for command: {}", - name - ) - .unwrap(); + writeln!(env.out, "No documentation found for command: {}", name).unwrap(); CommandResult::Continue(None) } else { - writeln!(arguments.env.out, "{}", &help_doc).unwrap(); + writeln!(env.out, "{}", &help_doc).unwrap(); CommandResult::Continue(Some(help_doc)) } } @@ -48,7 +40,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { - print_help(env, self.help(), &self.name()) + print_help(arguments.env, self.help(), &self.name()) } else { let name = &arguments.args[0]; @@ -59,7 +51,7 @@ impl Command for CommandImpl { } None => { if name == &self.name() || self.aliases().contains(name) { - print_help(env, self.help(), &self.name()) + print_help(arguments.env, self.help(), &self.name()) } else { writeln!(arguments.env.out, "Command: {} not found.", name).unwrap(); CommandResult::Continue(None) diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs index 8595c156..baf15141 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs @@ -1,11 +1,8 @@ use crate::sdk::std::net::ftp::{validate_and_run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; use suppaftp::FtpStream; #[cfg(test)] diff --git a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs index 10e21348..7b16a4c0 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs @@ -1,11 +1,8 @@ use crate::sdk::std::net::ftp::{run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; use suppaftp::FtpStream; #[cfg(test)] diff --git a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs index 499e45f3..c23511b6 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs @@ -1,11 +1,8 @@ use crate::sdk::std::net::ftp::{run_with_connection, Options}; use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; use suppaftp::FtpStream; #[cfg(test)] diff --git a/duckscript_sdk/src/sdk/std/not/mod.rs b/duckscript_sdk/src/sdk/std/not/mod.rs index 88e9f163..c930594c 100755 --- a/duckscript_sdk/src/sdk/std/not/mod.rs +++ b/duckscript_sdk/src/sdk/std/not/mod.rs @@ -1,9 +1,5 @@ use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs index c94e6e3f..44863337 100755 --- a/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/exit_on_error/mod.rs @@ -1,11 +1,8 @@ use crate::sdk::std::on_error::{get_value, EXIT_ON_ERROR_KEY, STATE_KEY}; use crate::utils::state::get_core_sub_state_for_command; use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -35,7 +32,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { let exit_on_error = if arguments.args.is_empty() { - let value_string = get_value(state, EXIT_ON_ERROR_KEY.to_string()); + let value_string = get_value(arguments.state, EXIT_ON_ERROR_KEY.to_string()); condition::is_true(value_string) } else { let exit_on_error = condition::is_true(Some(arguments.args[0].clone())); diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs index e4622fbd..c3212c53 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error/mod.rs @@ -1,10 +1,6 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs index 24f8ea3a..b5772bf1 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod.rs @@ -1,10 +1,6 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs index 2f986356..7561cacd 100755 --- a/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod.rs @@ -1,10 +1,6 @@ use crate::sdk::std::on_error::get_value; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs index b93a65c7..56be13d1 100755 --- a/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/on_error/mod.rs @@ -1,11 +1,8 @@ use crate::sdk::std::on_error::{get_value, EXIT_ON_ERROR_KEY, STATE_KEY}; use crate::utils::state::get_core_sub_state_for_command; use crate::utils::{condition, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -56,7 +53,8 @@ impl Command for CommandImpl { ("".to_string(), "".to_string()) }; - let sub_state = get_core_sub_state_for_command(state, STATE_KEY.to_string()); + let sub_state = + get_core_sub_state_for_command(arguments.state, STATE_KEY.to_string()); sub_state.insert("error".to_string(), StateValue::String(error)); sub_state.insert("line".to_string(), StateValue::String(line)); sub_state.insert("source".to_string(), StateValue::String(source)); diff --git a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs index 5e7ab825..7ce55349 100755 --- a/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs +++ b/duckscript_sdk/src/sdk/std/on_error/set_error/mod.rs @@ -1,11 +1,8 @@ use crate::sdk::std::on_error::STATE_KEY; use crate::utils::pckg; use crate::utils::state::get_core_sub_state_for_command; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -39,7 +36,10 @@ impl Command for CommandImpl { let sub_state = get_core_sub_state_for_command(arguments.state, STATE_KEY.to_string()); sub_state.insert("error".to_string(), StateValue::String(error)); - sub_state.insert("line".to_string(), StateValue::String(line.to_string())); + sub_state.insert( + "line".to_string(), + StateValue::String(arguments.line.to_string()), + ); sub_state.remove("source"); CommandResult::Continue(None) diff --git a/duckscript_sdk/src/sdk/std/print/mod.rs b/duckscript_sdk/src/sdk/std/print/mod.rs index 1c5f21df..8917408f 100755 --- a/duckscript_sdk/src/sdk/std/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/print/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use colored::{Color, ColoredString, Colorize}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/println/mod.rs b/duckscript_sdk/src/sdk/std/println/mod.rs index 45370bd4..1390d209 100755 --- a/duckscript_sdk/src/sdk/std/println/mod.rs +++ b/duckscript_sdk/src/sdk/std/println/mod.rs @@ -1,10 +1,6 @@ use crate::sdk::std::print::run_print; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/process/exec/mod.rs b/duckscript_sdk/src/sdk/std/process/exec/mod.rs index 615387fb..8d9d4f1a 100755 --- a/duckscript_sdk/src/sdk/std/process/exec/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/exec/mod.rs @@ -1,10 +1,6 @@ use crate::utils::exec::ExecInput; use crate::utils::{exec, pckg}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/release/mod.rs b/duckscript_sdk/src/sdk/std/release/mod.rs index d9b69d7e..cc5e0678 100755 --- a/duckscript_sdk/src/sdk/std/release/mod.rs +++ b/duckscript_sdk/src/sdk/std/release/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; use crate::utils::state::{remove_handle, remove_handle_recursive}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs index 7899fc70..ec242974 100755 --- a/duckscript_sdk/src/sdk/std/scope/clear/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/clear/mod.rs @@ -1,10 +1,6 @@ use crate::types::scope::clear; use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs index 3e20fc52..495c8bfa 100755 --- a/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/pop_stack/mod.rs @@ -1,9 +1,5 @@ use crate::utils::{pckg, scope}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs index 17771b9e..6a3bba5c 100755 --- a/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs +++ b/duckscript_sdk/src/sdk/std/scope/push_stack/mod.rs @@ -1,9 +1,5 @@ use crate::utils::{pckg, scope}; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs index 1e4fe014..fb6110a1 100755 --- a/duckscript_sdk/src/sdk/std/semver/parse/mod.rs +++ b/duckscript_sdk/src/sdk/std/semver/parse/mod.rs @@ -1,10 +1,6 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use semver::Version; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs index 6972a1fc..a9af3ab7 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_decode/mod.rs @@ -1,11 +1,8 @@ use crate::utils::pckg; use crate::utils::state::put_handle; use base64::Engine; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs index 04899382..29f49fbd 100755 --- a/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/base64_encode/mod.rs @@ -1,11 +1,8 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; use base64::Engine; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -37,11 +34,11 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; - match arguments.state.get(key) { + match state.get(key) { Some(state_value) => match state_value { StateValue::ByteArray(binary) => { let encoded = base64::engine::general_purpose::STANDARD.encode(binary); diff --git a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs index 8f3855eb..2e4c15db 100755 --- a/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/bytes_to_string/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::get_handles_sub_state; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; use std::str; #[cfg(test)] @@ -37,11 +34,11 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("Array handle not provided.".to_string()) } else { - let state = get_handles_sub_state(state); + let state = get_handles_sub_state(arguments.state); let key = &arguments.args[0]; - match arguments.state.get(key) { + match state.get(key) { Some(state_value) => match state_value { StateValue::ByteArray(binary) => match str::from_utf8(&binary) { Ok(text) => CommandResult::Continue(Some(text.to_string())), diff --git a/duckscript_sdk/src/sdk/std/string/split/mod.rs b/duckscript_sdk/src/sdk/std/string/split/mod.rs index eba2a1e7..a890870a 100755 --- a/duckscript_sdk/src/sdk/std/string/split/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/split/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs index a4396be7..03784f37 100755 --- a/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs +++ b/duckscript_sdk/src/sdk/std/string/string_to_bytes/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs index 269c67c0..67310cb8 100755 --- a/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_directory/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use duckscript::runner; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::{Context, StateValue}; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; +use duckscript::types::runtime::Context; use walkdir::DirEntry; use walkdir::WalkDir; diff --git a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs index f895cce7..af8a20be 100755 --- a/duckscript_sdk/src/sdk/std/test/test_file/mod.rs +++ b/duckscript_sdk/src/sdk/std/test/test_file/mod.rs @@ -1,10 +1,8 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::{Instruction, InstructionType}; -use duckscript::types::runtime::{Context, StateValue}; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; +use duckscript::types::instruction::InstructionType; +use duckscript::types::runtime::Context; use duckscript::{parser, runner}; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] @@ -69,12 +67,11 @@ impl Command for CommandImpl { script_instruction.arguments.as_ref(), ) { (Some(current_command), Some(current_arguments)) => { - if !current_arguments.args.is_empty() + if !current_arguments.is_empty() && command_names.contains(¤t_command) { - if current_arguments.args[0].starts_with("test_") { - test_names - .push(current_arguments.args[0].clone()); + if current_arguments[0].starts_with("test_") { + test_names.push(current_arguments[0].clone()); } } } @@ -92,7 +89,7 @@ impl Command for CommandImpl { let script = create_test_script(&file, &test_name); let mut context = Context::new(); - context.commands = commands.clone(); + context.commands = arguments.commands.clone(); match runner::run_script(&script, context, None) { Err(error) => { diff --git a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs index a02e50be..0555877d 100755 --- a/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_all_var_names/mod.rs @@ -1,10 +1,7 @@ use crate::utils::pckg; use crate::utils::state::put_handle; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs index 21fe63b2..795c288f 100755 --- a/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/get_by_name/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs index 717be008..4e9f926a 100755 --- a/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/is_defined/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs index 6cf0369a..9f6c1c8e 100755 --- a/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/set_by_name/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs index 64856d2e..e8c4a9f6 100755 --- a/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/unset_all_vars/mod.rs @@ -1,9 +1,5 @@ use crate::utils::pckg; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; -use duckscript::types::instruction::Instruction; -use duckscript::types::runtime::StateValue; -use std::collections::HashMap; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; #[cfg(test)] #[path = "./mod_test.rs"] diff --git a/duckscript_sdk/src/types/command.rs b/duckscript_sdk/src/types/command.rs index c018a827..b14dcbcf 100644 --- a/duckscript_sdk/src/types/command.rs +++ b/duckscript_sdk/src/types/command.rs @@ -3,12 +3,10 @@ use crate::types::scope::set_line_context_name; use crate::utils::eval; use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::parser; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::error::ScriptError; use duckscript::types::instruction::Instruction; use duckscript::types::runtime::StateValue; -use std::collections::HashMap; #[derive(Clone)] pub(crate) struct AliasCommand { @@ -84,8 +82,8 @@ impl Command for AliasCommand { if arguments.args.len() < self.arguments_amount { CommandResult::Error("Invalid arguments provided.".to_string()) } else { - let start_count = variables.len(); - let line_context_name = set_line_context_name(&self.scope_name, state); + let start_count = arguments.variables.len(); + let line_context_name = set_line_context_name(&self.scope_name, arguments.state); // define script arguments let mut handle_option = None; @@ -103,12 +101,12 @@ impl Command for AliasCommand { array.push(StateValue::String(argument.clone())); } - let handle = put_handle(argument.state, StateValue::List(array)); + let handle = put_handle(arguments.state, StateValue::List(array)); let mut key = self.scope_name.clone(); key.push_str("::arguments"); - variables.insert(key, handle.clone()); + arguments.variables.insert(key, handle.clone()); handle_option = Some(handle); } @@ -117,7 +115,7 @@ impl Command for AliasCommand { arguments.commands, arguments.state, arguments.variables, - env, + arguments.env, 0, ); diff --git a/duckscript_sdk/src/utils/condition.rs b/duckscript_sdk/src/utils/condition.rs index bf67270e..313e36e8 100644 --- a/duckscript_sdk/src/utils/condition.rs +++ b/duckscript_sdk/src/utils/condition.rs @@ -29,7 +29,7 @@ pub(crate) fn is_true(value: Option) -> bool { } pub(crate) fn eval_condition( - arguments: CommandArgs, + arguments: &Vec, instructions: &Vec, state: &mut HashMap, variables: &mut HashMap, From f68effe3531780b862cce45eced2aa3a412eb33d Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Thu, 3 Oct 2024 15:08:48 +0000 Subject: [PATCH 09/12] dev --- duckscript_sdk/src/sdk/std/eval/mod.rs | 2 +- duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs | 2 +- .../src/sdk/std/fs/gitignore_path_array/mod.rs | 2 +- duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs | 2 +- duckscript_sdk/src/sdk/std/hash/digest/mod.rs | 2 +- duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs | 2 +- duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs | 2 +- .../src/sdk/std/net/ftp/get_in_memory/mod.rs | 2 +- duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs | 4 ++-- duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs | 4 ++-- duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs | 2 +- .../src/sdk/std/net/ftp/put_in_memory/mod.rs | 2 +- duckscript_sdk/src/sdk/std/not/mod.rs | 2 +- duckscript_sdk/src/sdk/std/print/mod.rs | 10 +++++----- duckscript_sdk/src/sdk/std/println/mod.rs | 2 +- duckscript_sdk/src/sdk/std/process/exec/mod.rs | 2 +- duckscript_sdk/src/sdk/std/process/spawn/mod.rs | 10 ++++++++-- duckscript_sdk/src/sdk/std/process/watchdog/mod.rs | 4 ++-- duckscript_sdk/src/sdk/std/var/set/mod.rs | 2 +- duckscript_sdk/src/test/mod.rs | 10 ++++------ duckscript_sdk/src/utils/condition.rs | 10 +++++----- duckscript_sdk/src/utils/condition_test.rs | 12 ++++++------ duckscript_sdk/src/utils/eval.rs | 4 ++-- duckscript_sdk/src/utils/exec.rs | 8 ++++---- 24 files changed, 54 insertions(+), 50 deletions(-) diff --git a/duckscript_sdk/src/sdk/std/eval/mod.rs b/duckscript_sdk/src/sdk/std/eval/mod.rs index 5884ec47..c7b9c50e 100755 --- a/duckscript_sdk/src/sdk/std/eval/mod.rs +++ b/duckscript_sdk/src/sdk/std/eval/mod.rs @@ -27,7 +27,7 @@ impl Command for CommandImpl { Box::new((*self).clone()) } - fn run(&self, arguments: CommandArgs) -> CommandResult { + fn run(&self, mut arguments: CommandArgs) -> CommandResult { eval::eval_with_error( &arguments.args, &mut arguments.state, diff --git a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs index 9f373e63..42a97bc3 100755 --- a/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs +++ b/duckscript_sdk/src/sdk/std/flowcontrol/ifelse/mod.rs @@ -447,7 +447,7 @@ impl Command for ElseIfCommand { } else { let if_else_info = call_info.meta_info.clone(); let line_context_name = get_line_context_name(arguments.state); - match condition::eval_condition(arguments.args, arguments.instructions, arguments.state, arguments.variables, arguments.commands, arguments.env) { + match condition::eval_condition(&arguments.args, arguments.instructions, arguments.state, arguments.variables, arguments.commands, arguments.env) { Ok(passed) => { if passed { let next_line = if call_info.else_line_index + 1 < if_else_info.else_lines.len() { diff --git a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs index 13fd0877..89c4e80d 100755 --- a/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod.rs @@ -56,7 +56,7 @@ impl Command for CommandImpl { let value_string: String = FromPath::from_path(&path.path()); let state_value = StateValue::String(value_string); - array.push(arguments.state_value); + array.push(state_value); } Err(error) => return CommandResult::Error(error.to_string()), } diff --git a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs index 45b66733..d4a21bf9 100644 --- a/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs +++ b/duckscript_sdk/src/sdk/std/fs/zip/zip/mod.rs @@ -50,7 +50,7 @@ impl Command for CommandImpl { compression, zipfile, file_args, - } = match parse_args(&arguments) { + } = match parse_args(&arguments.args) { Ok(options) => options, Err(err) => return CommandResult::Error(err), }; diff --git a/duckscript_sdk/src/sdk/std/hash/digest/mod.rs b/duckscript_sdk/src/sdk/std/hash/digest/mod.rs index abbab277..96ffdec8 100755 --- a/duckscript_sdk/src/sdk/std/hash/digest/mod.rs +++ b/duckscript_sdk/src/sdk/std/hash/digest/mod.rs @@ -149,7 +149,7 @@ impl Command for CommandImpl { if arguments.args.is_empty() { CommandResult::Error("No input provided.".to_string()) } else { - match parse_options(&arguments) { + match parse_options(&arguments.args) { Ok(options) => { if options.algorithm.is_none() { CommandResult::Error("No algorithm defined".to_string()) diff --git a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs index 85d74a9f..5e58629c 100755 --- a/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/lib/alias/set/mod.rs @@ -36,7 +36,7 @@ fn create_alias_command( fn run(&self, arguments: CommandArgs) -> CommandResult { let mut all_arguments = vec![]; - all_arguments.append(&mut self.arguments.args.clone()); + all_arguments.append(&mut self.arguments.clone()); all_arguments.append(&mut arguments.args.clone()); eval::eval_with_error( diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs index dcd86278..92ab2df6 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get/mod.rs @@ -56,7 +56,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( - &arguments, + &arguments.args, &|options: &Options| -> Result<(), String> { if options.remote_file.is_none() { Err("Missing remote file name".to_string()) diff --git a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs index baf15141..c8af39f2 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod.rs @@ -33,7 +33,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( - &arguments, + &arguments.args, &|options: &Options| -> Result<(), String> { if options.remote_file.is_none() { Err("Missing remote file name".to_string()) diff --git a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs index 7b16a4c0..1f5f9320 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/list/mod.rs @@ -32,8 +32,8 @@ impl Command for CommandImpl { } fn run(&self, arguments: CommandArgs) -> CommandResult { - run_with_connection(&arguments, &mut |_options: &Options, - ftp_stream: &mut FtpStream| + run_with_connection(&arguments.args, &mut |_options: &Options, + ftp_stream: &mut FtpStream| -> CommandResult { match ftp_stream.list(None) { Ok(output) => { diff --git a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs index c23511b6..f2836927 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/nlst/mod.rs @@ -32,8 +32,8 @@ impl Command for CommandImpl { } fn run(&self, arguments: CommandArgs) -> CommandResult { - run_with_connection(&arguments, &mut |_options: &Options, - ftp_stream: &mut FtpStream| + run_with_connection(&arguments.args, &mut |_options: &Options, + ftp_stream: &mut FtpStream| -> CommandResult { match ftp_stream.nlst(None) { Ok(output) => { diff --git a/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs index bf2f03a6..2e6010f1 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/put/mod.rs @@ -33,7 +33,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( - &arguments, + &arguments.args, &|options: &Options| -> Result<(), String> { if options.remote_file.is_none() { Err("Missing remote file name".to_string()) diff --git a/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs b/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs index 3968658f..3be641c0 100755 --- a/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs +++ b/duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod.rs @@ -32,7 +32,7 @@ impl Command for CommandImpl { fn run(&self, arguments: CommandArgs) -> CommandResult { validate_and_run_with_connection( - &arguments, + &arguments.args, &|options: &Options| -> Result<(), String> { if options.remote_file.is_none() { Err("Missing remote file name".to_string()) diff --git a/duckscript_sdk/src/sdk/std/not/mod.rs b/duckscript_sdk/src/sdk/std/not/mod.rs index c930594c..db27f753 100755 --- a/duckscript_sdk/src/sdk/std/not/mod.rs +++ b/duckscript_sdk/src/sdk/std/not/mod.rs @@ -32,7 +32,7 @@ impl Command for CommandImpl { CommandResult::Error("Missing condition".to_string()) } else { match condition::eval_condition( - arguments.args, + &arguments.args, arguments.instructions, arguments.state, arguments.variables, diff --git a/duckscript_sdk/src/sdk/std/print/mod.rs b/duckscript_sdk/src/sdk/std/print/mod.rs index 8917408f..a1c11e7e 100755 --- a/duckscript_sdk/src/sdk/std/print/mod.rs +++ b/duckscript_sdk/src/sdk/std/print/mod.rs @@ -135,14 +135,14 @@ fn add_color( } } -pub(crate) fn run_print(env: &mut Env, arguments: CommandArgs) -> CommandResult { +pub(crate) fn run_print(env: &mut Env, arguments: &Vec) -> CommandResult { // collect options let mut styles = vec![]; let mut text_color = None; let mut background_color = None; let mut index = 0; let mut looking_for = LookingFor::Flag; - for argument in &arguments { + for argument in arguments { index = index + 1; match looking_for { @@ -173,7 +173,7 @@ pub(crate) fn run_print(env: &mut Env, arguments: CommandArgs) -> CommandResult // generate whole string let mut string = String::new(); let mut count = 0; - for argument in &arguments.args[index..] { + for argument in &arguments[index..] { count = count + 1; string.push_str(argument); string.push(' '); @@ -188,7 +188,7 @@ pub(crate) fn run_print(env: &mut Env, arguments: CommandArgs) -> CommandResult styled_string = add_color(styled_string, background_color, true); styled_string = add_styles(styled_string, styles); - match write!(arguments.env.out, "{}", styled_string) { + match write!(env.out, "{}", styled_string) { Ok(_) => CommandResult::Continue(Some(count.to_string())), Err(error) => CommandResult::Error(error.to_string()), } @@ -217,7 +217,7 @@ impl Command for CommandImpl { } fn run(&self, arguments: CommandArgs) -> CommandResult { - run_print(arguments.env, arguments.args) + run_print(arguments.env, &arguments.args) } } diff --git a/duckscript_sdk/src/sdk/std/println/mod.rs b/duckscript_sdk/src/sdk/std/println/mod.rs index 1390d209..9e49823a 100755 --- a/duckscript_sdk/src/sdk/std/println/mod.rs +++ b/duckscript_sdk/src/sdk/std/println/mod.rs @@ -29,7 +29,7 @@ impl Command for CommandImpl { } fn run(&self, arguments: CommandArgs) -> CommandResult { - let result = run_print(arguments.env, arguments.args); + let result = run_print(arguments.env, &arguments.args); if let CommandResult::Continue(ref _value) = result { match writeln!(arguments.env.out, "") { diff --git a/duckscript_sdk/src/sdk/std/process/exec/mod.rs b/duckscript_sdk/src/sdk/std/process/exec/mod.rs index 8d9d4f1a..d81d8d0b 100755 --- a/duckscript_sdk/src/sdk/std/process/exec/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/exec/mod.rs @@ -52,7 +52,7 @@ impl Command for CommandImpl { match looking_for { LookingFor::Flag => match argument.as_str() { "--fail-on-error" => { - fail_on_error = argument.output_variable.is_none(); + fail_on_error = arguments.output_variable.is_none(); command_start_index = command_start_index + 1; } "--get-exit-code" => { diff --git a/duckscript_sdk/src/sdk/std/process/spawn/mod.rs b/duckscript_sdk/src/sdk/std/process/spawn/mod.rs index b25f7c0b..8f76e24b 100755 --- a/duckscript_sdk/src/sdk/std/process/spawn/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/spawn/mod.rs @@ -40,7 +40,7 @@ impl Command for CommandImpl { let mut index = 0; let mut looking_for = LookingFor::Flag; - for argument in &arguments { + for argument in &arguments.args { index = index + 1; match looking_for { @@ -64,7 +64,13 @@ impl Command for CommandImpl { } } - match exec::spawn(&arguments, print_output, true, input, command_start_index) { + match exec::spawn( + &arguments.args, + print_output, + true, + input, + command_start_index, + ) { Ok(child) => { let pid = child.id(); diff --git a/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs b/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs index efb3df25..ec72b216 100755 --- a/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs +++ b/duckscript_sdk/src/sdk/std/process/watchdog/mod.rs @@ -48,7 +48,7 @@ impl Command for CommandImpl { let mut index = 0; let mut looking_for = LookingFor::Flag; - for argument in &arguments { + for argument in &arguments.args { index = index + 1; match looking_for { @@ -114,7 +114,7 @@ impl Command for CommandImpl { loop { attempt = attempt + 1; - match exec::exec(&arguments, false, input.clone(), command_start_index) { + match exec::exec(&arguments.args, false, input.clone(), command_start_index) { Ok(_) => (), Err(error) => return CommandResult::Error(error), } diff --git a/duckscript_sdk/src/sdk/std/var/set/mod.rs b/duckscript_sdk/src/sdk/std/var/set/mod.rs index 9330493e..e00c85c2 100755 --- a/duckscript_sdk/src/sdk/std/var/set/mod.rs +++ b/duckscript_sdk/src/sdk/std/var/set/mod.rs @@ -59,7 +59,7 @@ impl Command for CommandImpl { } else if arguments.args.len() == 1 { Some(arguments.args[0].clone()) } else { - match get_output(&arguments) { + match get_output(&arguments.args) { Ok(output) => output, Err(error) => return CommandResult::Error(error), } diff --git a/duckscript_sdk/src/test/mod.rs b/duckscript_sdk/src/test/mod.rs index 04b75562..7b8f07fb 100644 --- a/duckscript_sdk/src/test/mod.rs +++ b/duckscript_sdk/src/test/mod.rs @@ -1,9 +1,7 @@ use crate::utils::state::{get_handles_sub_state, put_handle}; use duckscript::runner; -use duckscript::types::command::{Command, CommandArgs, CommandResult, Commands}; -use duckscript::types::env::Env; +use duckscript::types::command::{Command, CommandArgs, CommandResult}; use duckscript::types::error::ScriptError; -use duckscript::types::instruction::Instruction; use duckscript::types::runtime::{Context, StateValue}; use std::collections::HashMap; use std::env; @@ -116,7 +114,7 @@ impl Command for ArrayCommand { array.push(StateValue::String(argument)); } - let key = put_handle(argument.state, StateValue::List(array)); + let key = put_handle(arguments.state, StateValue::List(array)); CommandResult::Continue(Some(key)) } @@ -135,7 +133,7 @@ impl Command for OnErrorCommand { } fn run(&self, arguments: CommandArgs) -> CommandResult { - println!("on error: {:#?}", &arguments); + println!("on error: {:#?}", &arguments.args); let mut index = 0; for argument in arguments.args { @@ -145,7 +143,7 @@ impl Command for OnErrorCommand { .insert(index.to_string(), argument.clone()); } - argument + arguments .variables .insert("on_error_invoked".to_string(), "true".to_string()); diff --git a/duckscript_sdk/src/utils/condition.rs b/duckscript_sdk/src/utils/condition.rs index 313e36e8..588350ab 100644 --- a/duckscript_sdk/src/utils/condition.rs +++ b/duckscript_sdk/src/utils/condition.rs @@ -36,10 +36,10 @@ pub(crate) fn eval_condition( commands: &mut Commands, env: &mut Env, ) -> Result { - if arguments.args.is_empty() { + if arguments.is_empty() { Ok(is_true(None)) } else { - let eval_statement = commands.exists(&arguments.args[0]); + let eval_statement = commands.exists(&arguments[0]); if eval_statement { match eval::eval_with_instructions( @@ -59,13 +59,13 @@ pub(crate) fn eval_condition( _ => Err("Invalid condition evaluation result.".to_string()), } } else { - eval_condition_for_slice(&arguments.args[..]) + eval_condition_for_slice(&arguments[..]) } } } pub(crate) fn eval_condition_for_slice(arguments: &[String]) -> Result { - if arguments.args.is_empty() { + if arguments.is_empty() { Ok(is_true(None)) } else { let mut searching_block_end = false; @@ -88,7 +88,7 @@ pub(crate) fn eval_condition_for_slice(arguments: &[String]) -> Result { start_block = 0; diff --git a/duckscript_sdk/src/utils/condition_test.rs b/duckscript_sdk/src/utils/condition_test.rs index 5fe640b3..42322dd8 100644 --- a/duckscript_sdk/src/utils/condition_test.rs +++ b/duckscript_sdk/src/utils/condition_test.rs @@ -60,7 +60,7 @@ fn is_true_valid() { #[test] fn eval_condition_empty() { let result = eval_condition( - vec![], + &vec![], &vec![], &mut HashMap::new(), &mut HashMap::new(), @@ -78,7 +78,7 @@ fn eval_condition_empty() { #[test] fn eval_condition_value_true() { let result = eval_condition( - vec!["true".to_string()], + &vec!["true".to_string()], &vec![], &mut HashMap::new(), &mut HashMap::new(), @@ -96,7 +96,7 @@ fn eval_condition_value_true() { #[test] fn eval_condition_value_false() { let result = eval_condition( - vec!["false".to_string()], + &vec!["false".to_string()], &vec![], &mut HashMap::new(), &mut HashMap::new(), @@ -120,7 +120,7 @@ fn eval_condition_command_true() { } let result = eval_condition( - vec!["test_set".to_string(), "true".to_string()], + &vec!["test_set".to_string(), "true".to_string()], &vec![], &mut HashMap::new(), &mut HashMap::new(), @@ -144,7 +144,7 @@ fn eval_condition_command_false() { } let result = eval_condition( - vec!["test_set".to_string(), "false".to_string()], + &vec!["test_set".to_string(), "false".to_string()], &vec![], &mut HashMap::new(), &mut HashMap::new(), @@ -168,7 +168,7 @@ fn eval_condition_command_error() { } let result = eval_condition( - vec!["test_error".to_string()], + &vec!["test_error".to_string()], &vec![], &mut HashMap::new(), &mut HashMap::new(), diff --git a/duckscript_sdk/src/utils/eval.rs b/duckscript_sdk/src/utils/eval.rs index 1d686859..2f486aef 100644 --- a/duckscript_sdk/src/utils/eval.rs +++ b/duckscript_sdk/src/utils/eval.rs @@ -49,7 +49,7 @@ pub(crate) fn eval( commands: &mut Commands, env: &mut Env, ) -> Result { - if arguments.args.is_empty() { + if arguments.is_empty() { Ok(CommandResult::Continue(None)) } else { match parse(arguments) { @@ -95,7 +95,7 @@ pub(crate) fn eval_with_instructions( commands: &mut Commands, env: &mut Env, ) -> CommandResult { - if arguments.args.is_empty() { + if arguments.is_empty() { CommandResult::Continue(None) } else { match parse(arguments) { diff --git a/duckscript_sdk/src/utils/exec.rs b/duckscript_sdk/src/utils/exec.rs index b6fc3286..49237441 100644 --- a/duckscript_sdk/src/utils/exec.rs +++ b/duckscript_sdk/src/utils/exec.rs @@ -29,7 +29,7 @@ pub(crate) fn exec( None => { return Err(format!( "Unable to extract exit code for command: {}", - &arguments.args[0] + &arguments[0] ) .to_string()); } @@ -78,13 +78,13 @@ fn create_command( input: &ExecInput, start_index: usize, ) -> Result { - if arguments.args.len() <= start_index { + if arguments.len() <= start_index { Err("Command not provided.".to_string()) } else { - let mut command = Command::new(&arguments.args[start_index]); + let mut command = Command::new(&arguments[start_index]); let argument_index = start_index + 1; - for argument in &arguments.args[argument_index..] { + for argument in &arguments[argument_index..] { command.arg(argument); } From 11b8e974597efe227ee6931a0cd55fa5327f867e Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Thu, 3 Oct 2024 15:38:10 +0000 Subject: [PATCH 10/12] dev --- docs/_includes/content.md | 29 ++++++++++++++++------------- docs/_includes/nav.md | 4 ++-- 2 files changed, 18 insertions(+), 15 deletions(-) diff --git a/docs/_includes/content.md b/docs/_includes/content.md index ec14f983..bdd82e37 100755 --- a/docs/_includes/content.md +++ b/docs/_includes/content.md @@ -356,13 +356,8 @@ If you want to know how to write your own commands or embed the duckscript runti Want to write new custom commands so you can use them in your duckscripts? great!
Hopefully the following sections will help you gain the basic knowledge on how to write them.
-First of all it is important to understand that there are two types of commands: - -* Commands which execute some action like copying files, printing some text to the console or returning an environment variable. -* Commands which provide flow control or some more complex action and require modifying the internal context in runtime. - - -## Standard Commands + +## Commands Commands are structs that must implement the Command trait.
* They must have a name, which is used to invoke the command.
@@ -370,7 +365,7 @@ Commands are structs that must implement the Command trait.
* They should return help documentation in markdown format in order to generate SDK documentation (must for PRs to duckscript official SDK).
* They must implement the **run** function which holds the command logic.
-The run function accepts the command arguments (variables already replaced to actual values) and returns the command result.
+The run function accepts the command arguments (args array contains actual values and not original variables) and returns the command result.
The command result can be one of the following: * Continue(Option) - Tells the runner to continue to the next command and optionally set the output variable the given value. @@ -393,11 +388,15 @@ impl Command for SetCommand { "set".to_string() } - fn run(&self, arguments: Vec) -> CommandResult { - let output = if arguments.is_empty() { + fn clone_and_box(&self) -> Box { + Box::new((*self).clone()) + } + + fn run(&self, arguments: CommandArgs) -> CommandResult { + let output = if arguments.args.is_empty() { None } else { - Some(arguments[0].clone()) + Some(arguments.args[0].clone()) }; CommandResult::Continue(output) @@ -420,6 +419,10 @@ impl Command for GetEnvCommand { "get_env".to_string() } + fn clone_and_box(&self) -> Box { + Box::new((*self).clone()) + } + fn run(&self, arguments: CommandArgs) -> CommandResult { if arguments.args.is_empty() { CommandResult::Error("Missing environment variable name.".to_string()) @@ -435,8 +438,8 @@ impl Command for GetEnvCommand { You can look at more examples in the duckscript_sdk folder. - -## Access to Context + +## Access The Context The duckscript runtime context is available in the CommandArgs struc.
```rust diff --git a/docs/_includes/nav.md b/docs/_includes/nav.md index aa1d44c3..4908fcbe 100755 --- a/docs/_includes/nav.md +++ b/docs/_includes/nav.md @@ -21,8 +21,8 @@ * [Full SDK Docs](https://github.com/sagiegurari/duckscript/blob/master/docs/sdk.md) * [Final Notes](#tutorial-final-notes) * [Duckscript Command Implementation Tutorial](#sdk-tutorial) - * [Standard Commands](#sdk-tutorial-standard-commands) - * [Context Commands](#sdk-tutorial-context-commands) + * [Commands](#sdk-tutorial-commands) + * [Access The Context](#sdk-tutorial-commands-context) * [Duckscript Embedding Tutorial](#embed-tutorial) * [Setting Up The Context](#embed-tutorial-setup-context) * [Running The Script](#embed-tutorial-running) From ccc8699395c90c9fa69d0d1d239a6702331aaa08 Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Thu, 3 Oct 2024 15:43:14 +0000 Subject: [PATCH 11/12] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c975c001..fe530dfb 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ### v0.10.0 * Enhancement: Runtime - \[Breaking Change\] New Env struct enabling commands to redirect out/err to provided streams #440 +* Enhancement: Runtime - \[Breaking Change\] Commands now get new CommandArgs struct instead of multiple fields. ### v0.9.4 (2024-09-28) From 1db4769aa595c251dec09038b3aafb0d5e0ecd5c Mon Sep 17 00:00:00 2001 From: sagie gur ari Date: Thu, 3 Oct 2024 15:46:42 +0000 Subject: [PATCH 12/12] dependencies --- CHANGELOG.md | 1 + duckscript_sdk/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fe530dfb..8825d0c2 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * Enhancement: Runtime - \[Breaking Change\] New Env struct enabling commands to redirect out/err to provided streams #440 * Enhancement: Runtime - \[Breaking Change\] Commands now get new CommandArgs struct instead of multiple fields. +* Enhancement: Runtime - Enable to halt execution via env. ### v0.9.4 (2024-09-28) diff --git a/duckscript_sdk/Cargo.toml b/duckscript_sdk/Cargo.toml index d9259911..f4492b04 100644 --- a/duckscript_sdk/Cargo.toml +++ b/duckscript_sdk/Cargo.toml @@ -47,7 +47,7 @@ suppaftp = "^6.0" walkdir = "^2" which = { version = "^6", default-features = false } whoami = "^1" -zip = { version = "^1", default-features = false, features = [ +zip = { version = "^2", default-features = false, features = [ "bzip2", "deflate", "time",