├── .buildnumber ├── examples ├── man.ds ├── store_output.ds ├── hello_world.ds ├── single_argument.ds ├── goto_label.ds ├── comment.ds ├── single_argument_with_escape.ds ├── on_error_2.ds ├── user_input.ds ├── print.ds ├── include_files.ds ├── alias.ds ├── exec.ds ├── functions.ds ├── binding.ds ├── use_variable.ds ├── array.ds ├── string.ds ├── ls.ds ├── debug.ds ├── on_error.ds └── for_in.ds ├── docs ├── index.md ├── Gemfile ├── favicon.ico ├── _config.yml ├── _includes │ └── main.html └── api.html ├── duckscript ├── src │ ├── test │ │ └── scripts │ │ │ ├── crash.ds │ │ │ ├── echo.ds │ │ │ ├── print_preprocessor.ds │ │ │ ├── include_file.ds │ │ │ ├── set.ds │ │ │ ├── simple_runnable.ds │ │ │ ├── multiple_commands.ds │ │ │ └── simple.ds │ ├── lib_test.rs │ ├── types │ │ ├── mod.rs │ │ └── env_test.rs │ └── preprocessor │ │ ├── print_preprocessor.rs │ │ └── include_files_preprocessor_test.rs └── README.md ├── .gitattributes ├── duckscript_sdk ├── src │ ├── types │ │ └── mod.rs │ ├── sdk │ │ ├── std │ │ │ ├── env │ │ │ │ ├── is_windows │ │ │ │ │ ├── script.ds │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── print_env │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── script.ds │ │ │ │ │ └── help.md │ │ │ │ ├── uname │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── help.md │ │ │ │ │ ├── script.ds │ │ │ │ │ └── mod.rs │ │ │ │ ├── os_name │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── cpu_count │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── get_user_name │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── os_family │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── os_release │ │ │ │ │ └── help.md │ │ │ │ ├── os_version │ │ │ │ │ └── help.md │ │ │ │ ├── unset │ │ │ │ │ └── help.md │ │ │ │ ├── get_env │ │ │ │ │ └── help.md │ │ │ │ ├── get_home_dir │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── which │ │ │ │ │ └── help.md │ │ │ │ ├── print_current_directory │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── env_to_map │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ └── set_current_directory │ │ │ │ │ └── help.md │ │ │ ├── var │ │ │ │ ├── unset │ │ │ │ │ ├── script.ds │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod.rs │ │ │ │ ├── get_all_var_names │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── unset_all_vars │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── is_defined │ │ │ │ │ └── help.md │ │ │ │ ├── get_by_name │ │ │ │ │ └── help.md │ │ │ │ └── set_by_name │ │ │ │ │ └── help.md │ │ │ ├── collections │ │ │ │ ├── map_is_empty │ │ │ │ │ ├── script.ds │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── set_is_empty │ │ │ │ │ ├── script.ds │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── array_is_empty │ │ │ │ │ ├── script.ds │ │ │ │ │ └── help.md │ │ │ │ ├── array_join │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── array_concat │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── help.md │ │ │ │ │ └── script.ds │ │ │ │ ├── array_contains │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── map_contains_key │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── script.ds │ │ │ │ │ └── help.md │ │ │ │ ├── set_from_array │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── help.md │ │ │ │ │ └── script.ds │ │ │ │ ├── map_contains_value │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── set_put │ │ │ │ │ └── help.md │ │ │ │ ├── set_contains │ │ │ │ │ └── help.md │ │ │ │ ├── array_push │ │ │ │ │ └── help.md │ │ │ │ ├── set_to_array │ │ │ │ │ └── help.md │ │ │ │ ├── array_pop │ │ │ │ │ └── help.md │ │ │ │ ├── is_set │ │ │ │ │ └── help.md │ │ │ │ ├── is_array │ │ │ │ │ └── help.md │ │ │ │ ├── is_map │ │ │ │ │ └── help.md │ │ │ │ ├── array_get │ │ │ │ │ └── help.md │ │ │ │ ├── set_size │ │ │ │ │ └── help.md │ │ │ │ ├── map_size │ │ │ │ │ └── help.md │ │ │ │ ├── map_to_properties │ │ │ │ │ └── help.md │ │ │ │ ├── map_put │ │ │ │ │ └── help.md │ │ │ │ ├── map │ │ │ │ │ └── help.md │ │ │ │ ├── map_get │ │ │ │ │ └── help.md │ │ │ │ ├── map_clear │ │ │ │ │ └── help.md │ │ │ │ ├── set_clear │ │ │ │ │ └── help.md │ │ │ │ ├── array_clear │ │ │ │ │ └── help.md │ │ │ │ ├── map_remove │ │ │ │ │ └── help.md │ │ │ │ ├── set_remove │ │ │ │ │ └── help.md │ │ │ │ ├── map_load_properties │ │ │ │ │ └── help.md │ │ │ │ ├── array_length │ │ │ │ │ └── help.md │ │ │ │ ├── set │ │ │ │ │ └── help.md │ │ │ │ ├── array │ │ │ │ │ └── help.md │ │ │ │ ├── help.md │ │ │ │ ├── array_remove │ │ │ │ │ └── help.md │ │ │ │ ├── range │ │ │ │ │ └── help.md │ │ │ │ └── map_keys │ │ │ │ │ └── help.md │ │ │ ├── read │ │ │ │ ├── mod_test.rs │ │ │ │ └── help.md │ │ │ ├── json │ │ │ │ ├── encode │ │ │ │ │ └── mod_test.rs │ │ │ │ └── mod.rs │ │ │ ├── net │ │ │ │ ├── wget │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── mod.rs │ │ │ │ ├── hostname │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── ftp │ │ │ │ │ ├── get │ │ │ │ │ │ └── mod_test.rs │ │ │ │ │ ├── put │ │ │ │ │ │ └── mod_test.rs │ │ │ │ │ ├── get_in_memory │ │ │ │ │ │ └── mod_test.rs │ │ │ │ │ ├── put_in_memory │ │ │ │ │ │ └── mod_test.rs │ │ │ │ │ ├── list │ │ │ │ │ │ └── mod_test.rs │ │ │ │ │ └── nlst │ │ │ │ │ │ └── mod_test.rs │ │ │ │ └── mod.rs │ │ │ ├── test │ │ │ │ ├── test_file │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── test_directory │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── assert_fail │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── assert_error │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ └── assert_eq │ │ │ │ │ └── help.md │ │ │ ├── fs │ │ │ │ ├── cp_glob │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── join_path │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── help.md │ │ │ │ │ └── script.ds │ │ │ │ ├── set_mode_glob │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── script.ds │ │ │ │ ├── temp_dir │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── gitignore_path_array │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── temp_file │ │ │ │ │ └── help.md │ │ │ │ ├── is_directory │ │ │ │ │ └── help.md │ │ │ │ ├── is_file │ │ │ │ │ └── help.md │ │ │ │ ├── get_file_size │ │ │ │ │ └── help.md │ │ │ │ ├── read_bytes │ │ │ │ │ └── help.md │ │ │ │ ├── is_readonly │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── print │ │ │ │ │ └── help.md │ │ │ │ ├── dirname │ │ │ │ │ └── help.md │ │ │ │ ├── read_text │ │ │ │ │ └── help.md │ │ │ │ ├── basename │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── mkdir │ │ │ │ │ └── help.md │ │ │ │ ├── canonical │ │ │ │ │ └── help.md │ │ │ │ ├── get_last_modified_time │ │ │ │ │ └── help.md │ │ │ │ ├── exists │ │ │ │ │ └── help.md │ │ │ │ ├── rmdir │ │ │ │ │ └── help.md │ │ │ │ ├── touch │ │ │ │ │ └── help.md │ │ │ │ ├── zip │ │ │ │ │ ├── zip │ │ │ │ │ │ └── mod_test.rs │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── unzip │ │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ │ └── help.md │ │ │ │ ├── set_mode │ │ │ │ │ └── help.md │ │ │ │ ├── glob_array │ │ │ │ │ └── help.md │ │ │ │ ├── is_path_newer │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ └── help.md │ │ │ │ ├── write_text │ │ │ │ │ └── help.md │ │ │ │ ├── cp │ │ │ │ │ └── help.md │ │ │ │ ├── write_bytes │ │ │ │ │ └── help.md │ │ │ │ └── append │ │ │ │ │ └── help.md │ │ │ ├── string │ │ │ │ ├── base64 │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── concat │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── script.ds │ │ │ │ │ └── help.md │ │ │ │ ├── length │ │ │ │ │ └── help.md │ │ │ │ ├── lowercase │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── uppercase │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── is_empty │ │ │ │ │ └── help.md │ │ │ │ ├── camelcase │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── kebabcase │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── snakecase │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── trim │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── trim_end │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── trim_start │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── bytes_to_string │ │ │ │ │ └── help.md │ │ │ │ ├── string_to_bytes │ │ │ │ │ └── help.md │ │ │ │ ├── equals │ │ │ │ │ └── help.md │ │ │ │ ├── replace │ │ │ │ │ └── help.md │ │ │ │ ├── indexof │ │ │ │ │ └── help.md │ │ │ │ ├── contains │ │ │ │ │ └── help.md │ │ │ │ ├── base64_decode │ │ │ │ │ └── help.md │ │ │ │ ├── base64_encode │ │ │ │ │ └── help.md │ │ │ │ ├── ends_with │ │ │ │ │ └── help.md │ │ │ │ ├── starts_with │ │ │ │ │ └── help.md │ │ │ │ └── last_indexof │ │ │ │ │ └── help.md │ │ │ ├── hash │ │ │ │ ├── sha256sum │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── script.ds │ │ │ │ │ └── help.md │ │ │ │ ├── sha512sum │ │ │ │ │ ├── mod_test.rs │ │ │ │ │ ├── script.ds │ │ │ │ │ └── help.md │ │ │ │ └── mod.rs │ │ │ ├── noop │ │ │ │ ├── help.md │ │ │ │ └── mod_test.rs │ │ │ ├── process │ │ │ │ ├── process_id │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── exit │ │ │ │ │ └── help.md │ │ │ │ ├── spawn │ │ │ │ │ └── help.md │ │ │ │ └── mod.rs │ │ │ ├── debug │ │ │ │ ├── duckscript_sdk_version │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── duckscript_version │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── dump_state │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── dump_instructions │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ └── dump_variables │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ ├── man │ │ │ │ └── help.md │ │ │ ├── is_command_defined │ │ │ │ └── help.md │ │ │ ├── lib │ │ │ │ ├── command │ │ │ │ │ ├── remove │ │ │ │ │ │ └── help.md │ │ │ │ │ └── mod.rs │ │ │ │ ├── mod.rs │ │ │ │ └── alias │ │ │ │ │ ├── mod.rs │ │ │ │ │ └── unset │ │ │ │ │ └── help.md │ │ │ ├── flowcontrol │ │ │ │ ├── end │ │ │ │ │ └── mod_test.rs │ │ │ │ └── goto │ │ │ │ │ └── help.md │ │ │ ├── time │ │ │ │ ├── current_time │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ └── mod.rs │ │ │ ├── math │ │ │ │ ├── less_than │ │ │ │ │ └── help.md │ │ │ │ ├── greater_than │ │ │ │ │ └── help.md │ │ │ │ ├── hex_encode │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── hex_decode │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ └── calc │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ ├── on_error │ │ │ │ ├── trigger_error │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── get_last_error │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── get_last_error_line │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── set_error │ │ │ │ │ └── help.md │ │ │ │ └── get_last_error_source │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ ├── thread │ │ │ │ ├── mod.rs │ │ │ │ └── sleep │ │ │ │ │ └── help.md │ │ │ ├── random │ │ │ │ ├── text │ │ │ │ │ └── help.md │ │ │ │ ├── range │ │ │ │ │ └── help.md │ │ │ │ └── mod.rs │ │ │ ├── eval │ │ │ │ └── help.md │ │ │ ├── semver │ │ │ │ ├── is_equal │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ │ ├── mod.rs │ │ │ │ └── is_newer │ │ │ │ │ ├── help.md │ │ │ │ │ └── mod_test.rs │ │ │ ├── echo │ │ │ │ ├── help.md │ │ │ │ └── mod_test.rs │ │ │ ├── scope │ │ │ │ ├── mod.rs │ │ │ │ └── push_stack │ │ │ │ │ └── help.md │ │ │ ├── print │ │ │ │ └── mod_test.rs │ │ │ └── println │ │ │ │ └── mod_test.rs │ │ ├── internal │ │ │ ├── sdkdocs │ │ │ │ ├── footer.md │ │ │ │ ├── help.md │ │ │ │ └── mod_test.rs │ │ │ └── mod.rs │ │ └── mod.rs │ └── utils │ │ ├── mod.rs │ │ ├── pckg.rs │ │ ├── pckg_test.rs │ │ └── annotation.rs └── README.md ├── .rusty-hook.toml ├── test ├── std │ ├── math │ │ ├── calc_test.ds │ │ ├── hex_encode_test.ds │ │ ├── hex_decode_test.ds │ │ ├── less_than_test.ds │ │ └── greater_than_test.ds │ ├── string │ │ ├── lowercase_test.ds │ │ ├── uppercase_test.ds │ │ ├── bytes_test.ds │ │ ├── camelcase_test.ds │ │ ├── kebabcase_test.ds │ │ ├── snakecase_test.ds │ │ ├── is_empty_test.ds │ │ ├── length_test.ds │ │ ├── indexof_test.ds │ │ ├── last_indexof_test.ds │ │ ├── replace_test.ds │ │ ├── base64_encode_test.ds │ │ ├── trim_test.ds │ │ ├── trim_end_test.ds │ │ ├── trim_start_test.ds │ │ ├── base64_decode_test.ds │ │ ├── contains_test.ds │ │ ├── equals_test.ds │ │ ├── ends_with_test.ds │ │ └── starts_with_test.ds │ ├── env │ │ ├── cpu_count_test.ds │ │ ├── print_env_test.ds │ │ ├── which_test.ds │ │ ├── get_home_dir_test.ds │ │ ├── env_to_map_test.ds │ │ └── uname_test.ds │ ├── process │ │ ├── spawn_test.ds │ │ └── process_id_test.ds │ ├── time │ │ └── current_time_test.ds │ ├── debug │ │ ├── duckscript_version_test.ds │ │ ├── duckscript_sdk_version_test.ds │ │ └── dump_test.ds │ ├── flowcontrol │ │ └── goto_test.ds │ ├── on_error │ │ ├── set_error_test.ds │ │ └── trigger_error_test.ds │ ├── semver │ │ └── semver_parse_test.ds │ ├── random │ │ ├── random_range_test.ds │ │ └── random_text_test.ds │ ├── fs │ │ ├── basename_test.ds │ │ ├── temp_dir_test.ds │ │ ├── join_path_test.ds │ │ ├── dirname_test.ds │ │ ├── temp_file_test.ds │ │ ├── is_file_test.ds │ │ ├── is_directory_test.ds │ │ ├── exists_test.ds │ │ ├── get_file_size_test.ds │ │ ├── is_readonly_test.ds │ │ ├── get_last_modified_time_test.ds │ │ ├── is_path_newer_test.ds │ │ └── chmod_test.ds │ ├── collections │ │ ├── map_test.ds │ │ ├── map_keys_test.ds │ │ ├── is_array_test.ds │ │ ├── is_map_test.ds │ │ ├── is_set_test.ds │ │ ├── set_put_test.ds │ │ ├── read_properties_test.ds │ │ ├── array_remove_test.ds │ │ ├── set_clear_test.ds │ │ ├── array_test.ds │ │ ├── range_test.ds │ │ ├── set_from_array_test.ds │ │ ├── array_clear_test.ds │ │ ├── map_clear_test.ds │ │ ├── array_is_empty_test.ds │ │ ├── map_remove_test.ds │ │ └── set_remove_test.ds │ ├── noop_test.ds │ ├── hash │ │ ├── sha256sum_test.ds │ │ └── sha512sum_test.ds │ ├── is_command_defined_test.ds │ ├── net │ │ ├── ftp │ │ │ ├── ftp_get_in_memory_test.ds │ │ │ ├── ftp_put_in_memory_test.ds │ │ │ ├── ftp_get_test.ds │ │ │ └── ftp_put_test.ds │ │ └── wget_test.ds │ └── var │ │ ├── set_by_name_test.ds │ │ ├── get_by_name_test.ds │ │ └── get_all_var_names_test.ds └── helper.ds ├── .gitignore ├── duckscript_cli ├── README.md └── src │ └── help.txt ├── .github ├── dependabot.yml └── ISSUE_TEMPLATE │ ├── feature_request.md │ └── bug_report.md ├── Cargo.toml └── .editorconfig /.buildnumber: -------------------------------------------------------------------------------- 1 | 15 -------------------------------------------------------------------------------- /examples/man.ds: -------------------------------------------------------------------------------- 1 | 2 | man set 3 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | --- 2 | --- 3 | {% include main.html %} -------------------------------------------------------------------------------- /duckscript/src/test/scripts/crash.ds: -------------------------------------------------------------------------------- 1 | 2 | crash 3 | -------------------------------------------------------------------------------- /duckscript/src/test/scripts/echo.ds: -------------------------------------------------------------------------------- 1 | 2 | echo ${value} 3 | -------------------------------------------------------------------------------- /examples/store_output.ds: -------------------------------------------------------------------------------- 1 | 2 | out = set "hello world" 3 | -------------------------------------------------------------------------------- /duckscript/src/test/scripts/print_preprocessor.ds: -------------------------------------------------------------------------------- 1 | !print test -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf 2 | *.ico binary 3 | *.woff binary 4 | -------------------------------------------------------------------------------- /duckscript/src/test/scripts/include_file.ds: -------------------------------------------------------------------------------- 1 | !include_files ./simple.ds -------------------------------------------------------------------------------- /duckscript/src/test/scripts/set.ds: -------------------------------------------------------------------------------- 1 | 2 | value = set "hello world" 3 | -------------------------------------------------------------------------------- /docs/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gem 'github-pages', group: :jekyll_plugins -------------------------------------------------------------------------------- /duckscript_sdk/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod command; 2 | pub(crate) mod scope; 3 | -------------------------------------------------------------------------------- /examples/hello_world.ds: -------------------------------------------------------------------------------- 1 | 2 | # print the text "hello world" 3 | echo hello world 4 | -------------------------------------------------------------------------------- /.rusty-hook.toml: -------------------------------------------------------------------------------- 1 | [hooks] 2 | pre-push = "cargo make --no-workspace workspace-ci-flow" 3 | -------------------------------------------------------------------------------- /docs/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sagiegurari/duckscript/master/docs/favicon.ico -------------------------------------------------------------------------------- /examples/single_argument.ds: -------------------------------------------------------------------------------- 1 | 2 | # print the text "hello world" 3 | echo "hello world" 4 | -------------------------------------------------------------------------------- /duckscript/src/test/scripts/simple_runnable.ds: -------------------------------------------------------------------------------- 1 | !include_files ./set.ds 2 | !include_files ./echo.ds -------------------------------------------------------------------------------- /examples/goto_label.ds: -------------------------------------------------------------------------------- 1 | 2 | goto :good 3 | 4 | echo error!!!! 5 | 6 | :good echo yay!!!! 7 | -------------------------------------------------------------------------------- /examples/comment.ds: -------------------------------------------------------------------------------- 1 | 2 | # This is just a comment 3 | 4 | echo This will print # But this will not 5 | -------------------------------------------------------------------------------- /examples/single_argument_with_escape.ds: -------------------------------------------------------------------------------- 1 | 2 | # print the text 'hello "world"' 3 | echo "hello \"world\"" 4 | -------------------------------------------------------------------------------- /duckscript/src/test/scripts/multiple_commands.ds: -------------------------------------------------------------------------------- 1 | toml = cat ./Cargo.toml 2 | 3 | echo "The output is:" 4 | echo ${toml} 5 | -------------------------------------------------------------------------------- /test/std/math/calc_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_calc 3 | result = calc 1 + 5 * 7 4 | 5 | assert_eq ${result} 36 6 | end 7 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/is_windows/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::is_windows::os = os_family 3 | equals ${scope::is_windows::os} windows 4 | -------------------------------------------------------------------------------- /examples/on_error_2.ds: -------------------------------------------------------------------------------- 1 | 2 | created = alias on_error echo 3 | 4 | echo Going to cause an error 5 | assert_error 6 | 7 | echo End 8 | -------------------------------------------------------------------------------- /test/std/math/hex_encode_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_hex_encode 3 | result = hex_encode 255 4 | 5 | assert_eq ${result} 0xff 6 | end 7 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .c9 3 | /target 4 | temp/ 5 | **/*.rs.bk 6 | **/*.log 7 | dump.rdb 8 | /rs*.sh 9 | /docs/_site 10 | /core 11 | target/ 12 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/unset/script.ds: -------------------------------------------------------------------------------- 1 | 2 | for scope::unset::name in ${scope::unset::arguments} 3 | set_by_name ${scope::unset::name} 4 | end 5 | -------------------------------------------------------------------------------- /test/std/string/lowercase_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_conversion 3 | output = lowercase "Hello World" 4 | 5 | assert_eq ${output} "hello world" 6 | end 7 | -------------------------------------------------------------------------------- /test/std/string/uppercase_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_conversion 3 | output = uppercase "Hello World" 4 | 5 | assert_eq ${output} "HELLO WORLD" 6 | end 7 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman 2 | title: duckscript 3 | description: Simple, extendable and embeddable scripting language. 4 | show_downloads: false -------------------------------------------------------------------------------- /test/std/env/cpu_count_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_cpu_count 3 | value = cpu_count 4 | valid = greater_than ${value} 0 5 | 6 | assert ${valid} 7 | end 8 | -------------------------------------------------------------------------------- /duckscript/src/lib_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | #[test] 4 | fn version_test() { 5 | let version = version(); 6 | 7 | assert!(!version.is_empty()); 8 | } 9 | -------------------------------------------------------------------------------- /duckscript/README.md: -------------------------------------------------------------------------------- 1 | # duckscript 2 | 3 | > Simple, extendable and embeddable scripting language. 4 | 5 | See [full readme](https://github.com/sagiegurari/duckscript) 6 | -------------------------------------------------------------------------------- /test/helper.ds: -------------------------------------------------------------------------------- 1 | 2 | fn skip_unstable 3 | value = get_env CARGO_MAKE_DUCKSCRIPT_SKIP_UNSTABLE_TESTS 4 | skip = eq ${value} true 5 | return ${skip} 6 | end 7 | -------------------------------------------------------------------------------- /duckscript_cli/README.md: -------------------------------------------------------------------------------- 1 | # duckscript 2 | 3 | > Simple, extendable and embeddable scripting language. 4 | 5 | See [full readme](https://github.com/sagiegurari/duckscript) 6 | -------------------------------------------------------------------------------- /duckscript_sdk/README.md: -------------------------------------------------------------------------------- 1 | # duckscript 2 | 3 | > Simple, extendable and embeddable scripting language. 4 | 5 | See [full readme](https://github.com/sagiegurari/duckscript) 6 | -------------------------------------------------------------------------------- /test/std/process/spawn_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_echo 3 | output = spawn echo hello world 4 | 5 | empty = is_empty ${output} 6 | 7 | assert_false ${empty} 8 | end 9 | -------------------------------------------------------------------------------- /test/std/time/current_time_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_current_time 3 | value = current_time 4 | 5 | result = greater_than ${value} 0 6 | 7 | assert ${result} 8 | end 9 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_is_empty/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::map_is_empty::length = map_size ${scope::map_is_empty::argument::1} 3 | equals 0 ${scope::map_is_empty::length} 4 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_is_empty/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::set_is_empty::length = set_size ${scope::set_is_empty::argument::1} 3 | equals 0 ${scope::set_is_empty::length} 4 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/read/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | -------------------------------------------------------------------------------- /test/std/debug/duckscript_version_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_duckscript_version 3 | version = duckscript_version 4 | empty = is_empty version 5 | 6 | assert_false ${empty} 7 | end 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/json/encode/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | -------------------------------------------------------------------------------- /test/std/flowcontrol/goto_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_goto_with_valid_label 3 | goto :test_goto_with_valid_label 4 | 5 | assert_fail 6 | 7 | :test_goto_with_valid_label 8 | end 9 | -------------------------------------------------------------------------------- /test/std/process/process_id_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_process_id 3 | id = pid 4 | 5 | empty = is_empty {id} 6 | 7 | assert_false ${empty} 8 | assert ${id} 9 | end 10 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: cargo 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: '03:00' 8 | open-pull-requests-limit: 99 9 | -------------------------------------------------------------------------------- /docs/_includes/main.html: -------------------------------------------------------------------------------- 1 |
2 | 3 |
{% include content.md %}
4 |
-------------------------------------------------------------------------------- /duckscript/src/test/scripts/simple.ds: -------------------------------------------------------------------------------- 1 | 2 | !print test pre process line 3 | 4 | :label_test variable_test = command_test arg1 arg2 " arg3 arg3 arg3 " #some comment 5 | 6 | #comment 7 | !print test -------------------------------------------------------------------------------- /duckscript/src/types/mod.rs: -------------------------------------------------------------------------------- 1 | //! # types 2 | //! 3 | //! All duckscript types. 4 | //! 5 | pub mod command; 6 | pub mod env; 7 | pub mod error; 8 | pub mod instruction; 9 | pub mod runtime; 10 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_is_empty/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::array_is_empty::length = array_length ${scope::array_is_empty::argument::1} 3 | equals 0 ${scope::array_is_empty::length} 4 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/wget/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/test_file/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | -------------------------------------------------------------------------------- /examples/user_input.ds: -------------------------------------------------------------------------------- 1 | 2 | echo Enter Full Name: 3 | name = read 4 | 5 | if is_empty ${name} 6 | echo You didn't enter any value 7 | else 8 | echo Your name is: ${name} 9 | end 10 | -------------------------------------------------------------------------------- /test/std/debug/duckscript_sdk_version_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_duckscript_sdk_version 3 | version = duckscript_sdk_version 4 | empty = is_empty version 5 | 6 | assert_false ${empty} 7 | end 8 | -------------------------------------------------------------------------------- /test/std/on_error/set_error_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_set_error 3 | set_error "my error message" 4 | 5 | error = get_last_error 6 | 7 | assert_eq ${error} "my error message" 8 | end 9 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/print_env/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/uname/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/cp_glob/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/join_path/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/base64/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/concat/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/test_directory/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/get_all_var_names/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/unset/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/unset_all_vars/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/is_windows/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/set_mode_glob/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/sha256sum/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/sha512sum/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_join/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/sha256sum/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::sha256sum::output = digest --algo sha256 --file ${scope::sha256sum::argument::1} 3 | scope::sha256sum::output = lowercase ${scope::sha256sum::output} 4 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/sha512sum/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::sha512sum::output = digest --algo sha512 --file ${scope::sha512sum::argument::1} 3 | scope::sha512sum::output = lowercase ${scope::sha512sum::output} 4 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/internal/sdkdocs/footer.md: -------------------------------------------------------------------------------- 1 | 2 | ### License 3 | Developed by Sagie Gur-Ari and licensed under the 4 | [Apache 2](https://github.com/sagiegurari/duckscript/blob/master/LICENSE) open source license. 5 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_concat/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_contains/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_contains_key/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_is_empty/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_from_array/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_is_empty/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /examples/print.ds: -------------------------------------------------------------------------------- 1 | 2 | # this will print "hello world during script execution" 3 | echo hello world during script execution 4 | 5 | # this will print "hello world during parsing" 6 | !print hello world during parsing 7 | -------------------------------------------------------------------------------- /test/std/env/print_env_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_print_env 3 | set_env TEST_PRINT_ENV TRUE 4 | 5 | text = printenv 6 | 7 | valid = contains ${text} TEST_PRINT_ENV=TRUE 8 | assert ${valid} 9 | end 10 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [workspace] 2 | members = ["duckscript", "duckscript_sdk", "duckscript_cli"] 3 | resolver = "2" 4 | 5 | [profile.release] 6 | opt-level = "z" 7 | lto = true 8 | codegen-units = 1 9 | panic = "abort" 10 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_contains_value/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("").unwrap()); 7 | } 8 | -------------------------------------------------------------------------------- /examples/include_files.ds: -------------------------------------------------------------------------------- 1 | 2 | # load the hello_world.ds script here 3 | !include_files ./hello_world.ds 4 | 5 | # load 2 scripts here. The hello_world.ds is loaded again. 6 | !include_files ./hello_world.ds ./use_variable.ds 7 | -------------------------------------------------------------------------------- /test/std/semver/semver_parse_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_valid 3 | version = semver_parse 1.2.3 4 | 5 | assert_eq ${version.major} 1 6 | assert_eq ${version.minor} 2 7 | assert_eq ${version.patch} 3 8 | end 9 | 10 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_contains_key/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::map_contains_key::value = map_get ${scope::map_contains_key::argument::1} ${scope::map_contains_key::argument::2} 3 | is_defined scope::map_contains_key::value 4 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | 2 | root = true 3 | 4 | [*] 5 | charset = utf-8 6 | end_of_line = lf 7 | insert_final_newline = true 8 | trim_trailing_whitespace = true 9 | indent_style = space 10 | indent_size = 4 11 | 12 | [*.json] 13 | indent_size = 2 14 | -------------------------------------------------------------------------------- /test/std/string/bytes_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_binary_string 3 | handle = string_to_bytes "hello world" 4 | text = bytes_to_string ${handle} 5 | 6 | release ${handle} 7 | 8 | assert_eq ${text} "hello world" 9 | end 10 | -------------------------------------------------------------------------------- /docs/api.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /test/std/math/hex_decode_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_hex_decode 3 | result = hex_decode 0xff 4 | 5 | assert_eq ${result} 255 6 | end 7 | 8 | fn test_hex_decode_no_prefix 9 | result = hex_decode ff 10 | 11 | assert_eq ${result} 255 12 | end 13 | -------------------------------------------------------------------------------- /test/std/random/random_range_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_valid 3 | value = random_range -10 10 4 | 5 | in_min = greater_than ${value} -11 6 | in_max = greater_than 10 ${value} 7 | 8 | assert ${in_min} 9 | assert ${in_max} 10 | end 11 | 12 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/print_env/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::print_env::map = env_to_map 3 | scope::print_env::text = map_to_properties ${scope::print_env::map} 4 | release ${scope::print_env::map} 5 | 6 | echo ${scope::print_env::text} 7 | set ${scope::print_env::text} 8 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/concat/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::concat::output = set "" 3 | for scope::concat::arg in ${scope::concat::arguments} 4 | scope::concat::output = set "${scope::concat::output}${scope::concat::arg}" 5 | end 6 | 7 | set ${scope::concat::output} 8 | -------------------------------------------------------------------------------- /test/std/fs/basename_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_relative_path 3 | value = basename ./test.txt 4 | 5 | assert_eq ${value} test.txt 6 | end 7 | 8 | fn test_full_path 9 | value = basename /dir/dir/test.txt 10 | 11 | assert_eq ${value} test.txt 12 | end 13 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/os_name/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = os_name 3 | ``` 4 | 5 | Returns the OS name. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The OS name. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | name = os_name 19 | ``` 20 | -------------------------------------------------------------------------------- /examples/alias.ds: -------------------------------------------------------------------------------- 1 | 2 | alias my_echo echo [ECHO] 3 | 4 | # This will print "[ECHO] hello world " 5 | my_echo hello world 6 | 7 | unalias my_echo 8 | 9 | # This will error 10 | echo The script will now error as my_echo is no longer defined 11 | my_echo hello world 12 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/hostname/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = hostname 3 | ``` 4 | 5 | Returns the hostname. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The hostname 14 | 15 | ### Examples 16 | 17 | ```sh 18 | name = hostname 19 | ``` 20 | -------------------------------------------------------------------------------- /test/std/fs/temp_dir_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_simple 3 | file = temp_file 4 | directory = temp_dir 5 | dir_exists = is_directory ${directory} 6 | 7 | valid = starts_with ${file} ${directory} 8 | 9 | assert ${valid} 10 | assert ${dir_exists} 11 | end 12 | 13 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/cpu_count/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = cpu_count 3 | ``` 4 | 5 | Returns the number of CPUs. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The CPU count. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | count = cpu_count 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_cli/src/help.txt: -------------------------------------------------------------------------------- 1 | USAGE: 2 | duck [FLAGS] [FILE] 3 | 4 | FLAGS: 5 | -h, --help Prints help information 6 | -e, --eval Evaluate script 7 | -l, --lint Lints the provided file 8 | 9 | ARGS: 10 | The script file to execute/lint 11 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/noop/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | noop 3 | ``` 4 | 5 | Empty function that does nothing and returns none. 6 | 7 | ### Parameters 8 | 9 | All parameters are ignored 10 | 11 | ### Return Value 12 | 13 | None 14 | 15 | ### Examples 16 | 17 | ```sh 18 | noop 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/process/process_id/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = pid 3 | ``` 4 | 5 | Returns the current process ID. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The current process ID. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | id = pid 19 | ``` 20 | -------------------------------------------------------------------------------- /examples/exec.ds: -------------------------------------------------------------------------------- 1 | 2 | exec echo hello world 3 | 4 | output = exec echo hello world 5 | 6 | stdout = set ${output.stdout} 7 | stderr = set ${output.stderr} 8 | exit_code = set ${output.code} 9 | 10 | echo stdout: ${stdout} 11 | echo stderr: ${stderr} 12 | echo exit code: ${exit_code} 13 | -------------------------------------------------------------------------------- /examples/functions.ds: -------------------------------------------------------------------------------- 1 | 2 | function print_first_and_second_argument 3 | echo ${1} ${2} 4 | return printed 5 | end 6 | 7 | function run_flow 8 | status = print_first_and_second_argument hello world 9 | echo The printout status is: ${status} 10 | end 11 | 12 | run_flow 13 | -------------------------------------------------------------------------------- /test/std/collections/map_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_put_get 3 | handle = map 4 | 5 | result = map_put ${handle} key value 6 | assert_eq ${result} true 7 | 8 | value = map_get ${handle} key 9 | assert_eq ${value} value 10 | 11 | release ${handle} 12 | end 13 | -------------------------------------------------------------------------------- /test/std/env/which_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_found 3 | path = which rustc 4 | valid = is_empty ${path} 5 | 6 | assert_false ${valid} 7 | end 8 | 9 | fn test_not_found 10 | path = which bad_executable 11 | valid = is_empty ${path} 12 | 13 | assert ${valid} 14 | end 15 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/get_user_name/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = whoami 3 | ``` 4 | 5 | Returns the current user name. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The current user name. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | name = whoami 19 | ``` 20 | -------------------------------------------------------------------------------- /examples/binding.ds: -------------------------------------------------------------------------------- 1 | 2 | out = set "Hello World" 3 | 4 | list = array ${out} 5 | for entry in ${list} 6 | echo current entry is: ${entry} 7 | end 8 | release list 9 | 10 | list = array %{out} 11 | for entry in ${list} 12 | echo current entry is: ${entry} 13 | end 14 | release list 15 | -------------------------------------------------------------------------------- /examples/use_variable.ds: -------------------------------------------------------------------------------- 1 | 2 | out = set "hello world" 3 | 4 | # This will print: "The out variable holds the value: hello world" 5 | echo The out variable holds the value: ${out} 6 | 7 | # This will print: "To use the out variable just write: ${out}" 8 | echo To use the out variable just write: \${out} 9 | -------------------------------------------------------------------------------- /duckscript_sdk/src/utils/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod annotation; 2 | pub(crate) mod condition; 3 | pub(crate) mod eval; 4 | pub(crate) mod exec; 5 | pub(crate) mod flags; 6 | pub(crate) mod instruction_query; 7 | pub(crate) mod io; 8 | pub(crate) mod pckg; 9 | pub(crate) mod scope; 10 | pub(crate) mod state; 11 | -------------------------------------------------------------------------------- /test/std/fs/join_path_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_single 3 | joined = join_path /test 4 | 5 | assert_eq ${joined} /test 6 | end 7 | 8 | fn test_multiple 9 | joined = join_path /test /dir1 /dir2 dir3 //dir4// /dir5 10 | 11 | assert_eq ${joined} /test/dir1/dir2/dir3/dir4/dir5 12 | end 13 | 14 | -------------------------------------------------------------------------------- /test/std/noop_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_no_args 3 | value = noop 4 | 5 | defined = is_defined value 6 | 7 | assert_false ${value} 8 | end 9 | 10 | fn test_multiple_args 11 | value = noop 1 2 3 4 12 | 13 | defined = is_defined value 14 | 15 | assert_false ${value} 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/std/hash/sha256sum_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_sha256sum 3 | file = set ./target/_duckscript_test/hash/sha256sum.txt 4 | writefile ${file} "hello world\n" 5 | hashed = sha256sum ${file} 6 | 7 | assert_eq ${hashed} a948904f2f0f479b8f8197694b30184b0d2ed1c1cd2a1ec0fb85d299a192a447 8 | end 9 | 10 | -------------------------------------------------------------------------------- /test/std/string/camelcase_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_without_symbols 3 | output = camelcase "Hello world 22" 4 | 5 | assert_eq ${output} "HelloWorld22" 6 | end 7 | 8 | fn test_with_symbols 9 | output = camelcase "Hello!@#$% world^&*()[]{}22" 10 | 11 | assert_eq ${output} "HelloWorld22" 12 | end 13 | -------------------------------------------------------------------------------- /test/std/random/random_text_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_no_length 3 | value = random_text 4 | 5 | len = strlen ${value} 6 | 7 | assert_eq ${len} 1 8 | end 9 | 10 | fn test_with_length 11 | value = random_text 50 12 | 13 | len = strlen ${value} 14 | 15 | assert_eq ${len} 50 16 | end 17 | 18 | -------------------------------------------------------------------------------- /test/std/string/kebabcase_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_without_symbols 3 | output = kebabcase "Hello World 22" 4 | 5 | assert_eq ${output} "hello-world-22" 6 | end 7 | 8 | fn test_with_symbols 9 | output = kebabcase "hello!@#$% world^&*()[]{}22" 10 | 11 | assert_eq ${output} "hello-world-22" 12 | end 13 | -------------------------------------------------------------------------------- /test/std/string/snakecase_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_without_symbols 3 | output = snakecase "Hello world 22" 4 | 5 | assert_eq ${output} "hello_world_22" 6 | end 7 | 8 | fn test_with_symbols 9 | output = snakecase "Hello!@#$% world^&*()[]{}22" 10 | 11 | assert_eq ${output} "hello_world_22" 12 | end 13 | -------------------------------------------------------------------------------- /examples/array.ds: -------------------------------------------------------------------------------- 1 | 2 | handle = array a b c "d e" 3 | len = array_length ${handle} 4 | released = release ${handle} 5 | echo Array length: ${len} released: ${released} 6 | 7 | handle = range 0 10 8 | len = array_length ${handle} 9 | released = release ${handle} 10 | echo Array length: ${len} released: ${released} 11 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/os_family/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = os_family 3 | ``` 4 | 5 | Returns the OS family (windows, linux, mac). 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The OS family (windows, linux, mac). 14 | 15 | ### Examples 16 | 17 | ```sh 18 | name = os_family 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/ftp/get/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = ftp_get", "out"); 12 | } 13 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/ftp/put/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = ftp_put", "out"); 12 | } 13 | -------------------------------------------------------------------------------- /test/std/fs/dirname_test.ds: -------------------------------------------------------------------------------- 1 | 2 | windows = is_windows 3 | 4 | fn test_relative_path 5 | value = dirname ./test.txt 6 | 7 | assert_eq ${value} . 8 | end 9 | 10 | fn test_full_path 11 | if not ${windows} 12 | value = dirname /dir/test.txt 13 | 14 | assert_eq ${value} /dir 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /test/std/fs/temp_file_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_no_extension 3 | file = temp_file 4 | 5 | valid = ends_with ${file} .tmp 6 | 7 | assert ${valid} 8 | end 9 | 10 | fn test_with_extension 11 | file = temp_file txt 12 | 13 | valid = ends_with ${file} .txt 14 | 15 | assert ${valid} 16 | end 17 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/length/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = length text 3 | ``` 4 | 5 | Returns the text length. 6 | 7 | ### Parameters 8 | 9 | The text to extract the length from. 10 | 11 | ### Return Value 12 | 13 | The text length value. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | len = length "Hello World" 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/is_windows/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_windows 3 | ``` 4 | 5 | Returns true if the current OS family is windows. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | True if the current OS family is windows. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | windows = is_windows 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/mod.rs: -------------------------------------------------------------------------------- 1 | mod internal; 2 | pub(crate) mod std; 3 | 4 | use duckscript::types::command::Commands; 5 | use duckscript::types::error::ScriptError; 6 | 7 | pub(crate) fn load(commands: &mut Commands) -> Result<(), ScriptError> { 8 | internal::load(commands)?; 9 | std::load(commands)?; 10 | 11 | Ok(()) 12 | } 13 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/os_release/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = os_release 3 | ``` 4 | 5 | Returns the OS release.
6 | **This command is not supported on windows.** 7 | 8 | ### Parameters 9 | 10 | None 11 | 12 | ### Return Value 13 | 14 | The OS release. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | release = os_release 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/os_version/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = os_version 3 | ``` 4 | 5 | Returns the OS version.
6 | **This command is not supported on windows.** 7 | 8 | ### Parameters 9 | 10 | None 11 | 12 | ### Return Value 13 | 14 | The OS version. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | version = os_version 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/unset/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | unset_env key 3 | ``` 4 | 5 | Removes the environment variable defined by the provided key. 6 | 7 | ### Parameters 8 | 9 | The name of the environment variable to remove 10 | 11 | ### Return Value 12 | 13 | None 14 | 15 | ### Examples 16 | 17 | ```sh 18 | unset_env HOME 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/temp_dir/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | path = temp_dir 3 | ``` 4 | 5 | This command will return the system temporary directory path. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The directory path. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | path = temp_dir 19 | 20 | echo ${path} 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/ftp/get_in_memory/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = ftp_get_in_memory", "out"); 12 | } 13 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/ftp/put_in_memory/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = ftp_put_in_memory", "out"); 12 | } 13 | -------------------------------------------------------------------------------- /test/std/fs/is_file_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_file 3 | value = is_file ./Cargo.toml 4 | 5 | assert ${value} 6 | end 7 | 8 | fn test_not_file 9 | value = is_file ./test 10 | 11 | assert_false ${value} 12 | end 13 | 14 | fn test_not_found 15 | value = is_file ./badpath 16 | 17 | assert_false ${value} 18 | end 19 | -------------------------------------------------------------------------------- /test/std/math/less_than_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_equals 3 | result = less_than 1 1 4 | 5 | assert_false ${result} 6 | end 7 | 8 | fn test_less_than 9 | result = less_than 1 1.5 10 | 11 | assert ${result} 12 | end 13 | 14 | fn test_greater_than 15 | result = less_than 2 1.5 16 | 17 | assert_false ${result} 18 | end 19 | -------------------------------------------------------------------------------- /test/std/string/is_empty_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_empty 3 | output = is_empty "" 4 | 5 | assert ${output} 6 | end 7 | 8 | fn test_not_empty 9 | output = is_empty "test" 10 | 11 | assert_false ${output} 12 | end 13 | 14 | fn test_undefined 15 | output = is_empty ${test_undefined} 16 | 17 | assert ${output} 18 | end 19 | -------------------------------------------------------------------------------- /test/std/string/length_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_empty 3 | output = length "" 4 | 5 | assert_eq ${output} 0 6 | end 7 | 8 | fn test_not_empty 9 | output = length "test" 10 | 11 | assert_eq ${output} 4 12 | end 13 | 14 | fn test_undefined 15 | output = length ${test_undefined} 16 | 17 | assert_eq ${output} 0 18 | end 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/duckscript_sdk_version/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = duckscript_sdk_version 3 | ``` 4 | 5 | Returns the duckscript SDK version. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The duckscript SDK version. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | version = duckscript_sdk_version 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/duckscript_version/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = duckscript_version 3 | ``` 4 | 5 | Returns the duckscript runtime version. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The duckscript runtime version. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | version = duckscript_version 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/man/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = man command 3 | ``` 4 | 5 | Prints and returns the help documentation of the provided command. 6 | 7 | ### Parameters 8 | 9 | The command name. 10 | 11 | ### Return Value 12 | 13 | The help documentation or if not found, none. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | man set 19 | ``` 20 | -------------------------------------------------------------------------------- /test/std/env/get_home_dir_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_get 3 | windows = is_windows 4 | 5 | if not ${windows} 6 | directory = get_home_dir 7 | empty = is_empty ${directory} 8 | not_false = not equals false ${directory} 9 | 10 | assert_false ${empty} 11 | assert ${not_false} 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/std/fs/is_directory_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_directory 3 | value = is_dir ./target 4 | 5 | assert ${value} 6 | end 7 | 8 | fn test_not_directory 9 | value = is_dir ./Cargo.toml 10 | 11 | assert_false ${value} 12 | end 13 | 14 | fn test_not_found 15 | value = is_dir ./badpath 16 | 17 | assert_false ${value} 18 | end 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/internal/mod.rs: -------------------------------------------------------------------------------- 1 | mod sdkdocs; 2 | 3 | use duckscript::types::command::Commands; 4 | use duckscript::types::error::ScriptError; 5 | 6 | static PACKAGE: &str = "internal"; 7 | 8 | pub(crate) fn load(commands: &mut Commands) -> Result<(), ScriptError> { 9 | commands.set(sdkdocs::create(PACKAGE))?; 10 | 11 | Ok(()) 12 | } 13 | -------------------------------------------------------------------------------- /test/std/math/greater_than_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_equals 3 | result = greater_than 1 1 4 | 5 | assert_false ${result} 6 | end 7 | 8 | fn test_less_than 9 | result = greater_than 1 1.5 10 | 11 | assert_false ${result} 12 | end 13 | 14 | fn test_greater_than 15 | result = greater_than 2 1.5 16 | 17 | assert ${result} 18 | end 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/gitignore_path_array/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_pattern_provided() { 11 | test::run_script_and_error(vec![create("")], "out = gitignore_path_array", "out"); 12 | } 13 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/is_command_defined/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_command_defined key 3 | ``` 4 | 5 | Returns true if the provided command name exists. 6 | 7 | ### Parameters 8 | 9 | The command name. 10 | 11 | ### Return Value 12 | 13 | True if the command exists. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | exists = is_command_defined exec 19 | ``` 20 | -------------------------------------------------------------------------------- /test/std/on_error/trigger_error_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_trigger_error_with_message 3 | trigger_error "my error message" 4 | 5 | error = get_last_error 6 | 7 | assert_eq ${error} "my error message" 8 | end 9 | 10 | fn test_trigger_error_no_message 11 | trigger_error 12 | 13 | error = get_last_error 14 | 15 | assert_eq ${error} Error 16 | end 17 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/lib/command/remove/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | remove_command name 3 | ``` 4 | 5 | Removes a command and all its aliases. 6 | 7 | ### Parameters 8 | 9 | The command or alias name to remove. 10 | 11 | ### Return Value 12 | 13 | A true/false value in case a command was removed. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | remove_command set 19 | ``` 20 | -------------------------------------------------------------------------------- /test/std/hash/sha512sum_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_sha512sum 3 | file = set ./target/_duckscript_test/hash/sha512sum.txt 4 | writefile ${file} "hello world\n" 5 | hashed = sha512sum ${file} 6 | 7 | assert_eq ${hashed} db3974a97f2407b7cae1ae637c0030687a11913274d578492558e39c16c017de84eacdc8c62fe34ee4e12b4b1428817f09b6a2760c3f8a664ceae94d2434a593 8 | end 9 | 10 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/get_env/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_env key 3 | ``` 4 | 5 | Returns the environment variable value for the provided key. 6 | 7 | ### Parameters 8 | 9 | First argument is the environment variable key. 10 | 11 | ### Return Value 12 | 13 | The environment variable value. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | home = get_env HOME 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/flowcontrol/end/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create()); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate(vec![create()], "out = end", CommandValidation::None); 13 | } 14 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/time/current_time/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = current_time 3 | ``` 4 | 5 | Returns the current time in milliseconds (from January 1, 1970 UTC). 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The current time in milliseconds. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | result = current_time 19 | echo ${result} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/os_name/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | test::run_script_and_validate(vec![create("")], "out = os_name", CommandValidation::Ignore); 13 | } 14 | -------------------------------------------------------------------------------- /duckscript_sdk/src/utils/pckg.rs: -------------------------------------------------------------------------------- 1 | #[cfg(test)] 2 | #[path = "./pckg_test.rs"] 3 | mod pckg_test; 4 | 5 | pub(crate) fn concat(parent: &str, current: &str) -> String { 6 | let mut package = String::from(parent); 7 | if !parent.is_empty() && !current.is_empty() { 8 | package.push_str("::"); 9 | } 10 | package.push_str(current); 11 | 12 | package 13 | } 14 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/uname/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = uname [-a] 3 | ``` 4 | 5 | Acts similar to uname on unix like systems. 6 | 7 | ### Parameters 8 | 9 | * Optional -a for extended information (not supported on windows). 10 | 11 | ### Return Value 12 | 13 | The OS name and optionally extra information. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | value = uname -a 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/temp_file/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | path = temp_file [extension] 3 | ``` 4 | 5 | This command will create a new empty temporary file and return its path. 6 | 7 | ### Parameters 8 | 9 | Optional file extension. 10 | 11 | ### Return Value 12 | 13 | The file path. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | path = temp_file toml 19 | 20 | echo ${path} 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript/src/preprocessor/print_preprocessor.rs: -------------------------------------------------------------------------------- 1 | //! # print_preprocessor 2 | //! 3 | //! The print pre processor implementation. 4 | //! 5 | 6 | pub(crate) fn run(arguments: &Option>) { 7 | if let Some(arguments_vec) = arguments { 8 | for argument in arguments_vec { 9 | print!("{} ", argument); 10 | } 11 | } 12 | 13 | println!(); 14 | } 15 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/lowercase/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = lowercase text 3 | ``` 4 | 5 | Converts the provided string into lowercase. 6 | 7 | ### Parameters 8 | 9 | The string to convert. 10 | 11 | ### Return Value 12 | 13 | The converted string. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | string = lowercase "Hello World" 19 | assert_eq ${string} "hello world" 20 | ``` 21 | 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/uppercase/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = uppercase text 3 | ``` 4 | 5 | Converts the provided string into uppercase. 6 | 7 | ### Parameters 8 | 9 | The string to convert. 10 | 11 | ### Return Value 12 | 13 | The converted string. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | string = uppercase "Hello World" 19 | assert_eq ${string} "HELLO WORLD" 20 | ``` 21 | 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/is_defined/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_defined key 3 | ``` 4 | 5 | Returns true if the provided variable name (not value) exists. 6 | 7 | ### Parameters 8 | 9 | The variable name. 10 | 11 | ### Return Value 12 | 13 | True if the variable is defined. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | key = set "hello world" 19 | exists = is_defined key 20 | ``` 21 | -------------------------------------------------------------------------------- /test/std/string/indexof_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_not_found 3 | output = indexof "1 2 3 4 5" "4 5 6" 4 | 5 | assert_eq ${output} "" 6 | end 7 | 8 | fn test_prefix 9 | output = indexof "1 2 3 4 5 1 2 3 4 5" "1 2" 10 | 11 | assert_eq ${output} 0 12 | end 13 | 14 | fn test_suffix 15 | output = indexof "1 2 3 4 5 1 2 3 4 5" "4 5" 16 | 17 | assert_eq ${output} 6 18 | end 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/dump_state/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | value = dump_state 3 | ``` 4 | 5 | Returns all script state in textual form. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The script state. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | numbers = range -5 15 19 | 20 | text = dump_instructions 21 | found = contains ${text} -5 22 | assert found 23 | ``` 24 | -------------------------------------------------------------------------------- /test/std/fs/exists_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_file 3 | value = is_path_exists ./Cargo.toml 4 | 5 | assert ${value} 6 | end 7 | 8 | fn test_directory 9 | if not is_windows 10 | value = is_path_exists ./target 11 | 12 | assert ${value} 13 | end 14 | end 15 | 16 | fn test_not_found 17 | value = is_path_exists ./badpath 18 | 19 | assert_false ${value} 20 | end 21 | -------------------------------------------------------------------------------- /test/std/fs/get_file_size_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_file 3 | size = get_file_size ./Cargo.toml 4 | positive = greater_than ${size} 0 5 | 6 | assert ${positive} 7 | end 8 | 9 | fn test_directory 10 | size = get_file_size ./src 11 | 12 | assert_false ${size} 13 | end 14 | 15 | fn test_not_found 16 | size = get_file_size ./badfile 17 | 18 | assert_false ${size} 19 | end 20 | -------------------------------------------------------------------------------- /test/std/collections/map_keys_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_map_keys 3 | handle = map 4 | 5 | result = map_put ${handle} key value 6 | assert_eq ${result} true 7 | 8 | keys = map_keys ${handle} 9 | size = array_length ${keys} 10 | assert_eq ${size} 1 11 | value = array_pop ${keys} 12 | assert_eq ${value} key 13 | 14 | release ${handle} 15 | release ${keys} 16 | end 17 | -------------------------------------------------------------------------------- /test/std/env/env_to_map_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_env_to_map 3 | set_env env_to_map_test1 test_value1 4 | 5 | handle = env_to_map 6 | 7 | set_env env_to_map_test2 test_value2 8 | 9 | value = map_get ${handle} env_to_map_test1 10 | assert_eq ${value} test_value1 11 | value = map_get ${handle} env_to_map_test2 12 | assert_false ${value} 13 | 14 | release ${handle} 15 | end 16 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/get_home_dir/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_home_dir 3 | ``` 4 | 5 | Returns the user home directory path.
6 | In case of any error, false will be returned. 7 | 8 | ### Parameters 9 | 10 | None 11 | 12 | ### Return Value 13 | 14 | The user home directory path or false in case of any error. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | directory = get_home_dir 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/less_than/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = less_than left right 3 | ``` 4 | 5 | This command returns true/false based on left < right calculation. 6 | 7 | ### Parameters 8 | 9 | Two numeric values to compare. 10 | 11 | ### Return Value 12 | 13 | True if first argument is smaller than second argument. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | result = less_than 1 1.5 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/flowcontrol/goto/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | goto :label 3 | ``` 4 | 5 | The goto command enables you to jump to any position in the script, if that position has a label value. 6 | 7 | ### Parameters 8 | 9 | A single valid label value. 10 | 11 | ### Return Value 12 | 13 | None 14 | 15 | ### Examples 16 | 17 | ```sh 18 | goto :good 19 | 20 | echo bad 21 | 22 | :good echo good 23 | ``` 24 | -------------------------------------------------------------------------------- /test/std/string/last_indexof_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_not_found 3 | output = last_indexof "1 2 3 4 5" "4 5 6" 4 | 5 | assert_eq ${output} "" 6 | end 7 | 8 | fn test_prefix 9 | output = last_indexof "1 2 3 4 5 1 2 3 4 5" "1 2" 10 | 11 | assert_eq ${output} 10 12 | end 13 | 14 | fn test_suffix 15 | output = last_indexof "1 2 3 4 5 1 2 3 4 5" "4 5" 16 | 17 | assert_eq ${output} 16 18 | end 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/which/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = which executable 3 | ``` 4 | 5 | Returns the path to the executable if it exists.
6 | If not found it will return an empty string. 7 | 8 | ### Parameters 9 | 10 | The executable to find. 11 | 12 | ### Return Value 13 | 14 | The executable path or empty string if not found. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | path = which echo 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/is_directory/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_dir path 3 | ``` 4 | 5 | This command will return true/false based if the provided path points to an existing directory. 6 | 7 | ### Parameters 8 | 9 | The path to check. 10 | 11 | ### Return Value 12 | 13 | True if the path points to an existing directory. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | existing_dir = is_dir ./dir 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/is_file/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_file path 3 | ``` 4 | 5 | This command will return true/false based if the provided path points to an existing file. 6 | 7 | ### Parameters 8 | 9 | The path to check. 10 | 11 | ### Return Value 12 | 13 | True if the path points to an existing file. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | existing_file = is_file ./dir/somefile.txt 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/greater_than/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = greater_than left right 3 | ``` 4 | 5 | This command returns true/false based on left > right calculation. 6 | 7 | ### Parameters 8 | 9 | Two numeric values to compare. 10 | 11 | ### Return Value 12 | 13 | True if first argument is bigger than second argument. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | result = greater_than 2 1.5 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/print_current_directory/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = pwd 3 | ``` 4 | 5 | Prints and also returns the current directory. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The current directory path. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # Print the current directory: 19 | pwd 20 | 21 | # Print and also store the current directory: 22 | directory = pwd 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/trigger_error/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | trigger_error [message] 3 | ``` 4 | 5 | Triggers an error that will trigger the on_error flow. 6 | 7 | ### Parameters 8 | 9 | Optional error message. 10 | 11 | ### Return Value 12 | 13 | None 14 | 15 | ### Examples 16 | 17 | ```sh 18 | trigger_error "my error message" 19 | error = get_last_error 20 | assert_eq ${error} "my error message" 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/is_empty/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_empty value 3 | ``` 4 | 5 | Returns true if the provided value is none or an empty string. 6 | 7 | ### Parameters 8 | 9 | The value to validate. 10 | 11 | ### Return Value 12 | 13 | True if the provided value is none or an empty string. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | value = set "hello world" 19 | empty = is_empty ${value} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_is_empty/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = array_is_empty handle 3 | ``` 4 | 5 | Returns true if the provided array handle is an empty array. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | True if the provided handle belongs to an empty array. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | values = array 19 | out = array_is_empty ${values} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/process/exit/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | code = exit [code] 3 | ``` 4 | 5 | Exits the script with the given code stored in the output variable. 6 | 7 | ### Parameters 8 | 9 | A number as exit code or none for 0. 10 | 11 | ### Return Value 12 | 13 | The exit code. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # exit with code '0' 19 | code = exit 20 | 21 | # exit with code '1' 22 | code = exit 1 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_put/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = set_put handle value 3 | ``` 4 | 5 | Pushes an additional value to an existing set. 6 | 7 | ### Parameters 8 | 9 | The set handle. 10 | 11 | ### Return Value 12 | 13 | True if a new value was pushed. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = set_new 1 2 3 19 | set_put ${handle} 4 20 | size = set_size ${handle} 21 | assert_eq ${size} 4 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/get_file_size/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_file_size path 3 | ``` 4 | 5 | This command will return the size of the file in bytes. 6 | 7 | ### Parameters 8 | 9 | The path to check. 10 | 11 | ### Return Value 12 | 13 | The size of the file in bytes or false in case path is a directory or does not exist. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | size = get_file_size ./dir/somefile.txt 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/read_bytes/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = read_binary_file file 3 | ``` 4 | 5 | Reads a raw file and returns a handle to the binary data. 6 | 7 | ### Parameters 8 | 9 | A single parameter holding the file path. 10 | 11 | ### Return Value 12 | 13 | The binary data handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = read_binary_file ./Cargo.toml 19 | text = bytes_to_string ${handle} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/dump_instructions/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | value = dump_instructions 3 | ``` 4 | 5 | Returns all script instructions structure (not script text) in textual form. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The script instructions. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | value = dump_instructions 19 | found = contains ${value} dump_instructions 20 | assert found 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/cpu_count/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = cpu_count", 15 | CommandValidation::Ignore, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/is_readonly/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_readonly path 3 | ``` 4 | 5 | This command will return true/false based if the provided path exists and is set to readonly. 6 | 7 | ### Parameters 8 | 9 | The path to check. 10 | 11 | ### Return Value 12 | 13 | True if the provided path exists and is set to readonly. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | readonly = is_readonly ./dir/somefile.txt 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/print/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = cat [file]+ 3 | ``` 4 | 5 | The cat command will print out the requested file/s.
6 | In addition it will also return the value to the output variable. 7 | 8 | ### Parameters 9 | 10 | Multiple file paths. 11 | 12 | ### Return Value 13 | 14 | The file content or none if the file does not exist. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | cat ./docs/sdk.md 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/temp_dir/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_simple() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = temp_dir", 15 | CommandValidation::Ignore, 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/unset/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | unset [names]* 3 | ``` 4 | 5 | Undefines all the variable names provided. 6 | 7 | ### Parameters 8 | 9 | A list of variable names to undefine. 10 | 11 | ### Return Value 12 | 13 | None 14 | 15 | ### Examples 16 | 17 | ```sh 18 | var = set 1 19 | defined = is_defined var 20 | assert ${defined} 21 | unset var 22 | defined = is_defined var 23 | assert_false ${defined} 24 | ``` 25 | -------------------------------------------------------------------------------- /test/std/is_command_defined_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_not_defined 3 | defined = is_command_defined badcommand 4 | 5 | assert_false ${defined} 6 | end 7 | 8 | fn test_defined 9 | defined = is_command_defined is_command_defined 10 | assert ${defined} 11 | 12 | defined = is_command_defined assert 13 | assert ${defined} 14 | 15 | defined = is_command_defined test_defined 16 | assert ${defined} 17 | end 18 | 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_from_array/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | set_handle = set_from_array array_handle 3 | ``` 4 | 5 | Returns a set handle created from the provided array values. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | The new set handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | array_handle = array value1 value2 value3 19 | set_handle = set_from_array ${handle} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_is_empty/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = set_is_empty handle 3 | ``` 4 | 5 | Returns true if the provided set handle is an empty set. 6 | 7 | ### Parameters 8 | 9 | The set handle. 10 | 11 | ### Return Value 12 | 13 | True if the provided handle belongs to an empty set. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = set 19 | set_put ${handle} value 20 | empty = set_is_empty ${handle} 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/print_env/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = printenv 3 | ``` 4 | 5 | Prints and returns all environment variables. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | All environment variables printout text. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | set_env TEST_PRINT_ENV TRUE 19 | 20 | text = printenv 21 | 22 | valid = contains ${text} TEST_PRINT_ENV=TRUE 23 | assert ${valid} 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/dirname/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = dirname path 3 | ``` 4 | 5 | This command will return the parent path of the provided path.
6 | If the parent path is empty, it will return none. 7 | 8 | ### Parameters 9 | 10 | The path to extract the parent path from. 11 | 12 | ### Return Value 13 | 14 | The parent path or none. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | directory = dirname ./dir/file.txt 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/read_text/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = readfile file 3 | ``` 4 | 5 | The readfile command will read the requested file and return the value to the output variable. 6 | 7 | ### Parameters 8 | 9 | A single parameter holding the file path. 10 | 11 | ### Return Value 12 | 13 | The file content or none in case file does not exist. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | text = readfile ./Cargo.toml 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript/src/preprocessor/include_files_preprocessor_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | #[test] 4 | fn run_no_arguments() { 5 | let output = run(&None); 6 | 7 | assert!(output.is_ok()); 8 | assert!(output.unwrap().is_empty()); 9 | } 10 | 11 | #[test] 12 | fn run_single_file() { 13 | let output = run(&Some(vec!["./src/test/scripts/simple.ds"])); 14 | 15 | assert!(output.is_ok()); 16 | assert!(output.unwrap().len(), 6); 17 | } -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_is_empty/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = map_is_empty handle 3 | ``` 4 | 5 | Returns true if the provided map handle is an empty map. 6 | 7 | ### Parameters 8 | 9 | The map handle. 10 | 11 | ### Return Value 12 | 13 | True if the provided handle belongs to an empty map. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = map 19 | map_put ${handle} key value 20 | empty = map_is_empty ${handle} 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/hex_encode/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | str = hex_encode num 3 | ``` 4 | 5 | Converts an integer number to the corresponding hexadecimal string.
6 | No support for negative numbers. 7 | 8 | ### Parameters 9 | 10 | An integer number. 11 | 12 | ### Return Value 13 | 14 | The corresponding hexadecimal string. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | str = hex_encode 255 20 | 21 | assert_eq ${str} 0xff 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/camelcase/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = camelcase text 3 | ``` 4 | 5 | Converts the provided string into camel case. 6 | All non-alphanumeric characters are ignored. 7 | 8 | ### Parameters 9 | 10 | The string to convert. 11 | 12 | ### Return Value 13 | 14 | The converted string. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | string = camelcase "hello, world!" 20 | assert_eq ${string} "HelloWorld" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/kebabcase/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = kebobcase text 3 | ``` 4 | 5 | Converts the provided string into kebob case. 6 | All non-alphanumeric characters are ignored. 7 | 8 | ### Parameters 9 | 10 | The string to convert. 11 | 12 | ### Return Value 13 | 14 | The converted string. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | string = kebobcase "Hello, World!" 20 | assert_eq ${string} "hello-world" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/snakecase/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = snakecase text 3 | ``` 4 | 5 | Converts the provided string into snake case. 6 | All non-alphanumeric characters are ignored. 7 | 8 | ### Parameters 9 | 10 | The string to convert. 11 | 12 | ### Return Value 13 | 14 | The converted string. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | string = snakecase "Hello, World!" 20 | assert_eq ${string} "hello_world" 21 | ``` 22 | 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/assert_fail/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | assert_fail [error message] 3 | ``` 4 | 5 | This command will exist with an error.
6 | If error message is provided, it will be used as part of the error output. 7 | 8 | ### Parameters 9 | 10 | Optional error message. 11 | 12 | ### Return Value 13 | 14 | None 15 | 16 | ### Examples 17 | 18 | ```sh 19 | assert_fail 20 | 21 | assert_fail "This is my error message" 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_contains/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = set_contains handle value 3 | ``` 4 | 5 | Returns true if the set contains the provided value. 6 | 7 | ### Parameters 8 | 9 | * The set handle. 10 | * The value 11 | 12 | ### Return Value 13 | 14 | True if the value was found in the set. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = set_new value1 value2 value3 20 | found = set_contains ${handle} value2 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/basename/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = basename path 3 | ``` 4 | 5 | This command will return the last path element of the provided path.
6 | If unable, it will return none. 7 | 8 | ### Parameters 9 | 10 | The path to extract the last element from. 11 | 12 | ### Return Value 13 | 14 | The last path element or none if unsuccessful. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | file = basename ./dir/file.txt 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/thread/mod.rs: -------------------------------------------------------------------------------- 1 | mod sleep; 2 | 3 | use crate::utils::pckg; 4 | use duckscript::types::command::Commands; 5 | use duckscript::types::error::ScriptError; 6 | 7 | static PACKAGE: &str = "thread"; 8 | 9 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 10 | let package = pckg::concat(parent, PACKAGE); 11 | 12 | commands.set(sleep::create(&package))?; 13 | 14 | Ok(()) 15 | } 16 | -------------------------------------------------------------------------------- /examples/string.ds: -------------------------------------------------------------------------------- 1 | 2 | # string is 'Hello World' 3 | string = substring "Hello World" 4 | echo ${string} 5 | 6 | # string is 'll' 7 | string = substring "Hello World" 2 4 8 | echo ${string} 9 | 10 | # string is 'llo World' 11 | string = substring "Hello World" 2 12 | echo ${string} 13 | 14 | # string is 'Hello W' 15 | string = substring "Hello World" -4 16 | echo ${string} 17 | 18 | len = length "Hello World" 19 | echo The text length is: ${len} 20 | -------------------------------------------------------------------------------- /test/std/fs/is_readonly_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_not_readonly 3 | value = is_readonly ./Cargo.toml 4 | 5 | error = get_last_error 6 | empty = is_empty ${error} 7 | assert ${empty} 8 | 9 | assert_false ${value} 10 | end 11 | 12 | fn test_not_found 13 | value = is_readonly ./badpath 14 | 15 | error = get_last_error 16 | empty = is_empty ${error} 17 | assert_false ${empty} 18 | 19 | assert_false ${value} 20 | end 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/get_last_error/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_last_error 3 | ``` 4 | 5 | In case of any runtime error, this function will return the error message. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The last error message or none 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # This will trigger an error 19 | assert_fail 20 | 21 | error = get_last_error 22 | echo Error Message: ${error} 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/trim/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = trim value 3 | ``` 4 | 5 | Returns the provided value with leading and trailing whitespace removed. 6 | 7 | ### Parameters 8 | 9 | The value to trim. 10 | 11 | ### Return Value 12 | 13 | The trimmed value. If no input provided, this command will return none. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # trimmed will now hold "some text" 19 | trimmed = trim " some text " 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/trim_end/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = trim_end value 3 | ``` 4 | 5 | Returns the provided value with trailing whitespace removed. 6 | 7 | ### Parameters 8 | 9 | The value to trim. 10 | 11 | ### Return Value 12 | 13 | The trimmed value. If no input provided, this command will return none. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # trimmed will now hold " some text" 19 | trimmed = trim_end " some text " 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/assert_fail/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_crash(vec![create("")], "out = assert_fail"); 12 | } 13 | 14 | #[test] 15 | fn run_with_message() { 16 | test::run_script_and_crash(vec![create("")], "out = assert_fail error"); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/get_all_var_names/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = get_all_var_names 3 | ``` 4 | 5 | Creates an array holding all currently known variable names and returns the array handle. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | A handle to the array. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = get_all_var_names 19 | 20 | # once done we should release the handle 21 | release ${handle} 22 | ``` 23 | -------------------------------------------------------------------------------- /test/std/collections/is_array_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_array_found 3 | arr = array 1 2 3 4 | 5 | value = is_array ${arr} 6 | assert ${value} 7 | 8 | released = release ${arr} 9 | assert ${released} 10 | end 11 | 12 | fn test_not_array 13 | arr = set true 14 | 15 | value = is_array ${arr} 16 | assert_false ${value} 17 | end 18 | 19 | fn test_not_found 20 | value = is_array ${arr} 21 | assert_false ${value} 22 | end 23 | -------------------------------------------------------------------------------- /test/std/fs/get_last_modified_time_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_file 3 | time = get_last_modified_time ./Cargo.toml 4 | positive = greater_than ${time} 0 5 | assert ${positive} 6 | end 7 | 8 | fn test_directory 9 | time = get_last_modified_time . 10 | positive = greater_than ${time} 0 11 | assert ${positive} 12 | end 13 | 14 | fn test_not_found 15 | time = get_last_modified_time ./badfile 16 | assert_false ${time} 17 | end 18 | 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_push/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = array_push handle value 3 | ``` 4 | 5 | Pushes an additional value to an existing array. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | True if a new value was pushed. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = array 1 2 3 19 | array_push ${handle} 4 20 | last_element = array_pop ${handle} 21 | assert_eq ${last_element} 4 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/cp_glob/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = glob_cp source_glob target 3 | ``` 4 | 5 | This command will copy all files that match the given glob. 6 | 7 | ### Parameters 8 | 9 | * The source glob, for example ./*.txt 10 | * The target path 11 | 12 | ### Return Value 13 | 14 | The amount of paths (files) copied or false in case of any error. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | count = glob_cp ./**/*.txt ../target 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/lib/command/mod.rs: -------------------------------------------------------------------------------- 1 | mod remove; 2 | 3 | use crate::utils::pckg; 4 | use duckscript::types::command::Commands; 5 | use duckscript::types::error::ScriptError; 6 | 7 | static PACKAGE: &str = "command"; 8 | 9 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 10 | let package = pckg::concat(parent, PACKAGE); 11 | 12 | commands.set(remove::create(&package))?; 13 | 14 | Ok(()) 15 | } 16 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/process/process_id/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = pid", 15 | CommandValidation::PositiveNumber("out".to_string()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/random/text/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | output = random_text [length] 3 | ``` 4 | 5 | Generates random alphanumeric text with the requested length (length is 1 if not provided). 6 | 7 | ### Parameters 8 | 9 | Optional text length. Length is defaulted to 1 if not provided. 10 | 11 | ### Return Value 12 | 13 | The generated alphanumeric value. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | value = random_text 50 19 | echo ${value} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/trim_start/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = trim_start value 3 | ``` 4 | 5 | Returns the provided value with leading whitespace removed. 6 | 7 | ### Parameters 8 | 9 | The value to trim. 10 | 11 | ### Return Value 12 | 13 | The trimmed value. If no input provided, this command will return none. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # trimmed will now hold "some text " 19 | trimmed = trim_start " some text " 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/time/mod.rs: -------------------------------------------------------------------------------- 1 | mod current_time; 2 | 3 | use crate::utils::pckg; 4 | use duckscript::types::command::Commands; 5 | use duckscript::types::error::ScriptError; 6 | 7 | static PACKAGE: &str = "time"; 8 | 9 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 10 | let package = pckg::concat(parent, PACKAGE); 11 | 12 | commands.set(current_time::create(&package))?; 13 | 14 | Ok(()) 15 | } 16 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_contains_key/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = map_contains_key handle key 3 | ``` 4 | 5 | Returns true if the provided key was found in the map. 6 | 7 | ### Parameters 8 | 9 | * The map handle. 10 | * The key 11 | 12 | ### Return Value 13 | 14 | True if the key was found in the map. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = map 20 | map_put ${handle} key value 21 | found = map_contains_key ${handle} key 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/utils/pckg_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | #[test] 4 | fn concat_both_provided() { 5 | let output = concat("1::2", "3"); 6 | assert_eq!(output, "1::2::3"); 7 | } 8 | 9 | #[test] 10 | fn concat_parent_provided() { 11 | let output = concat("1::2", ""); 12 | assert_eq!(output, "1::2"); 13 | } 14 | 15 | #[test] 16 | fn concat_current_provided() { 17 | let output = concat("", "3::4"); 18 | assert_eq!(output, "3::4"); 19 | } 20 | -------------------------------------------------------------------------------- /test/std/string/replace_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_found 3 | text = set "my large text value with lots of text" 4 | updated = replace ${text} text stuff 5 | 6 | assert_eq ${updated} "my large stuff value with lots of stuff" 7 | end 8 | 9 | fn test_not_found 10 | text = set "my large text value with lots of text" 11 | updated = replace ${text} stuff other 12 | 13 | assert_eq ${updated} "my large text value with lots of text" 14 | end 15 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_from_array/script.ds: -------------------------------------------------------------------------------- 1 | 2 | if not is_array ${scope::set_from_array::argument::1} 3 | trigger_error "Invalid input, non array handle or array not found." 4 | end 5 | 6 | scope::set_from_array::set = set_new 7 | for scope::set_from_array::next_value in ${scope::set_from_array::argument::1} 8 | set_put ${scope::set_from_array::set} ${scope::set_from_array::next_value} 9 | end 10 | 11 | set ${scope::set_from_array::set} 12 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_to_array/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | array_handle = set_to_array set_handle 3 | ``` 4 | 5 | Converts the provided set to an array and returns the new array handle. 6 | 7 | ### Parameters 8 | 9 | The set handle. 10 | 11 | ### Return Value 12 | 13 | The array handle or false in case of error. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | set_handle = set_new value1 value2 value3 19 | array_handle = set_to_array ${set_handle} 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/mkdir/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = mkdir directory 3 | ``` 4 | 5 | This command will create the requested directory (and needed parent directories) and return true/false if it was successful. 6 | 7 | ### Parameters 8 | 9 | The directory name to create. 10 | 11 | ### Return Value 12 | 13 | The operation success value - true if directory exists, else false. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | exists = mkdir ./dir/subdir 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/time/current_time/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = current_time", 15 | CommandValidation::PositiveNumber("out".to_string()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /examples/ls.ds: -------------------------------------------------------------------------------- 1 | 2 | # prints current directory content 3 | ls 4 | 5 | # prints current directory content 6 | ls . 7 | 8 | # prints examples directory content 9 | ls ./examples 10 | 11 | # prints examples directory content with extended info 12 | ls -l ./examples 13 | 14 | # prints current directory content with extended info 15 | ls -l 16 | 17 | # prints file name 18 | ls ./examples/ls.ds 19 | 20 | # prints file name with extended info 21 | ls -l ./examples/ls.ds 22 | -------------------------------------------------------------------------------- /test/std/env/uname_test.ds: -------------------------------------------------------------------------------- 1 | 2 | windows = is_windows 3 | 4 | fn test_uname 5 | name = os_name 6 | info = uname 7 | assert_eq ${name} ${info} 8 | end 9 | 10 | fn test_uname_extended 11 | name = os_name 12 | info = uname -a 13 | if ${windows} 14 | assert_eq ${name} ${info} 15 | else 16 | release = os_release 17 | version = os_version 18 | assert_eq "${name} ${release} ${version}" ${info} 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature Request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: sagiegurari 7 | 8 | --- 9 | 10 | ### Feature Description 11 | 12 | 13 | ### Describe The Solution You'd Like 14 | 15 | 16 | ### Code Sample 17 | 18 | ```rust 19 | /// paste code here 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_pop/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = array_pop handle 3 | ``` 4 | 5 | Returns the last element of the array or none if the array is empty. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | The last element of the array or none if the array is empty. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = array 1 2 3 19 | last_element = array_pop ${handle} 20 | assert_eq ${last_element} 3 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/canonical/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = canonicalize path 3 | ``` 4 | 5 | This command will return the c path for the provided input.
6 | In case unable, it will return the original input. 7 | 8 | ### Parameters 9 | 10 | The file/directory path to canonicalize. 11 | 12 | ### Return Value 13 | 14 | The canonicalized path, or if unsuccessful, the original path. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | path = canonicalize ./target 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/join_path/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = join_path path [path]* 3 | ``` 4 | 5 | Concats all paths and makes sure there is a / character between each path element. 6 | 7 | ### Parameters 8 | 9 | * A list of paths to join 10 | 11 | ### Return Value 12 | 13 | The joined path 14 | 15 | ### Examples 16 | 17 | ```sh 18 | joined = join_path /test /dir1 /dir2 dir3 //dir4// /dir5 19 | 20 | assert_eq ${joined} /test/dir1/dir2/dir3/dir4/dir5 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/get_last_error_line/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_last_error_line 3 | ``` 4 | 5 | In case of any runtime error, this function will return the error line (if available). 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The last error line or none 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # This will trigger an error 19 | assert_fail 20 | 21 | line = get_last_error_line 22 | echo Error Line: ${line} 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/assert_error/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = assert_error", "out"); 12 | } 13 | 14 | #[test] 15 | fn run_with_message() { 16 | test::run_script_and_error(vec![create("")], "out = assert_error error", "out"); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/is_set/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_set handle 3 | ``` 4 | 5 | Returns true if the provided value is a set handle. 6 | 7 | ### Parameters 8 | 9 | The set handle. 10 | 11 | ### Return Value 12 | 13 | True if the provided value is a set handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = set_new 1 2 3 19 | 20 | value = is_set ${handle} 21 | assert ${value} 22 | 23 | released = release ${handle} 24 | assert ${released} 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_contains_value/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = map_contains_value handle value 3 | ``` 4 | 5 | Returns true if the provided value was found in the map. 6 | 7 | ### Parameters 8 | 9 | * The map handle. 10 | * The value 11 | 12 | ### Return Value 13 | 14 | True if the value was found in the map. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = map 20 | map_put ${handle} key value 21 | found = map_contains_value ${handle} value 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/get_last_modified_time/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_last_modified_time path 3 | ``` 4 | 5 | This command will return the last modified time in millies from unix epoch. 6 | 7 | ### Parameters 8 | 9 | The path to check. 10 | 11 | ### Return Value 12 | 13 | The last modified time in millies from unix epoch or false in case path does not exist. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | time = get_last_modified_time ./dir/somefile.txt 19 | ``` 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/sha256sum/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = sha256sum file 3 | ``` 4 | 5 | Runs SHA-256 hash on the provided file returns the hashed value in hex. 6 | 7 | ### Parameters 8 | 9 | The file to hash 10 | 11 | ### Return Value 12 | 13 | The hash value in hex or false in case of error. 14 | The result will be in lowercase, same as with the core utils with the same name. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | hashed = sha256sum ./myfile.txt 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/sha512sum/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = sha512sum file 3 | ``` 4 | 5 | Runs SHA-512 hash on the provided file returns the hashed value in hex. 6 | 7 | ### Parameters 8 | 9 | The file to hash 10 | 11 | ### Return Value 12 | 13 | The hash value in hex or false in case of error. 14 | The result will be in lowercase, same as with the core utils with the same name. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | hashed = sha512sum ./myfile.txt 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/trigger_error/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = trigger_error", "out"); 12 | } 13 | 14 | #[test] 15 | fn run_with_message() { 16 | test::run_script_and_error(vec![create("")], "out = trigger_error msg", "out"); 17 | } 18 | -------------------------------------------------------------------------------- /test/std/collections/is_map_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_map_found 3 | map_handle = map 4 | 5 | value = is_map ${map_handle} 6 | assert ${value} 7 | 8 | released = release ${map_handle} 9 | assert ${released} 10 | end 11 | 12 | fn test_not_map 13 | map_handle = set true 14 | 15 | value = is_map ${map_handle} 16 | assert_false ${value} 17 | end 18 | 19 | fn test_not_found 20 | value = is_map ${map_handle} 21 | assert_false ${value} 22 | end 23 | -------------------------------------------------------------------------------- /test/std/collections/is_set_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_set_found 3 | set_handle = set_new 4 | 5 | value = is_set ${set_handle} 6 | assert ${value} 7 | 8 | released = release ${set_handle} 9 | assert ${released} 10 | end 11 | 12 | fn test_not_set 13 | set_handle = set true 14 | 15 | value = is_set ${set_handle} 16 | assert_false ${value} 17 | end 18 | 19 | fn test_not_found 20 | value = is_set ${set_handle} 21 | assert_false ${value} 22 | end 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/is_array/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_array handle 3 | ``` 4 | 5 | Returns true if the provided value is an array handle. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | True if the provided value is an array handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | arr = array 1 2 3 19 | 20 | value = is_array ${arr} 21 | assert ${value} 22 | 23 | released = release ${arr} 24 | assert ${released} 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/is_map/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_map handle 3 | ``` 4 | 5 | Returns true if the provided value is a map handle. 6 | 7 | ### Parameters 8 | 9 | The map handle. 10 | 11 | ### Return Value 12 | 13 | True if the provided value is a map handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | map_handle = map 19 | 20 | value = is_map ${map_handle} 21 | assert ${value} 22 | 23 | released = release ${map_handle} 24 | assert ${released} 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/env_to_map/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | r#"out = env_to_map"#, 15 | CommandValidation::Contains("out".to_string(), "handle:".to_string()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/exists/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_path_exists path 3 | ``` 4 | 5 | This command will return true/false based if the provided path points to an existing file system entry. 6 | 7 | ### Parameters 8 | 9 | The path to check. 10 | 11 | ### Return Value 12 | 13 | True if the path points to an existing file system entry. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | existing = is_path_exists ./dir 19 | existing = is_path_exists ./dir/somefile.txt 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/set_error/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | set_error message 3 | ``` 4 | 5 | Sets the last error which is accessible via get_last_error.
6 | This command will not trigger the on_error command flow. 7 | 8 | ### Parameters 9 | 10 | The error message. 11 | 12 | ### Return Value 13 | 14 | None 15 | 16 | ### Examples 17 | 18 | ```sh 19 | set_error "my error message" 20 | 21 | error = get_last_error 22 | 23 | assert_eq ${error} "my error message" 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/print_current_directory/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = pwd", 15 | CommandValidation::Contains("out".to_string(), "duckscript".to_string()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/assert_error/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | assert_error [error message] 3 | ``` 4 | 5 | This command will cause a runtime error which will not stop the script execution.
6 | If error message is provided, it will be used as part of the error output. 7 | 8 | ### Parameters 9 | 10 | Optional error message. 11 | 12 | ### Return Value 13 | 14 | None 15 | 16 | ### Examples 17 | 18 | ```sh 19 | assert_error 20 | 21 | assert_error "This is my error message" 22 | ``` 23 | -------------------------------------------------------------------------------- /test/std/collections/set_put_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_set_with_data 3 | handle = set_new a 4 | counter = range 1 4 5 | for index in ${counter} 6 | set_put ${handle} ${index} 7 | end 8 | 9 | size = set_size ${handle} 10 | assert_eq ${size} 4 11 | 12 | result = set_remove ${handle} 1 13 | assert ${result} 14 | size = set_size ${handle} 15 | assert_eq ${size} 3 16 | 17 | released = release ${handle} 18 | assert ${released} 19 | end 20 | 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/env_to_map/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = env_to_map 3 | ``` 4 | 5 | Converts all environment variables to a map and returns the map handle. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The map handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | set_env env_to_map_test test_value 19 | 20 | handle = env_to_map 21 | 22 | value = map_get ${handle} env_to_map_test 23 | assert_eq ${value} test_value 24 | 25 | release ${handle} 26 | ``` 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/hex_decode/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | num = hex_decode str 3 | ``` 4 | 5 | Decode a hexadecimal string to the corresponding integer number.
6 | No support for negative numbers. 7 | 8 | ### Parameters 9 | 10 | A hexadecimal string. 11 | 12 | ### Return Value 13 | 14 | The corresponding integer number. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | hex_num = set 0xff 20 | num = hex_decode ${hex_num} 21 | res = calc ${num} + 1 22 | 23 | assert_eq ${res} 256 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/concat/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = concat [value]* 3 | ``` 4 | 5 | Concats the provided input into a single string and returns it. 6 | 7 | ### Parameters 8 | 9 | Any number of values to concat. 10 | 11 | ### Return Value 12 | 13 | The result of the concatenation of all input values. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | output = concat 1 2 3 4 19 | assert_eq ${output} 1234 20 | 21 | output = concat 1 "2 3" 4 22 | assert_eq ${output} "12 34" 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/duckscript_sdk_version/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = duckscript_sdk_version", 15 | CommandValidation::Match("out".to_string(), crate::version()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/duckscript_version/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = duckscript_version", 15 | CommandValidation::Match("out".to_string(), duckscript::version()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/rmdir/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = rmdir path 3 | ``` 4 | 5 | This command delete the requested empty directory and returns true if successful.
6 | If the path leads to a file or a directory which is not empty, this command will fail. 7 | 8 | ### Parameters 9 | 10 | A single parameter holding the directory path. 11 | 12 | ### Return Value 13 | 14 | **true** if the directory was deleted. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | deleted = rmdir ./mydir 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/touch/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = touch file 3 | ``` 4 | 5 | This command will create an empty file and return true/false if the file exists.
6 | If file exits, it will not be modified. 7 | 8 | ### Parameters 9 | 10 | The file path. 11 | 12 | ### Return Value 13 | 14 | If the file exists after the command, it will return true.
15 | In case of any error, it will return false. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | exists = touch ./dir/file.txt 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/zip/zip/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = zip", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_only_zip_file() { 17 | test::run_script_and_error(vec![create("")], "out = zip ./myfile.zip", "out"); 18 | } 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/lib/mod.rs: -------------------------------------------------------------------------------- 1 | mod alias; 2 | mod command; 3 | 4 | use crate::utils::pckg; 5 | use duckscript::types::command::Commands; 6 | use duckscript::types::error::ScriptError; 7 | 8 | static PACKAGE: &str = "lib"; 9 | 10 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 11 | let package = pckg::concat(parent, PACKAGE); 12 | 13 | alias::load(commands, &package)?; 14 | command::load(commands, &package)?; 15 | 16 | Ok(()) 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/internal/sdkdocs/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | doc_file = internal::sdkdocs [prefix] output_file 3 | ``` 4 | 5 | Generates markdown documentation of all known commands and writes them into the provided file. 6 | 7 | ### Parameters 8 | 9 | * Optional name prefix 10 | * The target file name which will hold the generated documentation. 11 | 12 | ### Return Value 13 | 14 | The target file name. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | doc_file = internal::sdkdocs ./docs/sdk.md 20 | ``` 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/get_user_name/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | let name = whoami::username(); 13 | 14 | test::run_script_and_validate( 15 | vec![create("")], 16 | "out = whoami", 17 | CommandValidation::Match("out".to_string(), name), 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/random/range/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | output = random_range min max 3 | ``` 4 | 5 | Generate a random value in the range of min and max values provided, i.e. inclusive of min and exclusive of max. 6 | 7 | ### Parameters 8 | 9 | * min - The min range value (inclusive) 10 | * max - The max range value (exclusive) 11 | 12 | ### Return Value 13 | 14 | The generated numeric value. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | value = random_range -10 10 20 | echo ${value} 21 | ``` 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug Report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: sagiegurari 7 | 8 | --- 9 | 10 | ### Describe The Bug 11 | 12 | 13 | ### To Reproduce 14 | 15 | 16 | ### Error Stack 17 | 18 | ```console 19 | The error stack trace 20 | ``` 21 | 22 | ### Code Sample 23 | 24 | ```rust 25 | /// paste code here 26 | ``` 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/dump_instructions/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = dump_instructions", 15 | CommandValidation::Contains("out".to_string(), "dump_instructions".to_string()), 16 | ); 17 | } 18 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/zip/mod.rs: -------------------------------------------------------------------------------- 1 | mod unzip; 2 | mod zip; 3 | 4 | use crate::utils::pckg; 5 | use duckscript::types::command::Commands; 6 | use duckscript::types::error::ScriptError; 7 | 8 | static PACKAGE: &str = "zip"; 9 | 10 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 11 | let package = pckg::concat(parent, PACKAGE); 12 | 13 | commands.set(unzip::create(&package))?; 14 | commands.set(zip::create(&package))?; 15 | 16 | Ok(()) 17 | } 18 | -------------------------------------------------------------------------------- /test/std/collections/read_properties_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_read_properties 3 | count = read_properties a=1\nb=2\na.b.c=3 4 | assert_eq ${count} 3 5 | 6 | assert_eq ${a} 1 7 | assert_eq ${b} 2 8 | assert_eq ${a.b.c} 3 9 | end 10 | 11 | fn test_read_properties_with_prefix 12 | count = read_properties --prefix config a=1\nb=2\na.b.c=3 13 | assert_eq ${count} 3 14 | 15 | assert_eq ${config.a} 1 16 | assert_eq ${config.b} 2 17 | assert_eq ${config.a.b.c} 3 18 | end 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/get_last_error_source/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_last_error_source 3 | ``` 4 | 5 | In case of any runtime error, this function will return the error source (such as file name) if available. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The last error source or none 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # This will trigger an error 19 | assert_fail 20 | 21 | source = get_last_error_source 22 | echo Error Source File: ${source} 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/random/mod.rs: -------------------------------------------------------------------------------- 1 | mod range; 2 | mod text; 3 | 4 | use crate::utils::pckg; 5 | use duckscript::types::command::Commands; 6 | use duckscript::types::error::ScriptError; 7 | 8 | static PACKAGE: &str = "random"; 9 | 10 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 11 | let package = pckg::concat(parent, PACKAGE); 12 | 13 | commands.set(range::create(&package))?; 14 | commands.set(text::create(&package))?; 15 | 16 | Ok(()) 17 | } 18 | -------------------------------------------------------------------------------- /test/std/net/ftp/ftp_get_in_memory_test.ds: -------------------------------------------------------------------------------- 1 | 2 | !include_files ../../../helper.ds 3 | 4 | fn test_valid 5 | if skip_unstable 6 | return 7 | end 8 | 9 | handle = ftp_get_in_memory --host test.rebex.net --username demo --password password --remote-file readme.txt 10 | 11 | text = bytes_to_string ${handle} 12 | release ${handle} 13 | 14 | empty = is_empty ${text} 15 | assert_false ${empty} 16 | 17 | found = contains ${text} Welcome 18 | assert ${found} 19 | end 20 | 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/uname/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::uname::extended_info = equals -a ${scope::uname::argument::1} 3 | scope::uname::info = os_name 4 | 5 | scope::uname::not_windows = not is_windows 6 | 7 | if ${scope::uname::extended_info} and ${scope::uname::not_windows} 8 | scope::uname::release = os_release 9 | scope::uname::version = os_version 10 | scope::uname::info = set "${scope::uname::info} ${scope::uname::release} ${scope::uname::version}" 11 | end 12 | 13 | set ${scope::uname::info} 14 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/eval/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | eval command arguments 3 | ``` 4 | 5 | The eval command enables to run dynamically created commands.
6 | The command and arguments passed can be variables in the form of ${name}. 7 | 8 | ### Parameters 9 | 10 | Any number of arguments which will construct a line to evaluate and execute. 11 | 12 | ### Return Value 13 | 14 | The result of the evaluated line. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | command = set echo 20 | eval ${command} hello world 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/calc/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = calc [operation] 3 | ``` 4 | 5 | The calc command accepts multiple arguments which make up a mathematical operation which will be 6 | calculated and its result will be returned. 7 | 8 | ### Parameters 9 | 10 | Any number of arguments which will construct a line to calculate. 11 | 12 | ### Return Value 13 | 14 | The result of the mathematical calculation. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | # result is 36 20 | result = calc 1 + 5 * 7 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/hostname/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | let name = whoami::fallible::hostname().unwrap(); 13 | 14 | test::run_script_and_validate( 15 | vec![create("")], 16 | "out = hostname", 17 | CommandValidation::Match("out".to_string(), name), 18 | ); 19 | } 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/semver/is_equal/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | output = semver_is_equal value1 value2 3 | ``` 4 | 5 | Returns true if both semver values are valid and equal. 6 | 7 | ### Parameters 8 | 9 | Two semver values to compare. 10 | 11 | ### Return Value 12 | 13 | True if both semver values are valid and equal, else false. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | equal = semver_is_equal 1.2.3 1.2.3 19 | assert ${equal} 20 | 21 | equal = semver_is_equal 1.2.3 2.2.3 22 | assert_false ${equal} 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/bytes_to_string/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | text = bytes_to_string handle 3 | ``` 4 | 5 | Converts the provided UTF-8 binary array to string and returns it. 6 | 7 | ### Parameters 8 | 9 | A handle to a binary array holding UTF-8 text. 10 | 11 | ### Return Value 12 | 13 | The textual data. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = string_to_bytes "hello world" 19 | text = bytes_to_string ${handle} 20 | 21 | release ${handle} 22 | 23 | assert_eq ${text} "hello world" 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/thread/sleep/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | sleep millies 3 | ``` 4 | 5 | Will cause the script execution to half for the given amount of milliseconds.
6 | The command will also return the amount of milliseconds waited. 7 | 8 | ### Parameters 9 | 10 | A positive numeric value. 11 | 12 | ### Return Value 13 | 14 | The amount of milliseconds waited. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | # will sleep for 10 milliseconds 20 | time = sleep 10 21 | echo Waited for ${time} milliseconds. 22 | ``` 23 | -------------------------------------------------------------------------------- /test/std/net/wget_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_get 3 | response = wget https://www.rust-lang.org/ 4 | 5 | found = contains ${response} Rust 6 | 7 | assert ${found} 8 | end 9 | 10 | fn test_get_to_file 11 | file = set ./target/_duckscript_test/wget/page.html 12 | rm ${file} 13 | 14 | response_size = wget -O ${file} https://www.rust-lang.org/ 15 | 16 | response = readfile ${file} 17 | found = contains ${response} Rust 18 | 19 | assert ${found} 20 | assert ${response_size} 21 | end 22 | -------------------------------------------------------------------------------- /test/std/var/set_by_name_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_name_only 3 | name = set test 4 | assert_eq ${name} test 5 | 6 | value = set_by_name name 7 | defined = is_defined value 8 | assert_false ${defined} 9 | defined = is_defined name 10 | assert_false ${defined} 11 | end 12 | 13 | fn test_name_and_value 14 | name = set test 15 | assert_eq ${name} test 16 | 17 | value = set_by_name name new_value 18 | assert_eq ${name} new_value 19 | assert_eq ${value} new_value 20 | end 21 | 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/gitignore_path_array/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = gitignore_path_array path 3 | ``` 4 | 5 | Returns an array handle containing all path entries found from the provided root path that should be included based on the gitignore definitions. 6 | 7 | ### Parameters 8 | 9 | The root path. 10 | 11 | ### Return Value 12 | 13 | The array handle. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = gitignore_path_array ./src 19 | 20 | for path in ${handle} 21 | echo ${path} 22 | end 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/string_to_bytes/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = string_to_bytes text 3 | ``` 4 | 5 | Converts the provided string into binary format and returns a handle to the binary data. 6 | 7 | ### Parameters 8 | 9 | The text to convert. 10 | 11 | ### Return Value 12 | 13 | A handle to the binary data. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = string_to_bytes "hello world" 19 | text = bytes_to_string ${handle} 20 | 21 | release ${handle} 22 | 23 | assert_eq ${text} "hello world" 24 | ``` 25 | -------------------------------------------------------------------------------- /test/std/var/get_by_name_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_no_name 3 | value = get_by_name 4 | defined = is_defined value 5 | 6 | assert_false ${defined} 7 | end 8 | 9 | fn test_variable_not_found 10 | value = get_by_name notfound 11 | defined = is_defined value 12 | 13 | assert_false ${defined} 14 | end 15 | 16 | fn test_variable_found 17 | var = set test 18 | value = get_by_name var 19 | defined = is_defined value 20 | 21 | assert ${defined} 22 | assert_eq ${value} test 23 | end 24 | 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_get/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = array_get handle index 3 | ``` 4 | 5 | Returns the element from the array at a given index or none if the index is bigger than the array length. 6 | 7 | ### Parameters 8 | 9 | * The array handle. 10 | * The element index. 11 | 12 | ### Return Value 13 | 14 | The element at the given index from the array or none. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = array 1 2 3 20 | element = array_get ${handle} 2 21 | assert_eq ${element} 3 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_size/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = set_size handle 3 | ``` 4 | 5 | Returns the set size based on the provided set handle. 6 | 7 | ### Parameters 8 | 9 | The set handle. 10 | 11 | ### Return Value 12 | 13 | The set size. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = set 19 | 20 | result = set_put ${handle} 1 21 | result = set_put ${handle} 2 22 | result = set_put ${handle} 3 23 | 24 | result = set_size ${handle} 25 | assert_eq ${result} 3 26 | 27 | release ${handle} 28 | ``` 29 | -------------------------------------------------------------------------------- /test/std/collections/array_remove_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_array_with_data 3 | arr = array 1 2 3 4 | 5 | element = array_get ${arr} 0 6 | assert_eq ${element} 1 7 | 8 | result = array_remove ${arr} 0 9 | assert ${result} 10 | 11 | element = array_get ${arr} 0 12 | assert_eq ${element} 2 13 | 14 | result = array_remove ${arr} 1 15 | assert ${result} 16 | result = array_remove ${arr} 0 17 | assert ${result} 18 | 19 | empty = array_is_empty ${arr} 20 | assert ${empty} 21 | end 22 | -------------------------------------------------------------------------------- /test/std/fs/is_path_newer_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_valid 3 | dir = set ./target/_duckscript_test/fs/is_path_newer/ 4 | older = set "${dir}/older.txt" 5 | newer = set "${dir}/newer.txt" 6 | 7 | touch ${older} 8 | sleep 10 9 | touch ${newer} 10 | 11 | result = is_path_newer ${older} ${newer} 12 | assert_false ${result} 13 | 14 | result = is_path_newer ${newer} ${older} 15 | assert ${result} 16 | 17 | result = is_path_newer ${older} ${older} 18 | assert_false ${result} 19 | end 20 | 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_contains/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = array_contains handle value 3 | ``` 4 | 5 | Returns the first index of the array with the same value as provided.
6 | If not found, false will be returned. 7 | 8 | ### Parameters 9 | 10 | * The array handle. 11 | * The value 12 | 13 | ### Return Value 14 | 15 | The value index in the array or false if not found. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = array value1 value2 value3 21 | index = array_contains ${handle} value2 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_size/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = map_size handle 3 | ``` 4 | 5 | Returns the map size based on the provided map handle. 6 | 7 | ### Parameters 8 | 9 | The map handle. 10 | 11 | ### Return Value 12 | 13 | The map size. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = map 19 | 20 | result = map_put ${handle} a 1 21 | result = map_put ${handle} b 2 22 | result = map_put ${handle} c 3 23 | 24 | result = map_size ${handle} 25 | assert_eq ${result} 3 26 | 27 | release ${handle} 28 | ``` 29 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/read/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = read 3 | ``` 4 | 5 | Reads the user input into the output variable.
6 | If the user didn't insert any input, none will be returned. 7 | 8 | ### Parameters 9 | 10 | None 11 | 12 | ### Return Value 13 | 14 | The user input or none if no input was entered. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | echo Enter Full Name: 20 | name = read 21 | 22 | if is_empty ${name} 23 | echo You didn't enter any value 24 | else 25 | echo Your name is: ${name} 26 | end 27 | ``` 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/equals/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = eq value1 value2 3 | ``` 4 | 5 | Returns true if both provided values are equal. 6 | 7 | ### Parameters 8 | 9 | Two values to evaluate if they are equal 10 | 11 | ### Return Value 12 | 13 | **true** if equal. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | # valid conditions 19 | is_same = eq yes yes 20 | is_same = eq false false 21 | 22 | value = set "some text" 23 | is_same = eq ${value} "some text" 24 | 25 | # will return false 26 | is_same = eq 1 2 27 | ``` 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/set_mode/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = chmod mode path 3 | ``` 4 | 5 | This command will update the mode for the given path.
6 | **This command is currently only available for unix like systems and will return false for all others such as windows.** 7 | 8 | ### Parameters 9 | 10 | * The new mode, for example 755 11 | * The path 12 | 13 | ### Return Value 14 | 15 | The new mode as decimal number or false in case of any error. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | chmod 777 ./myfile.txt 21 | ``` 22 | -------------------------------------------------------------------------------- /test/std/string/base64_encode_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_encode 3 | handle = string_to_bytes "hello world" 4 | text = base64_encode ${handle} 5 | 6 | release ${handle} 7 | 8 | assert_eq ${text} aGVsbG8gd29ybGQ= 9 | end 10 | 11 | fn test_missing_input 12 | error = get_last_error 13 | empty = is_empty ${error} 14 | assert ${empty} 15 | 16 | result = base64_encode 17 | 18 | error = get_last_error 19 | empty = is_empty ${error} 20 | assert_false ${empty} 21 | 22 | assert_false ${result} 23 | end 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_to_properties/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | text = map_to_properties [--prefix prefix] handle 3 | ``` 4 | 5 | Converts the provided map to properties text. 6 | 7 | ### Parameters 8 | 9 | * Optional --prefix and the prefix value 10 | * The map handle. 11 | 12 | ### Return Value 13 | 14 | The properties text. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = map 20 | map_put ${handle} a 1 21 | map_put ${handle} b 2 22 | map_put ${handle} a.b.c 123 23 | 24 | text = map_to_properties ${handle} 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/glob_array/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = glob_array pattern 3 | ``` 4 | 5 | Returns an array handle containing all path entries found from the provided glob pattern.
6 | The pattern can be a relative path from current directory or an absolute path. 7 | 8 | ### Parameters 9 | 10 | The glob pattern. 11 | 12 | ### Return Value 13 | 14 | The array handle. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = glob_array ./somedir/**/*.txt 20 | 21 | for path in ${handle} 22 | echo ${path} 23 | end 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_concat/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = array_concat [handle]* 3 | ``` 4 | 5 | Concats all provided arrays and returns a handle to a new array with all items. 6 | 7 | ### Parameters 8 | 9 | Any number of array handles. 10 | 11 | ### Return Value 12 | 13 | A handle to the new array. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | input1 = range 1 4 19 | input2 = range 4 6 20 | input3 = range 6 8 21 | 22 | # new array will contain values from 1-7 23 | arr = array_concat ${input1} ${input2} ${input3} 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/echo/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | echo [arg]* 3 | ``` 4 | 5 | The echo command will printout all provided arguments.
6 | After all input is done, an end of line will be printed as well. 7 | 8 | ### Parameters 9 | 10 | Any number of arguments may be provided and will be printed. 11 | 12 | ### Return Value 13 | 14 | The amount of arguments printed. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | # Print multiple arguments: 20 | echo hello world 21 | 22 | # Print multiple spaces between words 23 | echo "hello world" 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/is_path_newer/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_path_provided() { 11 | test::run_script_and_error(vec![create("")], "out = is_path_newer", "out"); 12 | } 13 | 14 | #[test] 15 | fn run_not_found() { 16 | test::run_script_and_error( 17 | vec![create("")], 18 | "out = is_path_newer ./badpath ./Cargo.toml", 19 | "out", 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_put/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = map_put handle key value 3 | ``` 4 | 5 | Inserts a key-value pair into the map. 6 | 7 | ### Parameters 8 | 9 | * The map handle. 10 | * The key. 11 | * The new value. 12 | 13 | ### Return Value 14 | 15 | True if a new value was inserted. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = map 21 | 22 | result = map_put ${handle} key value 23 | assert_eq ${result} true 24 | 25 | value = map_get ${handle} key 26 | assert_eq ${value} value 27 | 28 | release ${handle} 29 | ``` 30 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/get_home_dir/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | let directory = home::home_dir().unwrap().to_string_lossy().into_owned(); 13 | test::run_script_and_validate( 14 | vec![create("")], 15 | "out = get_home_dir", 16 | CommandValidation::Match("out".to_string(), directory), 17 | ); 18 | } 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/replace/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = replace text from to 3 | ``` 4 | 5 | Returns new value of text after replacing all from values to the provided to values. 6 | 7 | ### Parameters 8 | 9 | * The full text 10 | * The from text 11 | * The to text 12 | 13 | ### Return Value 14 | 15 | The updated text. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | text = set "my large text value with lots of text" 21 | updated = replace ${text} text stuff 22 | 23 | assert_eq ${updated} "my large stuff value with lots of stuff" 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/utils/annotation.rs: -------------------------------------------------------------------------------- 1 | pub(crate) fn parse(string: &str) -> Option> { 2 | let modified_string = string.trim(); 3 | let length = modified_string.len(); 4 | if modified_string.starts_with("<") && modified_string.ends_with(">") && length > 2 { 5 | let end = length - 1; 6 | let values: Vec = modified_string[1..end] 7 | .split(',') 8 | .map(|item| item.to_string()) 9 | .collect(); 10 | 11 | Some(values) 12 | } else { 13 | None 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = map 3 | ``` 4 | 5 | Creates an empty map and returns a handle to that array.
6 | This handle can be passed to other commands which support maps using handles.
7 | Once the map is no longer used, it should be released using the **release** command. 8 | 9 | ### Parameters 10 | 11 | None 12 | 13 | ### Return Value 14 | 15 | A handle to the map. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = map 21 | 22 | # once done we should release the handle 23 | release ${handle} 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_get/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | value = map_get handle key 3 | ``` 4 | 5 | Returns a the value corresponding to the key from the map. 6 | 7 | ### Parameters 8 | 9 | * The map handle. 10 | * The key. 11 | 12 | ### Return Value 13 | 14 | The value corresponding to the key from the map. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = map 20 | 21 | result = map_put ${handle} key value 22 | assert_eq ${result} true 23 | 24 | value = map_get ${handle} key 25 | assert_eq ${value} value 26 | 27 | release ${handle} 28 | ``` 29 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/indexof/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = indexof full_text text_to_find 3 | ``` 4 | 5 | This command will attempt to find the text from the second argument inside the text in the first argument.
6 | If found, an index value will be returned, otherwise none is returned. 7 | 8 | ### Parameters 9 | 10 | * The text to search in 11 | * The text to find 12 | 13 | ### Return Value 14 | 15 | The index of the text found or none if not found. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | index = indexof " some text " some 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_clear/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = map_clear handle 3 | ``` 4 | 5 | Clears the provided map. 6 | 7 | ### Parameters 8 | 9 | The map handle. 10 | 11 | ### Return Value 12 | 13 | True if successful. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = map 19 | 20 | result = map_put ${handle} a 1 21 | 22 | result = map_is_empty ${handle} 23 | assert_false ${result} 24 | 25 | result map_clear ${handle} 26 | assert ${result} 27 | 28 | result = map_is_empty ${handle} 29 | assert ${result} 30 | 31 | release ${handle} 32 | ``` 33 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_clear/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = set_clear handle 3 | ``` 4 | 5 | Clears the provided set. 6 | 7 | ### Parameters 8 | 9 | The set handle. 10 | 11 | ### Return Value 12 | 13 | True if successful. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = set 19 | 20 | result = set_put ${handle} 1 21 | 22 | result = set_is_empty ${handle} 23 | assert_false ${result} 24 | 25 | result set_clear ${handle} 26 | assert ${result} 27 | 28 | result = set_is_empty ${handle} 29 | assert ${result} 30 | 31 | release ${handle} 32 | ``` 33 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/write_text/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = writefile file text 3 | ``` 4 | 5 | This command enables to write the provided text into the requested file.
6 | It will return true/false value based if it was able to write the text to the file. 7 | 8 | ### Parameters 9 | 10 | * The target file 11 | * The text content to write 12 | 13 | ### Return Value 14 | 15 | true/false based if it was able to write the text to the file. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | result = writefile ./target/tests/writefile.txt "line 1\nline 2" 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/lib/alias/mod.rs: -------------------------------------------------------------------------------- 1 | mod set; 2 | mod unset; 3 | 4 | use crate::utils::pckg; 5 | use duckscript::types::command::Commands; 6 | use duckscript::types::error::ScriptError; 7 | 8 | pub(crate) static ALIAS_STATE_KEY: &str = "ALIAS_STATE"; 9 | static PACKAGE: &str = "alias"; 10 | 11 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 12 | let package = pckg::concat(parent, PACKAGE); 13 | 14 | commands.set(set::create(&package))?; 15 | commands.set(unset::create(&package))?; 16 | 17 | Ok(()) 18 | } 19 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/contains/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = contains all partial 3 | ``` 4 | 5 | Returns true if the first argument contains the value of the second argument. 6 | 7 | ### Parameters 8 | 9 | * The full text to search in 10 | * The text to search for 11 | 12 | ### Return Value 13 | 14 | **true** if contains. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | # valid conditions 20 | result = contains abcd bc 21 | 22 | value = set "some text" 23 | result = contains ${value} "me tex" 24 | 25 | # will return false 26 | result = contains abcd b1c 27 | ``` 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/dump_variables/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | value = dump_variables 3 | ``` 4 | 5 | Returns all script variables in textual form. 6 | 7 | ### Parameters 8 | 9 | None 10 | 11 | ### Return Value 12 | 13 | The script variables. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | one = set 1 19 | two = set 2 20 | values = array 1 2 yes true 21 | numbers = range -5 15 22 | 23 | text = dump_variables 24 | found = contains ${text} two 25 | assert found 26 | found = contains ${text} 2 27 | assert found 28 | found = contains ${text} handle 29 | assert found 30 | ``` 31 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/base64_decode/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | text = base64_encode handle 3 | ``` 4 | 5 | Encodes using base64 the provided binary data and returns the encoded text value.
6 | The binary data is provided as a handle. 7 | 8 | ### Parameters 9 | 10 | The handle to the binary data to encode. 11 | 12 | ### Return Value 13 | 14 | The encoded textual value. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = string_to_bytes "hello world" 20 | text = base64_encode ${handle} 21 | 22 | release ${handle} 23 | 24 | assert_eq ${text} "hello world" 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/base64_encode/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | text = base64_encode handle 3 | ``` 4 | 5 | Encodes using base64 the provided binary data and returns the encoded text value.
6 | The binary data is provided as a handle. 7 | 8 | ### Parameters 9 | 10 | The handle to the binary data to encode. 11 | 12 | ### Return Value 13 | 14 | The encoded textual value. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = string_to_bytes "hello world" 20 | text = base64_encode ${handle} 21 | 22 | release ${handle} 23 | 24 | assert_eq ${text} "hello world" 25 | ``` 26 | -------------------------------------------------------------------------------- /test/std/collections/set_clear_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn clear_not_empty 3 | handle = set_new 1 2 3 4 | 5 | result = set_is_empty ${handle} 6 | assert_false ${result} 7 | 8 | result set_clear ${handle} 9 | assert ${result} 10 | 11 | result = set_is_empty ${handle} 12 | assert ${result} 13 | 14 | release ${handle} 15 | end 16 | 17 | fn clear_empty 18 | handle = set_new 19 | 20 | result set_clear ${handle} 21 | assert ${result} 22 | 23 | result = set_is_empty ${handle} 24 | assert ${result} 25 | 26 | release ${handle} 27 | end 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/noop/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate(vec![create("")], "out = noop", CommandValidation::None); 13 | } 14 | 15 | #[test] 16 | fn run_multiple_args() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | "out = noop 1 2 \"3 4\"", 20 | CommandValidation::None, 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /test/std/collections/array_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_array_with_data 3 | arr = array 1 2 3 4 | 5 | len = array_length ${arr} 6 | assert_eq ${len} 3 7 | 8 | isempty = array_is_empty ${arr} 9 | assert_false ${isempty} 10 | 11 | released = release ${arr} 12 | assert ${released} 13 | end 14 | 15 | fn test_array_no_data 16 | arr = array 17 | 18 | len = array_length ${arr} 19 | assert_eq ${len} 0 20 | 21 | isempty = array_is_empty ${arr} 22 | assert ${isempty} 23 | 24 | released = release ${arr} 25 | assert ${released} 26 | end 27 | -------------------------------------------------------------------------------- /test/std/net/ftp/ftp_put_in_memory_test.ds: -------------------------------------------------------------------------------- 1 | 2 | !include_files ../../../helper.ds 3 | 4 | fn test_auth_error 5 | if skip_unstable 6 | return 7 | end 8 | 9 | test_enabled = equals ${TEST_FTP_PUT} true 10 | 11 | if ${test_enabled} 12 | ftp_put_in_memory --host test.rebex.net --username demo --password password --remote-file readme2.txt --content "test content" 13 | 14 | assert_false ${result} 15 | last_error = get_last_error 16 | found = contains "${last_error}" 550 17 | assert ${found} 18 | end 19 | end 20 | 21 | -------------------------------------------------------------------------------- /duckscript/src/types/env_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | fn validate_env(env: &mut Env) { 4 | writeln!(env.out, "test").unwrap(); 5 | } 6 | 7 | #[test] 8 | fn env_default() { 9 | let mut env = Env::default(); 10 | 11 | validate_env(&mut env); 12 | } 13 | 14 | #[test] 15 | fn env_new_none() { 16 | let mut env = Env::new(None, None, None); 17 | 18 | validate_env(&mut env); 19 | } 20 | 21 | #[test] 22 | fn env_new_with_values() { 23 | let mut env = Env::new(Some(Box::new(stdout())), Some(Box::new(stdout())), None); 24 | 25 | validate_env(&mut env); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_clear/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = array_clear handle 3 | ``` 4 | 5 | Clears the provided array. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | True if successful. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = array 19 | 20 | result = array_push ${handle} 1 21 | 22 | result = array_is_empty ${handle} 23 | assert_false ${result} 24 | 25 | result array_clear ${handle} 26 | assert ${result} 27 | 28 | result = array_is_empty ${handle} 29 | assert ${result} 30 | 31 | release ${handle} 32 | ``` 33 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_remove/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | value = map_remove handle key 3 | ``` 4 | 5 | Removes a the value corresponding to the key from the map and returns it. 6 | 7 | ### Parameters 8 | 9 | * The map handle. 10 | * The key. 11 | 12 | ### Return Value 13 | 14 | The value corresponding to the key from the map. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = map 20 | 21 | result = map_put ${handle} key value 22 | assert_eq ${result} true 23 | 24 | value = map_remove ${handle} key 25 | assert_eq ${value} value 26 | 27 | release ${handle} 28 | ``` 29 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/cp/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = cp source target 3 | ``` 4 | 5 | This command copies the requested file or directory to the target location.
6 | If the source directory is not empty, its entire contents will be copied as well. 7 | 8 | ### Parameters 9 | 10 | * The source path to copy 11 | * The target path 12 | 13 | ### Return Value 14 | 15 | **true** if the path was copied. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | # copy a single file 21 | copied = cp ./file1.txt ./file2.txt 22 | 23 | # copy a directory 24 | copied = cp ./source ./target 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/dump_state/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::{ArrayCommand, CommandValidation}; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create(""), Box::new(ArrayCommand {})], 14 | r#" 15 | test_var = test_array 1 2 3 16 | out = dump_state 17 | "#, 18 | CommandValidation::Contains("out".to_string(), "3".to_string()), 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/hash/mod.rs: -------------------------------------------------------------------------------- 1 | mod digest; 2 | mod sha256sum; 3 | mod sha512sum; 4 | 5 | use crate::utils::pckg; 6 | use duckscript::types::command::Commands; 7 | use duckscript::types::error::ScriptError; 8 | 9 | static PACKAGE: &str = "hash"; 10 | 11 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 12 | let package = pckg::concat(parent, PACKAGE); 13 | 14 | commands.set(digest::create(&package))?; 15 | commands.set(sha256sum::create(&package)?)?; 16 | commands.set(sha512sum::create(&package)?)?; 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/semver/mod.rs: -------------------------------------------------------------------------------- 1 | mod is_equal; 2 | mod is_newer; 3 | mod parse; 4 | 5 | use crate::utils::pckg; 6 | use duckscript::types::command::Commands; 7 | use duckscript::types::error::ScriptError; 8 | 9 | static PACKAGE: &str = "semver"; 10 | 11 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 12 | let package = pckg::concat(parent, PACKAGE); 13 | 14 | commands.set(is_equal::create(&package))?; 15 | commands.set(is_newer::create(&package))?; 16 | commands.set(parse::create(&package))?; 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/ends_with/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = ends_with all partial 3 | ``` 4 | 5 | Returns true if the first argument ends with the value of the second argument. 6 | 7 | ### Parameters 8 | 9 | * The full text to search in 10 | * The suffix text to search for 11 | 12 | ### Return Value 13 | 14 | **true** if ends with. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | # valid conditions 20 | result = ends_with abcd abc 21 | 22 | value = set "some text" 23 | result = ends_with ${value} "me text" 24 | 25 | # will return false 26 | result = ends_with abcd abc 27 | ``` 28 | -------------------------------------------------------------------------------- /test/std/collections/range_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_range_with_data 3 | arr = range 0 10 4 | 5 | len = array_length ${arr} 6 | assert_eq ${len} 10 7 | 8 | isempty = array_is_empty ${arr} 9 | assert_false ${isempty} 10 | 11 | released = release ${arr} 12 | assert ${released} 13 | end 14 | 15 | fn test_range_no_data 16 | arr = range 0 0 17 | 18 | len = array_length ${arr} 19 | assert_eq ${len} 0 20 | 21 | isempty = array_is_empty ${arr} 22 | assert ${isempty} 23 | 24 | released = release ${arr} 25 | assert ${released} 26 | end 27 | -------------------------------------------------------------------------------- /test/std/net/ftp/ftp_get_test.ds: -------------------------------------------------------------------------------- 1 | 2 | !include_files ../../../helper.ds 3 | 4 | fn test_valid 5 | if skip_unstable 6 | return 7 | end 8 | 9 | filename = set ./target/_duckscript_test/net/ftp/get/readme.txt 10 | result = ftp_get --host test.rebex.net --username demo --password password --remote-file readme.txt --local-file ${filename} 11 | 12 | assert ${result} 13 | 14 | text = readfile ${filename} 15 | 16 | empty = is_empty ${text} 17 | assert_false ${empty} 18 | 19 | found = contains ${text} Welcome 20 | assert ${found} 21 | end 22 | 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/debug/dump_variables/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::{CommandValidation, SetCommand}; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create(""), Box::new(SetCommand {})], 14 | r#" 15 | test_var = test_set 1 16 | out = dump_variables 17 | "#, 18 | CommandValidation::Contains("out".to_string(), "test_var".to_string()), 19 | ); 20 | } 21 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/calc/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = calc", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_operation() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | "out = calc 1 + 5 * 7", 20 | CommandValidation::Match("out".to_string(), "36".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/starts_with/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = starts_with all partial 3 | ``` 4 | 5 | Returns true if the first argument starts with the value of the second argument. 6 | 7 | ### Parameters 8 | 9 | * The full text to search in 10 | * The prefix text to search for 11 | 12 | ### Return Value 13 | 14 | **true** if starts with. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | # valid conditions 20 | result = starts_with abcd abc 21 | 22 | value = set "some text" 23 | result = starts_with ${value} "some te" 24 | 25 | # will return false 26 | result = starts_with abcd bcd 27 | ``` 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set_remove/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | removed = set_remove handle value 3 | ``` 4 | 5 | Removes a the value from the set and returns true/false if it was removed. 6 | 7 | ### Parameters 8 | 9 | * The set handle. 10 | * The value to remove. 11 | 12 | ### Return Value 13 | 14 | True if the value was found and removed from the set. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | handle = set_new 20 | 21 | result = set_put ${handle} value 22 | assert_eq ${result} true 23 | 24 | removed = set_remove ${handle} value 25 | assert ${removed} 26 | 27 | release ${handle} 28 | ``` 29 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/hex_encode/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = hex_encode", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_valid() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | "out = hex_encode 255", 20 | CommandValidation::Match("out".to_string(), "0xff".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/scope/mod.rs: -------------------------------------------------------------------------------- 1 | pub(crate) mod clear; 2 | mod pop_stack; 3 | mod push_stack; 4 | 5 | use crate::utils::pckg; 6 | use duckscript::types::command::Commands; 7 | use duckscript::types::error::ScriptError; 8 | 9 | static PACKAGE: &str = "scope"; 10 | 11 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 12 | let package = pckg::concat(parent, PACKAGE); 13 | 14 | commands.set(clear::create(&package))?; 15 | commands.set(pop_stack::create(&package))?; 16 | commands.set(push_stack::create(&package))?; 17 | 18 | Ok(()) 19 | } 20 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_concat/script.ds: -------------------------------------------------------------------------------- 1 | 2 | for scope::array_concat::arg in ${scope::array_concat::arguments} 3 | if not is_array ${scope::array_concat::arg} 4 | trigger_error "Invalid input, non array handle or array not found." 5 | end 6 | end 7 | 8 | scope::array_concat::array = array 9 | 10 | for scope::array_concat::arg in ${scope::array_concat::arguments} 11 | for scope::array_concat::item in ${scope::array_concat::arg} 12 | array_push ${scope::array_concat::array} ${scope::array_concat::item} 13 | end 14 | end 15 | 16 | set ${scope::array_concat::array} 17 | -------------------------------------------------------------------------------- /test/std/string/trim_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_empty 3 | output = trim "" 4 | 5 | assert_eq ${output} "" 6 | end 7 | 8 | fn test_trimmed 9 | output = trim "test test" 10 | 11 | assert_eq ${output} "test test" 12 | end 13 | 14 | fn test_start_untrimmed 15 | output = trim " test test" 16 | 17 | assert_eq ${output} "test test" 18 | end 19 | 20 | fn test_end_untrimmed 21 | output = trim "test test " 22 | 23 | assert_eq ${output} "test test" 24 | end 25 | 26 | fn test_both_untrimmed 27 | output = trim " test test " 28 | 29 | assert_eq ${output} "test test" 30 | end 31 | -------------------------------------------------------------------------------- /test/std/var/get_all_var_names_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_with_values 3 | test1 = set 1 4 | test2 = set 2 5 | 6 | map_handle = map 7 | map_put ${map_handle} test1 1 8 | map_put ${map_handle} test2 1 9 | map_put ${map_handle} map_handle 1 10 | 11 | handle = get_all_var_names 12 | 13 | size = array_length ${handle} 14 | assert_eq 3 ${size} 15 | 16 | for name in ${handle} 17 | map_remove ${map_handle} ${name} 18 | end 19 | 20 | size = map_size ${map_handle} 21 | assert_eq 0 ${size} 22 | 23 | release ${map_handle} 24 | release ${handle} 25 | end 26 | 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/join_path/script.ds: -------------------------------------------------------------------------------- 1 | scope::join_path::added = set false 2 | 3 | for scope::join_path::path in ${scope::join_path::arguments} 4 | if ${scope::join_path::added} 5 | scope::join_path::output = set "${scope::join_path::output}/${scope::join_path::path}" 6 | else 7 | scope::join_path::output = set ${scope::join_path::path} 8 | scope::join_path::added = set true 9 | end 10 | end 11 | 12 | while contains ${scope::join_path::output} // 13 | scope::join_path::output = replace ${scope::join_path::output} // / 14 | end 15 | 16 | set ${scope::join_path::output} 17 | -------------------------------------------------------------------------------- /test/std/collections/set_from_array_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_valid 3 | arr = array 1 2 3 1 4 | 5 | handle = set_from_array ${arr} 6 | size = set_size ${handle} 7 | assert_eq ${size} 3 8 | 9 | result = set_contains ${handle} 1 10 | contained = not equals ${result} false 11 | assert ${contained} 12 | result = set_contains ${handle} 2 13 | contained = not equals ${result} false 14 | assert ${contained} 15 | result = set_contains ${handle} 3 16 | contained = not equals ${result} false 17 | assert ${contained} 18 | 19 | release ${handle} 20 | release ${arr} 21 | end 22 | -------------------------------------------------------------------------------- /test/std/debug/dump_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_dump 3 | one = set 1 4 | two = set 2 5 | values = array 1 2 yes true 6 | numbers = range -5 15 7 | 8 | text = dump_instructions 9 | found = contains ${text} -5 10 | assert found 11 | 12 | text = dump_variables 13 | found = contains ${text} two 14 | assert found 15 | found = contains ${text} 2 16 | assert found 17 | found = contains ${text} handle 18 | assert found 19 | 20 | text = dump_state 21 | found = contains ${text} yes 22 | assert found 23 | found = contains ${text} 7 24 | assert found 25 | end 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_load_properties/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = map_load_properties [--prefix prefix] handle text 3 | ``` 4 | 5 | Parsers and loads all properties to the provided map. 6 | 7 | ### Parameters 8 | 9 | * Optional --prefix and the prefix value 10 | * The map handle. 11 | * The properties text. 12 | 13 | ### Return Value 14 | 15 | True if successful. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = map 21 | 22 | result = map_put ${handle} key value 23 | assert_eq ${result} true 24 | 25 | value = map_get ${handle} key 26 | assert_eq ${value} value 27 | 28 | release ${handle} 29 | ``` 30 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/get_by_name/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = get_by_name name 3 | ``` 4 | 5 | This command returns the variable value based on the given variable name.
6 | It is similar to 7 | ```sh 8 | var = set ${name} 9 | ``` 10 | However, it allows for a dynamic variable name. 11 | 12 | ### Parameters 13 | 14 | The variable name. 15 | 16 | ### Return Value 17 | 18 | The variable value or none if no such variable exists. 19 | 20 | ### Examples 21 | 22 | ```sh 23 | var = set test 24 | value = get_by_name var 25 | defined = is_defined value 26 | 27 | assert ${defined} 28 | assert_eq ${value} test 29 | ``` 30 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_length/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = array_length handle 3 | ``` 4 | 5 | Returns the array length based on the provided array handle. 6 | 7 | ### Parameters 8 | 9 | The array handle. 10 | 11 | ### Return Value 12 | 13 | The array length. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = array a b c "d e" 19 | len = array_length ${handle} 20 | released = release ${handle} 21 | echo Array length: ${len} released: ${released} 22 | 23 | handle = range 0 10 24 | len = array_length ${handle} 25 | released = release ${handle} 26 | echo Array length: ${len} released: ${released} 27 | ``` 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/process/spawn/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | pid = spawn [--silent] [--input value] command [args]* 3 | ``` 4 | 5 | Executes the provided native command and arguments.
6 | It will not wait for the process to finish and will return the process pid. 7 | 8 | ### Parameters 9 | 10 | * Optional --silent flag to suppress any output. 11 | * --input - Optional content to be sent to the child process input stream. 12 | * The command to execute and its arguments. 13 | 14 | ### Return Value 15 | 16 | The process pid. 17 | 18 | ### Examples 19 | 20 | ```sh 21 | pid = spawn echo test 22 | 23 | echo PID: ${pid} 24 | ``` 25 | -------------------------------------------------------------------------------- /test/std/collections/array_clear_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn clear_not_empty 3 | handle = array 4 | 5 | result = array_push ${handle} 1 6 | 7 | result = array_is_empty ${handle} 8 | assert_false ${result} 9 | 10 | result = array_clear ${handle} 11 | assert ${result} 12 | 13 | result = array_is_empty ${handle} 14 | assert ${result} 15 | 16 | release ${handle} 17 | end 18 | 19 | fn clear_empty 20 | handle = array 21 | 22 | result = array_clear ${handle} 23 | assert ${result} 24 | 25 | result = array_is_empty ${handle} 26 | assert ${result} 27 | 28 | release ${handle} 29 | end 30 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/is_readonly/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_path_provided() { 12 | test::run_script_and_error(vec![create("")], "out = is_readonly", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_not_readonly() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | "out = is_readonly ./Cargo.toml", 20 | CommandValidation::Match("out".to_string(), "false".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/camelcase/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = camelcase", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_single_argument() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = camelcase "hello, world!""#, 20 | CommandValidation::Match("out".to_string(), "HelloWorld".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/lowercase/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = lowercase", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_single_argument() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = lowercase "Hello World""#, 20 | CommandValidation::Match("out".to_string(), "hello world".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/uppercase/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = uppercase", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_single_argument() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = uppercase "hello world""#, 20 | CommandValidation::Match("out".to_string(), "HELLO WORLD".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/basename/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_path_provided() { 12 | test::run_script_and_error(vec![create("")], "out = basename", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_provided() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | "out = basename ./target/_duckscript/file.txt", 20 | CommandValidation::Match("out".to_string(), "file.txt".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/kebabcase/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = kebabcase", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_single_argument() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = kebabcase "Hello, World!""#, 20 | CommandValidation::Match("out".to_string(), "hello-world".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/snakecase/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = snakecase", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_single_argument() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = snakecase "Hello, World!""#, 20 | CommandValidation::Match("out".to_string(), "hello_world".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /examples/debug.ds: -------------------------------------------------------------------------------- 1 | 2 | one = set 1 3 | two = set 2 4 | values = array 1 2 yes true 5 | numbers = range -5 15 6 | 7 | text = dump_instructions 8 | found = contains ${text} -5 9 | assert found 10 | echo Script Instructions: 11 | echo ${text} 12 | 13 | text = dump_variables 14 | found = contains ${text} two 15 | assert found 16 | found = contains ${text} 2 17 | assert found 18 | found = contains ${text} handle 19 | assert found 20 | echo Script Variables: 21 | echo ${text} 22 | 23 | text = dump_state 24 | found = contains ${text} yes 25 | assert found 26 | found = contains ${text} 7 27 | assert found 28 | echo Script State: 29 | echo ${text} 30 | -------------------------------------------------------------------------------- /test/std/collections/map_clear_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn clear_not_empty 3 | handle = map 4 | 5 | result = map_put ${handle} a 1 6 | 7 | result = map_is_empty ${handle} 8 | assert_false ${result} 9 | 10 | result map_clear ${handle} 11 | assert ${result} 12 | 13 | result = map_is_empty ${handle} 14 | assert ${result} 15 | 16 | release ${handle} 17 | end 18 | 19 | fn clear_empty 20 | handle = map 21 | 22 | result map_clear ${handle} 23 | assert ${result} 24 | 25 | result = map_is_empty ${handle} 26 | assert ${result} 27 | 28 | release ${handle} 29 | end 30 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/is_path_newer/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = is_path_newer newer older 3 | ``` 4 | 5 | This command will return true if the 'newer' path last modified time is after the 'older' path last modified time. 6 | 7 | ### Parameters 8 | 9 | * newer - The file/directory path to check. 10 | * older - The file/directory path to check. 11 | 12 | ### Return Value 13 | 14 | True if the 'newer' path last modified time is after the 'older' path last modified time. 15 | Otherwise or in case of an error, false will be returned. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | newer = is_path_newer ./new_file.txt ./old_file.txt 21 | ``` 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/set_mode_glob/script.ds: -------------------------------------------------------------------------------- 1 | 2 | scope::glob_chmod::handle = glob_array ${scope::glob_chmod::argument::2} 3 | scope::glob_chmod::output = array_length ${scope::glob_chmod::handle} 4 | 5 | for scope::glob_chmod::entry in ${scope::glob_chmod::handle} 6 | scope::glob_chmod::result = chmod ${scope::glob_chmod::argument::1} ${scope::glob_chmod::entry} 7 | 8 | if equals ${scope::glob_chmod::result} false 9 | release ${scope::glob_chmod::handle} 10 | scope::glob_chmod::output = set false 11 | end 12 | end 13 | 14 | release ${scope::glob_chmod::handle} 15 | 16 | set ${scope::glob_chmod::output} 17 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/semver/is_newer/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | output = semver_is_newer newer older 3 | ``` 4 | 5 | Returns true if both semver values are valid and first value is newer. 6 | 7 | ### Parameters 8 | 9 | * The expected newer value 10 | * The expected older value 11 | 12 | ### Return Value 13 | 14 | True if both semver values are valid and first value is newer, else false. 15 | 16 | ### Examples 17 | 18 | ```sh 19 | newer = semver_is_newer 3.2.3 2.2.3 20 | assert ${newer} 21 | 22 | newer = semver_is_newer 1.2.3 2.2.3 23 | assert_false ${newer} 24 | 25 | newer = semver_is_newer 1.2.3 1.2.3 26 | assert_false ${newer} 27 | ``` 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/trim/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate(vec![create("")], "out = trim", CommandValidation::None); 13 | } 14 | 15 | #[test] 16 | fn run_with_spaces() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = trim " some text " "#, 20 | CommandValidation::Match("out".to_string(), "some text".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /test/std/string/trim_end_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_empty 3 | output = trim_end "" 4 | 5 | assert_eq ${output} "" 6 | end 7 | 8 | fn test_trimmed 9 | output = trim_end "test test" 10 | 11 | assert_eq ${output} "test test" 12 | end 13 | 14 | fn test_start_untrimmed 15 | output = trim_end " test test" 16 | 17 | assert_eq ${output} " test test" 18 | end 19 | 20 | fn test_end_untrimmed 21 | output = trim_end "test test " 22 | 23 | assert_eq ${output} "test test" 24 | end 25 | 26 | fn test_both_untrimmed 27 | output = trim_end " test test " 28 | 29 | assert_eq ${output} " test test" 30 | end 31 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/os_family/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_valid() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = os_family", 15 | CommandValidation::Any( 16 | "out".to_string(), 17 | vec![ 18 | "windows".to_string(), 19 | "linux".to_string(), 20 | "mac".to_string(), 21 | ], 22 | ), 23 | ); 24 | } 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/lib/alias/unset/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | unalias name 3 | ``` 4 | 5 | Removes previously defined alias and return true/false based if an alias was actually removed. 6 | 7 | ### Parameters 8 | 9 | The alias name to remove. 10 | 11 | ### Return Value 12 | 13 | A true/false value in case an alias with the provided name existed. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | alias my_echo echo [ECHO] 19 | 20 | # This will print "[ECHO] hello world " 21 | my_echo hello world 22 | 23 | unalias my_echo 24 | 25 | # This will error 26 | echo The script will now error as my_echo is no longer defined 27 | my_echo hello world 28 | ``` 29 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/mod.rs: -------------------------------------------------------------------------------- 1 | mod ftp; 2 | mod hostname; 3 | mod http_client; 4 | mod wget; 5 | 6 | use crate::utils::pckg; 7 | use duckscript::types::command::Commands; 8 | use duckscript::types::error::ScriptError; 9 | 10 | static PACKAGE: &str = "net"; 11 | 12 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 13 | let package = pckg::concat(parent, PACKAGE); 14 | 15 | commands.set(hostname::create(&package))?; 16 | commands.set(http_client::create(&package))?; 17 | commands.set(wget::create(&package)?)?; 18 | 19 | ftp::load(commands, &package)?; 20 | 21 | Ok(()) 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/get_last_error/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::sdk::std::on_error::on_error; 3 | use crate::test; 4 | use crate::test::{CommandValidation, ErrorCommand}; 5 | 6 | #[test] 7 | fn common_functions() { 8 | test::test_common_command_functions(create("")); 9 | } 10 | 11 | #[test] 12 | fn run_no_args() { 13 | test::run_script_and_validate( 14 | vec![create(""), on_error::create(""), Box::new(ErrorCommand {})], 15 | r#" 16 | test_error 17 | out = get_last_error 18 | "#, 19 | CommandValidation::Match("out".to_string(), "test".to_string()), 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/write_bytes/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = write_binary_file file handle 3 | ``` 4 | 5 | This command enables to write binary data of the provided binary handle into the requested file.
6 | It will return true/false value based if it was able to write the binary data to the file. 7 | 8 | ### Parameters 9 | 10 | * The target file 11 | * The binary data handle 12 | 13 | ### Return Value 14 | 15 | true/false based if it was able to write the binary data to the file. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = string_to_bytes "some text" 21 | result = write_binary_file ./target/tests/data.bin ${handle} 22 | ``` 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/zip/unzip/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = unzip", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_only_zip_file() { 17 | test::run_script_and_error(vec![create("")], "out = unzip ./myfile.zip", "out"); 18 | } 19 | 20 | #[test] 21 | fn run_only_zip_file_not_exists() { 22 | test::run_script_and_error(vec![create("")], "out = unzip ./myfile.zip ./out", "out"); 23 | } 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/get_last_error_line/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::sdk::std::on_error::on_error; 3 | use crate::test; 4 | use crate::test::{CommandValidation, ErrorCommand}; 5 | 6 | #[test] 7 | fn common_functions() { 8 | test::test_common_command_functions(create("")); 9 | } 10 | 11 | #[test] 12 | fn run_no_args() { 13 | test::run_script_and_validate( 14 | vec![create(""), on_error::create(""), Box::new(ErrorCommand {})], 15 | r#" 16 | test_error 17 | out = get_last_error_line 18 | "#, 19 | CommandValidation::Match("out".to_string(), "2".to_string()), 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/on_error/get_last_error_source/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::sdk::std::on_error::on_error; 3 | use crate::test; 4 | use crate::test::{CommandValidation, ErrorCommand}; 5 | 6 | #[test] 7 | fn common_functions() { 8 | test::test_common_command_functions(create("")); 9 | } 10 | 11 | #[test] 12 | fn run_no_args() { 13 | test::run_script_and_validate( 14 | vec![create(""), on_error::create(""), Box::new(ErrorCommand {})], 15 | r#" 16 | test_error 17 | out = get_last_error_source 18 | "#, 19 | CommandValidation::Match("out".to_string(), "".to_string()), 20 | ); 21 | } 22 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/trim_end/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate(vec![create("")], "out = trim_end", CommandValidation::None); 13 | } 14 | 15 | #[test] 16 | fn run_with_spaces() { 17 | test::run_script_and_validate( 18 | vec![create("")], 19 | r#"out = trim_end " some text " "#, 20 | CommandValidation::Match("out".to_string(), " some text".to_string()), 21 | ); 22 | } 23 | -------------------------------------------------------------------------------- /test/std/collections/array_is_empty_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_size_empty 3 | handle = array 4 | 5 | result = array_is_empty ${handle} 6 | assert ${result} 7 | 8 | release ${handle} 9 | end 10 | 11 | fn test_size_emptied 12 | handle = array 13 | 14 | result = array_push ${handle} value 15 | assert_eq ${result} true 16 | array_pop ${handle} 17 | 18 | result = array_is_empty ${handle} 19 | assert ${result} 20 | release ${handle} 21 | end 22 | 23 | fn test_size_not_empty 24 | handle = array 1 2 3 25 | 26 | result = array_is_empty ${handle} 27 | assert_false ${result} 28 | 29 | release ${handle} 30 | end 31 | -------------------------------------------------------------------------------- /test/std/fs/chmod_test.ds: -------------------------------------------------------------------------------- 1 | 2 | windows = is_windows 3 | 4 | fn test_modify 5 | if not ${windows} 6 | file = set ./target/_duckscript_test/chmod/modify.txt 7 | touch ${file} 8 | 9 | value = chmod 777 ${file} 10 | readonly = is_readonly ${file} 11 | 12 | assert_eq ${value} 511 13 | assert_false ${readonly} 14 | 15 | value = chmod 444 ${file} 16 | readonly = is_readonly ${file} 17 | 18 | assert_eq ${value} 292 19 | assert ${readonly} 20 | end 21 | end 22 | 23 | fn test_not_exists 24 | value = chmod 777 ./target/test.txt 25 | 26 | assert_false ${value} 27 | end 28 | -------------------------------------------------------------------------------- /test/std/string/trim_start_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_empty 3 | output = trim_start "" 4 | 5 | assert_eq ${output} "" 6 | end 7 | 8 | fn test_trimmed 9 | output = trim_start "test test" 10 | 11 | assert_eq ${output} "test test" 12 | end 13 | 14 | fn test_start_untrimmed 15 | output = trim_start " test test" 16 | 17 | assert_eq ${output} "test test" 18 | end 19 | 20 | fn test_end_untrimmed 21 | output = trim_start "test test " 22 | 23 | assert_eq ${output} "test test " 24 | end 25 | 26 | fn test_both_untrimmed 27 | output = trim_start " test test " 28 | 29 | assert_eq ${output} "test test " 30 | end 31 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/set_current_directory/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | cd path 3 | ``` 4 | 5 | Sets the current directory based on the input path.
6 | If no path is provided, it will default to the user home directory.
7 | If the path does not exist, it will return none. 8 | 9 | ### Parameters 10 | 11 | The new current directory. 12 | 13 | ### Return Value 14 | 15 | The new current directory or none in case of any error such as target directory not found. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | # Move to user home directory and store the path in the home variable 21 | home = cd 22 | 23 | # Move to the requested directory 24 | cd ./scripts 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/set_by_name/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = set_by_name name [value] 3 | ``` 4 | 5 | This command sets the variable value based on the variable name.
6 | It is similar to 7 | ```sh 8 | name = set ${value} 9 | ``` 10 | However, it allows for a dynamic variable name. 11 | 12 | ### Parameters 13 | 14 | * The variable name. 15 | * The new variable value, if not provided, the variable will be unset. 16 | 17 | ### Return Value 18 | 19 | The new variable value. 20 | 21 | ### Examples 22 | 23 | ```sh 24 | var = set test 25 | value = get_by_name var 26 | defined = is_defined value 27 | 28 | assert ${defined} 29 | assert_eq ${value} test 30 | ``` 31 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/zip/unzip/help.md: -------------------------------------------------------------------------------- 1 | ``` 2 | unzip [target] 3 | ``` 4 | 5 | Unpacks the ZIP file into the `target` directory, if provided, or 6 | into current working directory otherwise. 7 | 8 | ### Parameters 9 | 10 | - zipfile - The path to the ZIP archive to be created. 11 | - target - The directory to unpack files into. If not provided, 12 | current working directory is used. 13 | 14 | ### Return value 15 | 16 | true if successful (i.e. the zip file exists and there are no existing file conflicts) 17 | 18 | ### Examples 19 | 20 | ```sh 21 | # ./stuff directory will be created automatically 22 | unzipped = unzip ./archive.zip ./stuff 23 | ``` 24 | -------------------------------------------------------------------------------- /test/std/collections/map_remove_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_remove 3 | handle = map 4 | 5 | result = map_put ${handle} key value 6 | assert_eq ${result} true 7 | 8 | value = map_remove ${handle} key 9 | assert_eq ${value} value 10 | 11 | release ${handle} 12 | end 13 | 14 | fn test_remove_twice 15 | handle = map 16 | 17 | result = map_put ${handle} key value 18 | assert_eq ${result} true 19 | 20 | value = map_remove ${handle} key 21 | assert_eq ${value} value 22 | value = map_remove ${handle} key 23 | defined = is_defined value 24 | assert_false ${defined} 25 | 26 | release ${handle} 27 | end 28 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/semver/is_equal/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = semver_is_equal", "out"); 12 | } 13 | 14 | #[test] 15 | fn run_single_arg() { 16 | test::run_script_and_error(vec![create("")], "out = semver_is_equal 1.2.3", "out"); 17 | } 18 | 19 | #[test] 20 | fn run_invalid_args() { 21 | test::run_script_and_error( 22 | vec![create("")], 23 | "out = semver_is_equal abc_123 123_test", 24 | "out", 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/semver/is_newer/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | 4 | #[test] 5 | fn common_functions() { 6 | test::test_common_command_functions(create("")); 7 | } 8 | 9 | #[test] 10 | fn run_no_args() { 11 | test::run_script_and_error(vec![create("")], "out = semver_is_newer", "out"); 12 | } 13 | 14 | #[test] 15 | fn run_single_arg() { 16 | test::run_script_and_error(vec![create("")], "out = semver_is_newer 1.2.3", "out"); 17 | } 18 | 19 | #[test] 20 | fn run_invalid_args() { 21 | test::run_script_and_error( 22 | vec![create("")], 23 | "out = semver_is_newer abc_123 123_test", 24 | "out", 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/fs/append/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = appendfile file text 3 | ``` 4 | 5 | This command enables to write the provided text into the requested file.
6 | It will return true/false value based if it was able to write the text to the file.
7 | In case the file doesn't exist, it will create it.
8 | If the file exists, it will append the text to it. 9 | 10 | ### Parameters 11 | 12 | * The target file 13 | * The text content to write 14 | 15 | ### Return Value 16 | 17 | true/false based if it was able to write the text to the file. 18 | 19 | ### Examples 20 | 21 | ```sh 22 | out = appendfile ./target/tests/writefile.txt "line 1\nline 2" 23 | ``` 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/last_indexof/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | var = last_indexof full_text text_to_find 3 | ``` 4 | 5 | This command will attempt to find the text from the second argument inside the text in the first argument.
6 | If found, an index value will be returned, otherwise none is returned.
7 | Unlike the **indexof** command, this command will search for text starting at the end, going backwards. 8 | 9 | ### Parameters 10 | 11 | * The text to search in 12 | * The text to find 13 | 14 | ### Return Value 15 | 16 | The index of the text found or none if not found. 17 | 18 | ### Examples 19 | 20 | ```sh 21 | index = last_indexof " some text " some 22 | ``` 23 | -------------------------------------------------------------------------------- /test/std/collections/set_remove_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_remove 3 | handle = set_new 4 | 5 | result = set_put ${handle} value 6 | assert_eq ${result} true 7 | 8 | removed = set_remove ${handle} value 9 | assert ${removed} 10 | 11 | empty = set_is_empty ${handle} 12 | assert ${empty} 13 | 14 | release ${handle} 15 | end 16 | 17 | fn test_remove_twice 18 | handle = set_new 19 | 20 | result = set_put ${handle} value 21 | assert_eq ${result} true 22 | 23 | removed = set_remove ${handle} value 24 | assert ${removed} 25 | removed = set_remove ${handle} value 26 | assert_false ${removed} 27 | 28 | release ${handle} 29 | end 30 | -------------------------------------------------------------------------------- /examples/on_error.ds: -------------------------------------------------------------------------------- 1 | 2 | # This will trigger an error 3 | echo Going to cause an error 4 | assert_error 5 | 6 | error = get_last_error 7 | echo Error Message: ${error} 8 | 9 | line = get_last_error_line 10 | echo Error Line: ${line} 11 | 12 | source = get_last_error_source 13 | echo Error Source File: ${source} 14 | 15 | # Get current state 16 | will_exit = exit_on_error 17 | echo Current state: ${will_exit} 18 | 19 | # Update the current state 20 | will_exit = exit_on_error true 21 | echo Current state: ${will_exit} 22 | 23 | # This will cause the script to exit 24 | echo Going to cause an error 25 | assert_error 26 | 27 | # We will not get to this line 28 | echo We should not be here 29 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/set/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = set_new value1 value2 value3 ... 3 | ``` 4 | 5 | Creates a new set from the input arguments and returns a handle to that set.
6 | This handle can be passed to other commands which support sets using handles.
7 | Once the set is no longer used, it should be released using the **release** command. 8 | 9 | ### Parameters 10 | 11 | Any number of arguments which will construct the set. 12 | 13 | ### Return Value 14 | 15 | A handle to the set. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = set_new ${var} "hello world" 5 ${another_var} 21 | 22 | # once done we should release the handle 23 | release ${handle} 24 | ``` 25 | -------------------------------------------------------------------------------- /test/std/net/ftp/ftp_put_test.ds: -------------------------------------------------------------------------------- 1 | 2 | !include_files ../../../helper.ds 3 | 4 | fn test_auth_error 5 | if skip_unstable 6 | return 7 | end 8 | 9 | test_enabled = equals ${TEST_FTP_PUT} true 10 | 11 | if ${test_enabled} 12 | filename = set ./target/_duckscript_test/net/ftp/put/readme.txt 13 | writefile ${filename} "test content" 14 | 15 | result = ftp_put --host test.rebex.net --username demo --password password --remote-file readme2.txt --local-file ${filename} 16 | 17 | assert_false ${result} 18 | last_error = get_last_error 19 | found = contains "${last_error}" 550 20 | assert ${found} 21 | end 22 | end 23 | 24 | -------------------------------------------------------------------------------- /test/std/string/base64_decode_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_encode_decode 3 | handle = string_to_bytes "hello world" 4 | text = base64_encode ${handle} 5 | release ${handle} 6 | 7 | assert_eq ${text} aGVsbG8gd29ybGQ= 8 | 9 | handle = base64_decode ${text} 10 | text = bytes_to_string ${handle} 11 | release ${handle} 12 | 13 | assert_eq ${text} "hello world" 14 | end 15 | 16 | fn test_missing_input 17 | error = get_last_error 18 | empty = is_empty ${error} 19 | assert ${empty} 20 | 21 | result = base64_decode 22 | 23 | error = get_last_error 24 | empty = is_empty ${error} 25 | assert_false ${empty} 26 | 27 | assert_false ${result} 28 | end 29 | -------------------------------------------------------------------------------- /test/std/string/contains_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_prefix 3 | output = contains "1 2 3 4 5" "1 2" 4 | 5 | assert ${output} 6 | end 7 | 8 | fn test_suffix 9 | output = contains "1 2 3 4 5" "4 5" 10 | 11 | assert ${output} 12 | end 13 | 14 | fn test_middle 15 | output = contains "1 2 3 4 5" "2 3" 16 | 17 | assert ${output} 18 | end 19 | 20 | fn test_all 21 | output = contains "1 2 3 4 5" "1 2 3 4 5" 22 | 23 | assert ${output} 24 | end 25 | 26 | fn test_empty 27 | output = contains "1 2 3 4 5" "" 28 | 29 | assert ${output} 30 | end 31 | 32 | fn test_not_contained 33 | output = contains "1 2 3 4 5" "4 5 6" 34 | 35 | assert_false ${output} 36 | end 37 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/echo/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = echo", 15 | CommandValidation::Match("out".to_string(), "0".to_string()), 16 | ); 17 | } 18 | 19 | #[test] 20 | fn run_multiple_args() { 21 | test::run_script_and_validate( 22 | vec![create("")], 23 | "out = echo 1 2 \"3 4\"", 24 | CommandValidation::Match("out".to_string(), "3".to_string()), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/math/hex_decode/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::sdk::std::math::calc; 3 | use crate::test; 4 | use crate::test::CommandValidation; 5 | 6 | #[test] 7 | fn common_functions() { 8 | test::test_common_command_functions(create("")); 9 | } 10 | 11 | #[test] 12 | fn run_no_args() { 13 | test::run_script_and_error(vec![create("")], "out = hex_decode", "out"); 14 | } 15 | 16 | #[test] 17 | fn run_valid() { 18 | test::run_script_and_validate( 19 | vec![create(""), calc::create("")], 20 | r#" 21 | num = hex_decode 0xFF 22 | out = calc ${num} + 1 23 | "#, 24 | CommandValidation::Match("out".to_string(), "256".to_string()), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/test/assert_eq/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | assert_eq value1 value2 [error message] 3 | ``` 4 | 5 | Used to validate the input is the same.
6 | If they are not, the command will exist with an error. 7 | 8 | ### Parameters 9 | 10 | * Two values to evaluate if they are equal 11 | * Optional error message 12 | 13 | ### Return Value 14 | 15 | **true** if equal. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | # valid conditions 21 | assert_eq yes yes 22 | assert_eq false false 23 | 24 | value = set "some text" 25 | assert_eq ${value} "some text" 26 | 27 | # error conditions (each one will break the execution) 28 | assert_eq 1 2 29 | assert_eq 1 2 "This is my error message" 30 | ``` 31 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = array value1 value2 value3 ... 3 | ``` 4 | 5 | Creates an array from the input arguments and returns a handle to that array.
6 | This handle can be passed to other commands which support arrays using handles.
7 | Once the array is no longer used, it should be released using the **release** command. 8 | 9 | ### Parameters 10 | 11 | Any number of arguments which will construct the array. 12 | 13 | ### Return Value 14 | 15 | A handle to the array. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | handle = array ${var} "hello world" 5 ${another_var} 21 | 22 | # once done we should release the handle 23 | release ${handle} 24 | ``` 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/help.md: -------------------------------------------------------------------------------- 1 | The collections module contains commands which enable to interact with different data models such as arrays, sets and maps. 2 | 3 | * Arrays are simple ordered list of items 4 | * Sets are unordered unique collection of items 5 | * Maps are key/value (dictionary) structure where the keys are unique 6 | 7 | Access to these data structures are done via handles.
8 | Handles are provided by the data structure creation command (such as: array, range, map, set) and are used in all 9 | other commands to read/modify those data structures.
10 | Once done with a specific data structure, you must release it via release command to prevent any memory leaks. 11 | 12 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/print/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = print", 15 | CommandValidation::Match("out".to_string(), "0".to_string()), 16 | ); 17 | } 18 | 19 | #[test] 20 | fn run_multiple_args() { 21 | test::run_script_and_validate( 22 | vec![create("")], 23 | "out = print 1 2 \"3 4\"", 24 | CommandValidation::Match("out".to_string(), "3".to_string()), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /examples/for_in.ds: -------------------------------------------------------------------------------- 1 | 2 | # Simple example iteration over the list of letters: 3 | args = array a b c 4 | 5 | for arg in ${args} 6 | echo current arg is: ${arg} 7 | end 8 | 9 | released = release ${args} 10 | echo Array released: ${released} 11 | 12 | # Example nested loops: 13 | values = array 1 2 3 14 | for i in ${values} 15 | for j in ${values} 16 | echo i: ${i} j: ${j} 17 | end 18 | end 19 | 20 | released = release ${values} 21 | echo Array released: ${released} 22 | 23 | values = range 1 10 24 | 25 | for i in ${values} 26 | for j in ${values} 27 | echo i: ${i} j: ${j} 28 | end 29 | end 30 | 31 | released = release ${values} 32 | echo Array released: ${released} 33 | -------------------------------------------------------------------------------- /test/std/string/equals_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_prefix 3 | output = equals "1 2 3 4 5" "1 2" 4 | 5 | assert_false ${output} 6 | end 7 | 8 | fn test_suffix 9 | output = equals "1 2 3 4 5" "4 5" 10 | 11 | assert_false ${output} 12 | end 13 | 14 | fn test_middle 15 | output = equals "1 2 3 4 5" "2 3" 16 | 17 | assert_false ${output} 18 | end 19 | 20 | fn test_all 21 | output = equals "1 2 3 4 5" "1 2 3 4 5" 22 | 23 | assert ${output} 24 | end 25 | 26 | fn test_empty 27 | output = equals "1 2 3 4 5" "" 28 | 29 | assert_false ${output} 30 | end 31 | 32 | fn test_not_contained 33 | output = equals "1 2 3 4 5" "4 5 6" 34 | 35 | assert_false ${output} 36 | end 37 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/println/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = println", 15 | CommandValidation::Match("out".to_string(), "0".to_string()), 16 | ); 17 | } 18 | 19 | #[test] 20 | fn run_multiple_args() { 21 | test::run_script_and_validate( 22 | vec![create("")], 23 | "out = println 1 2 \"3 4\"", 24 | CommandValidation::Match("out".to_string(), "3".to_string()), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/scope/push_stack/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | scope_push_stack [--copy name1 name2 ...] 3 | ``` 4 | 5 | Removes all known variables except for the variables provided by the optional --copy argument.
6 | Functions with the **** annotation will automatically invoke this command and keep only the relevant 7 | function arguments in the new scope. 8 | 9 | ### Parameters 10 | 11 | Optional variable names to keep. 12 | 13 | ### Return Value 14 | 15 | None. 16 | 17 | ### Examples 18 | 19 | ```sh 20 | var1 = set 1 21 | var2 = set 2 22 | 23 | scope_push_stack --copy var2 24 | 25 | defined = is_defined var1 26 | echo ${defined} 27 | defined = is_defined var2 28 | echo ${defined} 29 | ``` 30 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/string/trim_start/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_validate( 13 | vec![create("")], 14 | "out = trim_start", 15 | CommandValidation::None, 16 | ); 17 | } 18 | 19 | #[test] 20 | fn run_with_spaces() { 21 | test::run_script_and_validate( 22 | vec![create("")], 23 | r#"out = trim_start " some text " "#, 24 | CommandValidation::Match("out".to_string(), "some text ".to_string()), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /test/std/string/ends_with_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_prefix 3 | output = ends_with "1 2 3 4 5" "1 2" 4 | 5 | assert_false ${output} 6 | end 7 | 8 | fn test_suffix 9 | output = ends_with "1 2 3 4 5" "4 5" 10 | 11 | assert ${output} 12 | end 13 | 14 | fn test_middle 15 | output = ends_with "1 2 3 4 5" "2 3" 16 | 17 | assert_false ${output} 18 | end 19 | 20 | fn test_all 21 | output = ends_with "1 2 3 4 5" "1 2 3 4 5" 22 | 23 | assert ${output} 24 | end 25 | 26 | fn test_empty 27 | output = ends_with "1 2 3 4 5" "" 28 | 29 | assert ${output} 30 | end 31 | 32 | fn test_not_contained 33 | output = ends_with "1 2 3 4 5" "4 5 6" 34 | 35 | assert_false ${output} 36 | end 37 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/json/mod.rs: -------------------------------------------------------------------------------- 1 | mod encode; 2 | mod parse; 3 | 4 | use crate::types::command::create_doc_only_command; 5 | use crate::utils::pckg; 6 | use duckscript::types::command::Commands; 7 | use duckscript::types::error::ScriptError; 8 | 9 | static PACKAGE: &str = "json"; 10 | 11 | pub(crate) static OBJECT_VALUE: &str = "[OBJECT]"; 12 | 13 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 14 | let package = pckg::concat(parent, PACKAGE); 15 | 16 | commands.set(create_doc_only_command(&package, include_str!("help.md")))?; 17 | 18 | commands.set(encode::create(&package))?; 19 | commands.set(parse::create(&package))?; 20 | 21 | Ok(()) 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/process/mod.rs: -------------------------------------------------------------------------------- 1 | mod exec; 2 | mod exit; 3 | mod process_id; 4 | mod spawn; 5 | mod watchdog; 6 | 7 | use crate::utils::pckg; 8 | use duckscript::types::command::Commands; 9 | use duckscript::types::error::ScriptError; 10 | 11 | static PACKAGE: &str = "process"; 12 | 13 | pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> { 14 | let package = pckg::concat(parent, PACKAGE); 15 | 16 | commands.set(exec::create(&package))?; 17 | commands.set(exit::create(&package))?; 18 | commands.set(process_id::create(&package))?; 19 | commands.set(spawn::create(&package))?; 20 | commands.set(watchdog::create(&package))?; 21 | 22 | Ok(()) 23 | } 24 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/internal/sdkdocs/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_file_provided() { 12 | test::run_script_and_error( 13 | vec![create("internal")], 14 | "out = internal::SDKDocsGen", 15 | "out", 16 | ); 17 | } 18 | 19 | #[test] 20 | fn run_valid() { 21 | test::run_script_and_validate( 22 | vec![create("internal")], 23 | "out = internal::SDKDocsGen ./target/temp.md", 24 | CommandValidation::Match("out".to_string(), "./target/temp.md".to_string()), 25 | ); 26 | } 27 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/array_remove/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | result = array_remove handle index 3 | ``` 4 | 5 | Removes the item from the array at the given index.
6 | If the array is not found or the index is greater than the array size, this command will return false.
7 | Otherwise it will return true. 8 | 9 | ### Parameters 10 | 11 | * The array handle. 12 | * The element index. 13 | 14 | ### Return Value 15 | 16 | True if successful. 17 | 18 | ### Examples 19 | 20 | ```sh 21 | arr = array old 22 | 23 | element = array_get ${arr} 0 24 | assert_eq ${element} old 25 | 26 | result = array_remove ${arr} 0 27 | assert ${result} 28 | 29 | empty = array_is_empty ${arr} 30 | assert ${empty} 31 | ``` 32 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/range/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | handle = range start end 3 | ``` 4 | 5 | Creates an array from the input start and end range values and returns a handle to that array.
6 | This handle can be passed to other commands which support arrays using handles.
7 | Once the array is no longer used, it should be released using the **release** command. 8 | 9 | ### Parameters 10 | 11 | * The start numeric value 12 | * The end numeric value which cannot be smaller than the start value. 13 | 14 | ### Return Value 15 | 16 | A handle to the array. 17 | 18 | ### Examples 19 | 20 | ```sh 21 | handle = range 1 10 22 | 23 | # once done we should release the handle 24 | release ${handle} 25 | ``` 26 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/wget/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::types::command::create_alias_command; 2 | use crate::utils::pckg; 3 | use duckscript::types::command::Command; 4 | use duckscript::types::error::ScriptError; 5 | 6 | #[cfg(test)] 7 | #[path = "./mod_test.rs"] 8 | mod mod_test; 9 | 10 | pub(crate) fn create(package: &str) -> Result, ScriptError> { 11 | let name = pckg::concat(package, "WGet"); 12 | let command = create_alias_command( 13 | name, 14 | vec!["wget".to_string()], 15 | include_str!("help.md").to_string(), 16 | "wget".to_string(), 17 | include_str!("script.ds").to_string(), 18 | 1, 19 | )?; 20 | 21 | Ok(Box::new(command)) 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/collections/map_keys/help.md: -------------------------------------------------------------------------------- 1 | ```sh 2 | keys = map_keys handle 3 | ``` 4 | 5 | Returns a handle to an array holding all keys in the provided map handle. 6 | 7 | ### Parameters 8 | 9 | * The map handle. 10 | 11 | ### Return Value 12 | 13 | A handle to an array holding all map keys. 14 | 15 | ### Examples 16 | 17 | ```sh 18 | handle = map 19 | 20 | result = map_put ${handle} key1 value1 21 | assert_eq ${result} true 22 | result = map_put ${handle} key2 value2 23 | assert_eq ${result} true 24 | 25 | keys = map_keys ${handle} 26 | for key in ${keys} 27 | value = map_get ${handle} ${key} 28 | echo Key: ${key} Value: ${value} 29 | end 30 | 31 | release ${handle} 32 | release ${keys} 33 | ``` 34 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/env/uname/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::types::command::create_alias_command; 2 | use crate::utils::pckg; 3 | use duckscript::types::command::Command; 4 | use duckscript::types::error::ScriptError; 5 | 6 | #[cfg(test)] 7 | #[path = "./mod_test.rs"] 8 | mod mod_test; 9 | 10 | pub(crate) fn create(package: &str) -> Result, ScriptError> { 11 | let name = pckg::concat(package, "UName"); 12 | let command = create_alias_command( 13 | name, 14 | vec!["uname".to_string()], 15 | include_str!("help.md").to_string(), 16 | "uname".to_string(), 17 | include_str!("script.ds").to_string(), 18 | 0, 19 | )?; 20 | 21 | Ok(Box::new(command)) 22 | } 23 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/ftp/list/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | use crate::test; 3 | use crate::test::CommandValidation; 4 | 5 | #[test] 6 | fn common_functions() { 7 | test::test_common_command_functions(create("")); 8 | } 9 | 10 | #[test] 11 | fn run_no_args() { 12 | test::run_script_and_error(vec![create("")], "out = ftp_list", "out"); 13 | } 14 | 15 | #[test] 16 | fn run_valid() { 17 | if !test::skip_unstable() { 18 | test::run_script_and_validate( 19 | vec![create("")], 20 | "out = ftp_list --host test.rebex.net --username demo --password password", 21 | CommandValidation::Contains("out".to_string(), "handle:".to_string()), 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/var/unset/mod.rs: -------------------------------------------------------------------------------- 1 | use crate::types::command::create_alias_command; 2 | use crate::utils::pckg; 3 | use duckscript::types::command::Command; 4 | use duckscript::types::error::ScriptError; 5 | 6 | #[cfg(test)] 7 | #[path = "./mod_test.rs"] 8 | mod mod_test; 9 | 10 | pub(crate) fn create(package: &str) -> Result, ScriptError> { 11 | let name = pckg::concat(package, "Unset"); 12 | let command = create_alias_command( 13 | name, 14 | vec!["unset".to_string()], 15 | include_str!("help.md").to_string(), 16 | "unset".to_string(), 17 | include_str!("script.ds").to_string(), 18 | 0, 19 | )?; 20 | 21 | Ok(Box::new(command)) 22 | } 23 | -------------------------------------------------------------------------------- /test/std/string/starts_with_test.ds: -------------------------------------------------------------------------------- 1 | 2 | fn test_prefix 3 | output = starts_with "1 2 3 4 5" "1 2" 4 | 5 | assert ${output} 6 | end 7 | 8 | fn test_suffix 9 | output = starts_with "1 2 3 4 5" "4 5" 10 | 11 | assert_false ${output} 12 | end 13 | 14 | fn test_middle 15 | output = starts_with "1 2 3 4 5" "2 3" 16 | 17 | assert_false ${output} 18 | end 19 | 20 | fn test_all 21 | output = starts_with "1 2 3 4 5" "1 2 3 4 5" 22 | 23 | assert ${output} 24 | end 25 | 26 | fn test_empty 27 | output = starts_with "1 2 3 4 5" "" 28 | 29 | assert ${output} 30 | end 31 | 32 | fn test_not_contained 33 | output = starts_with "1 2 3 4 5" "4 5 6" 34 | 35 | assert_false ${output} 36 | end 37 | -------------------------------------------------------------------------------- /duckscript_sdk/src/sdk/std/net/ftp/nlst/mod_test.rs: -------------------------------------------------------------------------------- 1 | use super::*; 2 | 3 | use crate::test; 4 | use crate::test::CommandValidation; 5 | 6 | #[test] 7 | fn common_functions() { 8 | test::test_common_command_functions(create("")); 9 | } 10 | 11 | #[test] 12 | fn run_no_args() { 13 | test::run_script_and_error(vec![create("")], "out = ftp_nlst", "out"); 14 | } 15 | 16 | #[test] 17 | fn run_valid() { 18 | if !test::skip_unstable() { 19 | test::run_script_and_validate( 20 | vec![create("")], 21 | "out = ftp_nlst --host test.rebex.net --username demo --password password", 22 | CommandValidation::Contains("out".to_string(), "handle:".to_string()), 23 | ); 24 | } 25 | } 26 | --------------------------------------------------------------------------------