duckscript/docs/sdk.md

7240 lines
140 KiB
Markdown
Raw Normal View History

2019-12-30 10:45:28 +00:00
# Table of Contents
2021-09-21 13:43:23 +00:00
* [`std::Echo` (echo)](#std__Echo)
* [`std::Eval` (eval)](#std__Eval)
* [`std::IsCommandDefined` (is_command_defined)](#std__IsCommandDefined)
* [`std::Noop` (noop)](#std__Noop)
* [`std::Not` (not)](#std__Not)
* [`std::Print` (print)](#std__Print)
* [`std::Println` (println)](#std__Println)
2021-09-21 13:43:23 +00:00
* [`std::ReadUserInput` (read)](#std__ReadUserInput)
* [`std::Release` (release)](#std__Release)
* [`std::ShowCommandDocumentation` (man)](#std__ShowCommandDocumentation)
* [`std::collections`](#std__collections)
* [`std::collections::Array` (array)](#std__collections__Array)
* [`std::collections::ArrayClear` (array_clear)](#std__collections__ArrayClear)
* [`std::collections::ArrayConcat` (array_concat)](#std__collections__ArrayConcat)
* [`std::collections::ArrayContains` (array_contains)](#std__collections__ArrayContains)
* [`std::collections::ArrayGet` (array_get)](#std__collections__ArrayGet)
* [`std::collections::ArrayIsEmpty` (array_is_empty)](#std__collections__ArrayIsEmpty)
* [`std::collections::ArrayJoin` (array_join)](#std__collections__ArrayJoin)
* [`std::collections::ArrayLength` (array_length, arrlen, array_size)](#std__collections__ArrayLength)
* [`std::collections::ArrayPop` (array_pop)](#std__collections__ArrayPop)
* [`std::collections::ArrayPush` (array_push, array_add, array_put)](#std__collections__ArrayPush)
* [`std::collections::ArrayRemove` (array_remove)](#std__collections__ArrayRemove)
* [`std::collections::ArraySet` (array_set)](#std__collections__ArraySet)
* [`std::collections::IsArray` (is_array)](#std__collections__IsArray)
* [`std::collections::IsMap` (is_map)](#std__collections__IsMap)
* [`std::collections::IsSet` (is_set)](#std__collections__IsSet)
* [`std::collections::Map` (map)](#std__collections__Map)
* [`std::collections::MapClear` (map_clear)](#std__collections__MapClear)
* [`std::collections::MapContainsKey` (map_contains_key)](#std__collections__MapContainsKey)
* [`std::collections::MapContainsValue` (map_contains_value)](#std__collections__MapContainsValue)
* [`std::collections::MapGet` (map_get)](#std__collections__MapGet)
* [`std::collections::MapIsEmpty` (map_is_empty)](#std__collections__MapIsEmpty)
* [`std::collections::MapKeys` (map_keys)](#std__collections__MapKeys)
* [`std::collections::MapLoadProperties` (map_load_properties)](#std__collections__MapLoadProperties)
* [`std::collections::MapPut` (map_put, map_add)](#std__collections__MapPut)
* [`std::collections::MapRemove` (map_remove)](#std__collections__MapRemove)
* [`std::collections::MapSize` (map_size)](#std__collections__MapSize)
* [`std::collections::MapToProperties` (map_to_properties)](#std__collections__MapToProperties)
* [`std::collections::Range` (range)](#std__collections__Range)
* [`std::collections::ReadProperties` (read_properties)](#std__collections__ReadProperties)
* [`std::collections::Set` (set_new)](#std__collections__Set)
* [`std::collections::SetClear` (set_clear)](#std__collections__SetClear)
* [`std::collections::SetContains` (set_contains)](#std__collections__SetContains)
* [`std::collections::SetFromArray` (set_from_array)](#std__collections__SetFromArray)
* [`std::collections::SetIsEmpty` (set_is_empty)](#std__collections__SetIsEmpty)
* [`std::collections::SetPut` (set_put, set_add)](#std__collections__SetPut)
* [`std::collections::SetRemove` (set_remove)](#std__collections__SetRemove)
* [`std::collections::SetSize` (set_size)](#std__collections__SetSize)
* [`std::collections::SetToArray` (set_to_array)](#std__collections__SetToArray)
* [`std::collections::WriteProperties` (write_properties)](#std__collections__WriteProperties)
* [`std::debug::DuckscriptSDKVersion` (duckscript_sdk_version)](#std__debug__DuckscriptSDKVersion)
* [`std::debug::DuckscriptVersion` (duckscript_version)](#std__debug__DuckscriptVersion)
* [`std::debug::DumpInstructions` (dump_instructions)](#std__debug__DumpInstructions)
* [`std::debug::DumpState` (dump_state)](#std__debug__DumpState)
* [`std::debug::DumpVariables` (dump_variables)](#std__debug__DumpVariables)
* [`std::env::EnvToMap` (env_to_map)](#std__env__EnvToMap)
* [`std::env::FindExecutable` (which)](#std__env__FindExecutable)
* [`std::env::GetCpuCount` (cpu_count, get_cpu_count)](#std__env__GetCpuCount)
* [`std::env::GetHomeDirectory` (get_home_dir)](#std__env__GetHomeDirectory)
* [`std::env::GetOSFamily` (os_family)](#std__env__GetOSFamily)
* [`std::env::GetOSName` (os_name)](#std__env__GetOSName)
* [`std::env::GetOSRelease` (os_release)](#std__env__GetOSRelease)
* [`std::env::GetOSVersion` (os_version)](#std__env__GetOSVersion)
* [`std::env::GetUserName` (whoami, get_user_name)](#std__env__GetUserName)
* [`std::env::GetVar` (get_env)](#std__env__GetVar)
* [`std::env::IsWindows` (is_windows)](#std__env__IsWindows)
* [`std::env::PrintCurrentDirectory` (pwd, print_current_directory)](#std__env__PrintCurrentDirectory)
* [`std::env::PrintEnv` (print_env, printenv)](#std__env__PrintEnv)
* [`std::env::SetCurrentDirectory` (cd, set_current_dir, set_current_directory)](#std__env__SetCurrentDirectory)
* [`std::env::SetVar` (set_env)](#std__env__SetVar)
* [`std::env::UName` (uname)](#std__env__UName)
* [`std::env::UnsetVar` (unset_env)](#std__env__UnsetVar)
* [`std::error::GetLastError` (get_last_error)](#std__error__GetLastError)
* [`std::error::GetLastErrorLine` (get_last_error_line)](#std__error__GetLastErrorLine)
* [`std::error::GetLastErrorSource` (get_last_error_source)](#std__error__GetLastErrorSource)
* [`std::error::SetError` (set_error)](#std__error__SetError)
* [`std::error::SetExitOnError` (exit_on_error, set_exit_on_error)](#std__error__SetExitOnError)
* [`std::error::TriggerError` (trigger_error)](#std__error__TriggerError)
* [`std::flowcontrol::ForIn` (for)](#std__flowcontrol__ForIn)
* [`std::flowcontrol::Function` (function, fn)](#std__flowcontrol__Function)
* [`std::flowcontrol::GoTo` (goto)](#std__flowcontrol__GoTo)
* [`std::flowcontrol::If` (if)](#std__flowcontrol__If)
* [`std::flowcontrol::While` (while)](#std__flowcontrol__While)
* [`std::fs::Append` (appendfile)](#std__fs__Append)
* [`std::fs::CPGlob` (glob_cp, cp_glob)](#std__fs__CPGlob)
* [`std::fs::CopyPath` (cp)](#std__fs__CopyPath)
* [`std::fs::CreateDirectory` (mkdir)](#std__fs__CreateDirectory)
* [`std::fs::CreateEmptyFile` (touch)](#std__fs__CreateEmptyFile)
* [`std::fs::DeleteEmptyDirectory` (rmdir)](#std__fs__DeleteEmptyDirectory)
* [`std::fs::DeletePath` (rm)](#std__fs__DeletePath)
* [`std::fs::Exists` (is_path_exists)](#std__fs__Exists)
* [`std::fs::GetCanonicalPath` (canonicalize)](#std__fs__GetCanonicalPath)
* [`std::fs::GetFileName` (basename)](#std__fs__GetFileName)
2022-04-20 07:17:21 +00:00
* [`std::fs::GetFileSize` (get_file_size, filesize)](#std__fs__GetFileSize)
2021-09-21 13:43:23 +00:00
* [`std::fs::GetLastModifiedTime` (get_last_modified_time)](#std__fs__GetLastModifiedTime)
* [`std::fs::GetParentDirectory` (dirname)](#std__fs__GetParentDirectory)
* [`std::fs::GitIgnorePathArray` (gitignore_path_array)](#std__fs__GitIgnorePathArray)
* [`std::fs::GlobArray` (glob_array, globarray)](#std__fs__GlobArray)
* [`std::fs::IsDirectory` (is_directory, is_dir)](#std__fs__IsDirectory)
* [`std::fs::IsFile` (is_file)](#std__fs__IsFile)
* [`std::fs::IsPathNewer` (is_path_newer)](#std__fs__IsPathNewer)
* [`std::fs::IsReadonly` (is_readonly)](#std__fs__IsReadonly)
* [`std::fs::JoinPath` (join_path)](#std__fs__JoinPath)
* [`std::fs::List` (ls)](#std__fs__List)
* [`std::fs::MovePath` (mv)](#std__fs__MovePath)
* [`std::fs::Print` (cat)](#std__fs__Print)
* [`std::fs::ReadBytes` (readbinfile, read_binary_file)](#std__fs__ReadBytes)
* [`std::fs::ReadText` (readfile, read_text_file)](#std__fs__ReadText)
* [`std::fs::SetMode` (chmod)](#std__fs__SetMode)
* [`std::fs::SetModeGlob` (glob_chmod, chmod_glob)](#std__fs__SetModeGlob)
* [`std::fs::TempDirectory` (temp_dir)](#std__fs__TempDirectory)
* [`std::fs::TempFile` (temp_file)](#std__fs__TempFile)
* [`std::fs::WriteBytes` (writebinfile, write_binary_file)](#std__fs__WriteBytes)
* [`std::fs::WriteText` (writefile, write_text_file)](#std__fs__WriteText)
* [`std::hash::Digest` (digest)](#std__hash__Digest)
* [`std::hash::Sha256Sum` (sha256sum, sha256sum)](#std__hash__Sha256Sum)
* [`std::hash::Sha512Sum` (sha512sum, sha512sum)](#std__hash__Sha512Sum)
* [`std::json`](#std__json)
* [`std::json::Encode` (json_encode)](#std__json__Encode)
* [`std::json::Parse` (json_parse)](#std__json__Parse)
* [`std::lib::alias::Set` (alias)](#std__lib__alias__Set)
* [`std::lib::alias::Unset` (unalias)](#std__lib__alias__Unset)
* [`std::lib::command::Remove` (remove_command)](#std__lib__command__Remove)
* [`std::math::Calc` (calc)](#std__math__Calc)
* [`std::math::GreaterThan` (greater_than)](#std__math__GreaterThan)
* [`std::math::HexDecode` (hex_decode)](#std__math__HexDecode)
* [`std::math::HexEncode` (hex_encode)](#std__math__HexEncode)
* [`std::math::LessThan` (less_than)](#std__math__LessThan)
* [`std::net::Hostname` (hostname)](#std__net__Hostname)
* [`std::net::HttpClient` (http_client)](#std__net__HttpClient)
* [`std::net::WGet` (wget)](#std__net__WGet)
* [`std::net::ftp::Get` (ftp_get)](#std__net__ftp__Get)
* [`std::net::ftp::GetInMemory` (ftp_get_in_memory)](#std__net__ftp__GetInMemory)
* [`std::net::ftp::List` (ftp_list)](#std__net__ftp__List)
* [`std::net::ftp::NLst` (ftp_nlst)](#std__net__ftp__NLst)
* [`std::net::ftp::Put` (ftp_put)](#std__net__ftp__Put)
* [`std::net::ftp::PutInMemory` (ftp_put_in_memory)](#std__net__ftp__PutInMemory)
* [`std::process::Execute` (exec)](#std__process__Execute)
* [`std::process::Exit` (exit, quit, q)](#std__process__Exit)
* [`std::process::ProcessID` (pid, process_id)](#std__process__ProcessID)
* [`std::process::Spawn` (spawn)](#std__process__Spawn)
* [`std::process::Watchdog` (watchdog)](#std__process__Watchdog)
* [`std::random::Range` (random_range, rand_range)](#std__random__Range)
* [`std::random::Text` (random_text, rand_text)](#std__random__Text)
* [`std::scope::Clear` (clear_scope)](#std__scope__Clear)
* [`std::scope::PopStack` (scope_pop_stack)](#std__scope__PopStack)
* [`std::scope::PushStack` (scope_push_stack)](#std__scope__PushStack)
* [`std::semver::IsEqual` (semver_is_equal)](#std__semver__IsEqual)
* [`std::semver::IsNewer` (semver_is_newer)](#std__semver__IsNewer)
* [`std::semver::Parse` (semver_parse)](#std__semver__Parse)
* [`std::string::Base64` (base64)](#std__string__Base64)
* [`std::string::Base64Decode` (base64_decode)](#std__string__Base64Decode)
* [`std::string::Base64Encode` (base64_encode)](#std__string__Base64Encode)
* [`std::string::BytesToString` (bytes_to_string)](#std__string__BytesToString)
* [`std::string::CamelCase` (camelcase)](#std__string__CamelCase)
* [`std::string::Concat` (concat)](#std__string__Concat)
* [`std::string::Contains` (contains)](#std__string__Contains)
* [`std::string::EndsWith` (ends_with)](#std__string__EndsWith)
* [`std::string::Equals` (equals, eq)](#std__string__Equals)
* [`std::string::IndexOf` (indexof)](#std__string__IndexOf)
* [`std::string::IsEmpty` (is_empty)](#std__string__IsEmpty)
* [`std::string::KebabCase` (kebabcase)](#std__string__KebabCase)
* [`std::string::LastIndexOf` (last_indexof)](#std__string__LastIndexOf)
* [`std::string::Length` (length, strlen)](#std__string__Length)
* [`std::string::Lowercase` (lowercase)](#std__string__Lowercase)
* [`std::string::Replace` (replace)](#std__string__Replace)
* [`std::string::SnakeCase` (snakecase)](#std__string__SnakeCase)
* [`std::string::Split` (split)](#std__string__Split)
* [`std::string::StartsWith` (starts_with)](#std__string__StartsWith)
* [`std::string::StringToBytes` (string_to_bytes)](#std__string__StringToBytes)
* [`std::string::SubString` (substring)](#std__string__SubString)
* [`std::string::Trim` (trim)](#std__string__Trim)
* [`std::string::TrimEnd` (trim_end)](#std__string__TrimEnd)
* [`std::string::TrimStart` (trim_start)](#std__string__TrimStart)
* [`std::string::Uppercase` (uppercase)](#std__string__Uppercase)
* [`std::test::Assert` (assert)](#std__test__Assert)
* [`std::test::AssertEquals` (assert_eq)](#std__test__AssertEquals)
* [`std::test::AssertError` (assert_error)](#std__test__AssertError)
* [`std::test::AssertFail` (assert_fail)](#std__test__AssertFail)
* [`std::test::AssertFalse` (assert_false)](#std__test__AssertFalse)
* [`std::test::TestDirectory` (test_directory)](#std__test__TestDirectory)
* [`std::test::TestFile` (test_file)](#std__test__TestFile)
* [`std::thread::Sleep` (sleep)](#std__thread__Sleep)
* [`std::time::CurrentTimeMillies` (current_time)](#std__time__CurrentTimeMillies)
* [`std::var::GetAllVarNames` (get_all_var_names)](#std__var__GetAllVarNames)
* [`std::var::GetByName` (get_by_name)](#std__var__GetByName)
* [`std::var::IsDefined` (is_defined)](#std__var__IsDefined)
* [`std::var::Set` (set)](#std__var__Set)
* [`std::var::SetByName` (set_by_name)](#std__var__SetByName)
* [`std::var::Unset` (unset)](#std__var__Unset)
* [`std::var::UnsetAllVars` (unset_all_vars)](#std__var__UnsetAllVars)
<a name="std__Echo"></a>
2021-09-21 13:44:25 +00:00
## `std::Echo`
2019-12-30 10:45:28 +00:00
```sh
echo [arg]*
```
The echo command will printout all provided arguments.<br>
After all input is done, an end of line will be printed as well.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
Any number of arguments may be provided and will be printed.
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The amount of arguments printed.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:32:48 +00:00
# Print multiple arguments:
2019-12-30 10:45:28 +00:00
echo hello world
2020-01-02 22:32:48 +00:00
# Print multiple spaces between words
2019-12-30 10:45:28 +00:00
echo "hello world"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
echo
<a name="std__Eval"></a>
2021-09-21 13:44:25 +00:00
## `std::Eval`
2019-12-30 10:45:28 +00:00
```sh
eval command arguments
```
The eval command enables to run dynamically created commands.<br>
The command and arguments passed can be variables in the form of ${name}.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
Any number of arguments which will construct a line to evaluate and execute.
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The result of the evaluated line.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
command = set echo
eval ${command} hello world
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
eval
2020-08-27 09:10:11 +00:00
<a name="std__IsCommandDefined"></a>
2021-09-21 13:44:25 +00:00
## `std::IsCommandDefined`
2019-12-30 10:45:28 +00:00
```sh
2020-08-27 09:10:11 +00:00
var = is_command_defined key
2019-12-30 10:45:28 +00:00
```
2020-08-27 09:10:11 +00:00
Returns true if the provided command name exists.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
2020-08-27 09:10:11 +00:00
The command name.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
2020-08-27 09:10:11 +00:00
True if the command exists.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-08-27 09:10:11 +00:00
exists = is_command_defined exec
2019-12-30 10:45:28 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-08-27 09:10:11 +00:00
is_command_defined
2019-12-30 10:45:28 +00:00
2020-07-03 08:57:23 +00:00
<a name="std__Noop"></a>
2021-09-21 13:44:25 +00:00
## `std::Noop`
2020-07-03 08:57:23 +00:00
```sh
noop
```
Empty function that does nothing and returns none.
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-03 08:57:23 +00:00
All parameters are ignored
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-03 08:57:23 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-07-03 08:57:23 +00:00
```sh
noop
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-03 08:57:23 +00:00
noop
2020-02-05 19:13:09 +00:00
<a name="std__Not"></a>
2021-09-21 13:44:25 +00:00
## `std::Not`
2019-12-30 10:45:28 +00:00
```sh
2020-02-05 19:13:09 +00:00
output = not [command|value|condition]
2019-12-30 10:45:28 +00:00
```
2020-02-05 19:13:09 +00:00
Enables to switch falsy to true and truthy to false.<br>
The **not** commands accept either:
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
* A command with optional arguments and invokes it
* A single value which doesn't match any known command
* A condition statement
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
If the result is one of the following:
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
* No output
* false (case insensitive)
* 0
* no (case insensitive)
* Empty value
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
It will return true, otherwise it will return false.
A condition statement is made up of values, or/and keywords and '('/')' groups.<br>
Each must be separated with a space character.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
A command and its arguments to invoke and evaluate its output, if a single value is provided an no such command exists, it is evaluated as a value.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
The switched value of the input.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-02-05 19:13:09 +00:00
fn test_not_true
value = not true
2020-01-02 22:32:48 +00:00
2020-02-05 19:13:09 +00:00
assert_false ${value}
2020-01-12 17:53:30 +00:00
end
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
fn test_not_false
value = not false
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
assert ${value}
2020-01-12 17:53:30 +00:00
end
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
fn test_not_command_true
value = not set true
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
assert_false ${value}
2020-01-12 17:53:30 +00:00
end
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
fn test_not_command_false
value = not set false
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
assert ${value}
2020-01-12 17:53:30 +00:00
end
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
fn test_not_condition_true
value = not true and false or true and false or ( true and true or false )
assert_false ${value}
2020-01-12 17:53:30 +00:00
end
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
fn test_not_condition_false
value = not true and false or true and false or ( true and true or false ) and false
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
assert ${value}
end
2019-12-30 10:45:28 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
not
2019-12-30 10:45:28 +00:00
<a name="std__Print"></a>
## `std::Print`
```sh
print [--style|-s bold|underline|italic|dimmed|blink|strikethrough]* [--color|-c black|red|green|yellow|blue|magenta|cyan|white|bright_<color>|rgb_<red>_<green>_<blue>] [--background-color|-bgc black|red|green|yellow|blue|magenta|cyan|white|bright_<color>|rgb_<red>_<green>_<blue>] [arg]*
```
The print command will printout all provided arguments with optional color values.<br>
No end of line will be added.<br>
The style will continue to additional printouts until an echo/println is used to close the line.<br>
**Not all colors and all styles are supported on every terminal.**
### Parameters
* Optional styles - To support multiple styles, add the option as much as needed.
* Optional color - The text color. For RGB, use the rgb_ prefix with the values separated by a _ character.
* Optional background color (also supports rgb_ prefix)
* Any number of arguments may be provided and will be printed.
### Return Value
The amount of arguments printed.
### Examples
```sh
# Print multiple arguments:
print hello world
# Print multiple spaces between words
print "hello world"
# Print with style/color values
print --style underline --color red My Bold Red Text
echo
2022-06-11 10:48:47 +00:00
print -s underline -s bold -c bright_green -bgc red Hello World
echo
```
### Aliases:
print
<a name="std__Println"></a>
## `std::Println`
```sh
println [--style|-s bold|underline|italic|dimmed|blink|strikethrough]* [--color|-c black|red|green|yellow|blue|magenta|cyan|white|bright_<color>|rgb_<red>_<green>_<blue>] [--background-color|-bgc black|red|green|yellow|blue|magenta|cyan|white|bright_<color>|rgb_<red>_<green>_<blue>] [arg]*
```
The println command will printout all provided arguments with optional color values.<br>
**Not all colors and all styles are supported on every terminal.**
### Parameters
* Optional styles - To support multiple styles, add the option as much as needed.
* Optional color - The text color. For RGB, use the rgb_ prefix with the values separated by a _ character.
* Optional background color (also supports rgb_ prefix)
* Any number of arguments may be provided and will be printed.
### Return Value
The amount of arguments printed.
### Examples
```sh
# Print multiple arguments:
println hello world
# Print multiple spaces between words
println "hello world"
# Print with style/color values
println --style underline --color red My Bold Red Text
2022-06-11 10:48:47 +00:00
println -s underline -s bold -c bright_green -bgc red Hello World
```
#### Source:
<details>
<summary>Show Source</summary>
```sh
scope::println::count = set 0
if not array_is_empty ${scope::println::arguments}
scope::println::commandline = array_join ${scope::println::arguments} "\" \""
scope::println::commandline = set "\"${scope::println::commandline}"
scope::println::commandline = substring ${scope::println::commandline} -2
scope::println::count = print %{scope::println::commandline}
end
echo
set ${scope::println::count}
```
</details>
### Aliases:
println
2020-02-05 19:13:09 +00:00
<a name="std__ReadUserInput"></a>
2021-09-21 13:44:25 +00:00
## `std::ReadUserInput`
2019-12-30 10:45:28 +00:00
```sh
2020-02-05 19:13:09 +00:00
var = read
2019-12-30 10:45:28 +00:00
```
2020-02-05 19:13:09 +00:00
Reads the user input into the output variable.<br>
If the user didn't insert any input, none will be returned.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
None
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
The user input or none if no input was entered.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-02-05 19:13:09 +00:00
echo Enter Full Name:
name = read
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
if is_empty ${name}
echo You didn't enter any value
else
echo Your name is: ${name}
end
2019-12-30 10:45:28 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
read
2019-12-30 10:45:28 +00:00
2020-02-05 19:13:09 +00:00
<a name="std__Release"></a>
2021-09-21 13:44:25 +00:00
## `std::Release`
2019-12-30 10:45:28 +00:00
```sh
2020-02-05 19:13:09 +00:00
release [-r|--recursive] handle
2019-12-30 10:45:28 +00:00
```
2020-02-05 19:13:09 +00:00
Releases an internal handle stored in the runtime memory.<br>
Certain commands (such as **array**) will create a handle and the variable will only hold a reference to that handle.<br>
In order to release those handles once they are no longer needed, the release command should be used.<br>
By providing the recursive flag, it will also go over the data values (array items, map values, set keys, ...) and release each one of them as well
if they are handles to other arrays/maps/sets/...
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
* Optional recursive (-r/--recursive) flag (default false)
2020-02-05 19:13:09 +00:00
* The handle name.
2020-01-01 18:59:33 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-01 18:59:33 +00:00
2020-02-05 19:13:09 +00:00
* true - If a handle was found and removed
* false - If no handle was found
2021-09-21 13:47:41 +00:00
### Examples
2020-02-05 19:13:09 +00:00
```sh
release ${array_handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
release
<a name="std__ShowCommandDocumentation"></a>
2021-09-21 13:44:25 +00:00
## `std::ShowCommandDocumentation`
2020-01-03 09:34:04 +00:00
```sh
var = man command
```
Prints and returns the help documentation of the provided command.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-03 09:34:04 +00:00
The command name.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-03 09:34:04 +00:00
The help documentation or if not found, none.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-03 09:34:04 +00:00
```sh
man set
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-03 09:34:04 +00:00
man
2020-07-31 09:07:20 +00:00
<a name="std__collections"></a>
2021-09-21 13:44:25 +00:00
## `std::collections`
2020-07-31 09:07:20 +00:00
The collections module contains commands which enable to interact with different data models such as arrays, sets and maps.
* Arrays are simple ordered list of items
* Sets are unordered unique collection of items
* Maps are key/value (dictionary) structure where the keys are unique
Access to these data structures are done via handles.<br>
Handles are provided by the data structure creation command (such as: array, range, map, set) and are used in all
other commands to read/modify those data structures.<br>
Once done with a specific data structure, you must release it via release command to prevent any memory leaks.
<a name="std__collections__Array"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::Array`
2020-01-05 17:02:30 +00:00
```sh
handle = array value1 value2 value3 ...
```
Creates an array from the input arguments and returns a handle to that array.<br>
This handle can be passed to other commands which support arrays using handles.<br>
Once the array is no longer used, it should be released using the **release** command.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-05 17:02:30 +00:00
Any number of arguments which will construct the array.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-05 17:02:30 +00:00
A handle to the array.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-05 17:02:30 +00:00
```sh
handle = array ${var} "hello world" 5 ${another_var}
# once done we should release the handle
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-05 17:02:30 +00:00
array
2020-05-05 17:28:17 +00:00
<a name="std__collections__ArrayClear"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayClear`
2020-05-05 17:28:17 +00:00
```sh
result = array_clear handle
```
Clears the provided array.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-05 17:28:17 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-05 17:28:17 +00:00
True if successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-05 17:28:17 +00:00
```sh
handle = array
result = array_push ${handle} 1
result = array_is_empty ${handle}
assert_false ${result}
result array_clear ${handle}
assert ${result}
result = array_is_empty ${handle}
assert ${result}
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-05 17:28:17 +00:00
array_clear
2020-01-24 17:24:00 +00:00
<a name="std__collections__ArrayConcat"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayConcat`
2020-01-24 17:24:00 +00:00
```sh
handle = array_concat [handle]*
```
Concats all provided arrays and returns a handle to a new array with all items.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-24 17:24:00 +00:00
Any number of array handles.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-24 17:24:00 +00:00
A handle to the new array.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-24 17:24:00 +00:00
```sh
input1 = range 1 4
input2 = range 4 6
input3 = range 6 8
# new array will contain values from 1-7
arr = array_concat ${input1} ${input2} ${input3}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-01-24 17:24:00 +00:00
```sh
2020-01-31 14:05:30 +00:00
2020-01-24 17:24:00 +00:00
for scope::array_concat::arg in ${scope::array_concat::arguments}
if not is_array ${scope::array_concat::arg}
trigger_error "Invalid input, non array handle or array not found."
end
end
scope::array_concat::array = array
for scope::array_concat::arg in ${scope::array_concat::arguments}
for scope::array_concat::item in ${scope::array_concat::arg}
array_push ${scope::array_concat::array} ${scope::array_concat::item}
end
end
set ${scope::array_concat::array}
2020-01-31 14:05:30 +00:00
2020-01-24 17:24:00 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-01-24 17:24:00 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-24 17:24:00 +00:00
array_concat
2020-05-04 06:46:35 +00:00
<a name="std__collections__ArrayContains"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayContains`
2020-05-04 06:39:23 +00:00
```sh
2020-05-04 06:46:35 +00:00
var = array_contains handle value
2020-05-04 06:39:23 +00:00
```
Returns the first index of the array with the same value as provided.<br>
If not found, false will be returned.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-04 06:39:23 +00:00
* The array handle.
* The value
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-04 06:39:23 +00:00
The value index in the array or false if not found.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-04 06:39:23 +00:00
```sh
handle = array value1 value2 value3
2020-05-04 06:46:35 +00:00
index = array_contains ${handle} value2
2020-05-04 06:39:23 +00:00
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-05-04 06:39:23 +00:00
```sh
2020-05-04 06:46:35 +00:00
scope::array_contains::index = set false
scope::array_contains::value = set ${scope::array_contains::argument::2}
2020-05-04 06:39:23 +00:00
2020-05-04 06:46:35 +00:00
scope::array_contains::counter = set 0
for scope::array_contains::next_value in ${scope::array_contains::argument::1}
scope::array_contains::found = equals ${scope::array_contains::next_value} ${scope::array_contains::value}
2020-05-04 06:39:23 +00:00
2020-05-04 06:46:35 +00:00
if ${scope::array_contains::found}
scope::array_contains::index = set ${scope::array_contains::counter}
scope::array_contains::argument::1 = set
2020-05-04 06:39:23 +00:00
end
2023-04-22 20:03:53 +00:00
scope::array_contains::counter = calc ${scope::array_contains::counter} + 1
2020-05-04 06:39:23 +00:00
end
2020-05-04 06:46:35 +00:00
set ${scope::array_contains::index}
2020-05-04 06:39:23 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-05-04 06:39:23 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-04 06:46:35 +00:00
array_contains
2020-05-04 06:39:23 +00:00
2020-04-04 12:14:54 +00:00
<a name="std__collections__ArrayGet"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayGet`
2020-04-04 12:14:54 +00:00
```sh
var = array_get handle index
```
Returns the element from the array at a given index or none if the index is bigger than the array length.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-04 12:14:54 +00:00
* The array handle.
* The element index.
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-04 12:14:54 +00:00
The element at the given index from the array or none.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-04 12:14:54 +00:00
```sh
handle = array 1 2 3
element = array_get ${handle} 2
assert_eq ${element} 3
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-04 12:14:54 +00:00
array_get
<a name="std__collections__ArrayIsEmpty"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayIsEmpty`
```sh
var = array_is_empty handle
```
Returns true if the provided array handle is an empty array.
2021-09-21 13:47:41 +00:00
### Parameters
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
True if the provided handle belongs to an empty array.
2021-09-21 13:47:41 +00:00
### Examples
```sh
values = array
out = array_is_empty ${values}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
```sh
2020-01-31 14:05:30 +00:00
scope::array_is_empty::length = array_length ${scope::array_is_empty::argument::1}
equals 0 ${scope::array_is_empty::length}
2020-01-31 14:05:30 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2021-09-21 13:45:27 +00:00
### Aliases:
array_is_empty
2020-01-25 16:23:19 +00:00
<a name="std__collections__ArrayJoin"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayJoin`
2020-01-25 16:23:19 +00:00
```sh
2020-01-25 16:34:22 +00:00
var = array_join handle separator
2020-01-25 16:23:19 +00:00
```
2020-01-25 16:34:22 +00:00
Joins all values in the provided array with the provided separator in between each value.
2020-01-25 16:23:19 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-25 16:23:19 +00:00
2020-01-25 16:34:22 +00:00
* An array handle
* The separator to put between each item pair
2020-01-25 16:23:19 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-25 16:23:19 +00:00
2020-01-25 16:34:22 +00:00
The joined string value
2020-01-25 16:23:19 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-25 16:23:19 +00:00
```sh
2020-01-25 16:34:22 +00:00
function test_to_string
arr = array hello world
string = array_join ${arr} ", "
2020-01-25 16:23:19 +00:00
2020-01-25 16:34:22 +00:00
release ${arr}
assert_eq ${string} "hello, world"
end
function test_numbers
arr = range 1 5
string = array_join ${arr} ", "
release ${arr}
assert_eq ${string} "1, 2, 3, 4"
end
function test_empty_separator
arr = range 1 5
string = array_join ${arr} ""
release ${arr}
assert_eq ${string} "1234"
end
2020-01-25 16:23:19 +00:00
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-01-25 16:23:19 +00:00
```sh
2020-01-31 14:05:30 +00:00
2020-01-25 16:23:19 +00:00
if not is_array ${scope::array_join::argument::1}
trigger_error "Invalid input, non array handle or array not found."
end
if not array_is_empty ${scope::array_join::argument::1}
for scope::array_join::item in ${scope::array_join::argument::1}
scope::array_join::string = set "${scope::array_join::string}${scope::array_join::item}${scope::array_join::argument::2}"
end
if not is_empty ${scope::array_join::argument::2}
scope::array_join::separatorlen = strlen ${scope::array_join::argument::2}
scope::array_join::stringlen = strlen ${scope::array_join::string}
scope::array_join::offset = calc ${scope::array_join::stringlen} - ${scope::array_join::separatorlen}
scope::array_join::string = substring ${scope::array_join::string} 0 ${scope::array_join::offset}
end
end
set ${scope::array_join::string}
2020-01-31 14:05:30 +00:00
2020-01-25 16:23:19 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-01-25 16:23:19 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-25 16:23:19 +00:00
array_join
2020-01-08 23:50:04 +00:00
<a name="std__collections__ArrayLength"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayLength`
2020-01-08 23:50:04 +00:00
```sh
var = array_length handle
```
Returns the array length based on the provided array handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-08 23:50:04 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-08 23:50:04 +00:00
The array length.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-08 23:50:04 +00:00
```sh
handle = array a b c "d e"
len = array_length ${handle}
released = release ${handle}
echo Array length: ${len} released: ${released}
handle = range 0 10
len = array_length ${handle}
released = release ${handle}
echo Array length: ${len} released: ${released}
```
2021-09-21 13:45:27 +00:00
### Aliases:
array_length, arrlen, array_size
2020-01-08 23:50:04 +00:00
2020-01-22 22:06:40 +00:00
<a name="std__collections__ArrayPop"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayPop`
2020-01-22 22:06:40 +00:00
```sh
var = array_pop handle
```
Returns the last element of the array or none if the array is empty.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-22 22:06:40 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-22 22:06:40 +00:00
The last element of the array or none if the array is empty.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-22 22:06:40 +00:00
```sh
handle = array 1 2 3
last_element = array_pop ${handle}
assert_eq ${last_element} 3
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-22 22:06:40 +00:00
array_pop
2020-01-24 16:20:19 +00:00
<a name="std__collections__ArrayPush"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayPush`
2020-01-24 16:20:19 +00:00
```sh
var = array_push handle value
```
Pushes an additional value to an existing array.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-24 16:20:19 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-24 16:20:19 +00:00
True if a new value was pushed.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-24 16:20:19 +00:00
```sh
handle = array 1 2 3
array_push ${handle} 4
last_element = array_pop ${handle}
assert_eq ${last_element} 4
```
2021-09-21 13:45:27 +00:00
### Aliases:
array_push, array_add, array_put
2020-01-24 16:20:19 +00:00
2020-05-05 17:39:54 +00:00
<a name="std__collections__ArrayRemove"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArrayRemove`
2020-05-05 17:39:54 +00:00
```sh
result = array_remove handle index
```
Removes the item from the array at the given index.<br>
If the array is not found or the index is greater than the array size, this command will return false.<br>
Otherwise it will return true.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-05 17:39:54 +00:00
* The array handle.
* The element index.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-05 17:39:54 +00:00
True if successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-05 17:39:54 +00:00
```sh
arr = array old
element = array_get ${arr} 0
assert_eq ${element} old
result = array_remove ${arr} 0
assert ${result}
empty = array_is_empty ${arr}
assert ${empty}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-05 17:39:54 +00:00
array_remove
2020-04-04 12:14:54 +00:00
<a name="std__collections__ArraySet"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ArraySet`
2020-04-04 12:14:54 +00:00
```sh
2020-04-04 12:20:48 +00:00
result = array_set handle index value
2020-04-04 12:14:54 +00:00
```
2020-04-04 12:20:48 +00:00
Updates the array at a given index with the provided value.<br>
If the array is not found or the index is greater than the array size, this command will return false.<br>
Otherwise it will return true.
2020-04-04 12:14:54 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-04 12:14:54 +00:00
* The array handle.
* The element index.
2020-04-04 12:20:48 +00:00
* The element value.
2020-04-04 12:14:54 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-04 12:14:54 +00:00
2020-04-04 12:20:48 +00:00
True if successful.
2020-04-04 12:14:54 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-04-04 12:14:54 +00:00
```sh
2020-04-04 12:20:48 +00:00
arr = array old
element = array_get ${arr} 0
assert_eq ${element} old
result = array_set ${arr} 0 new
assert ${result}
element = array_get ${arr} 0
assert_eq ${element} new
2020-04-04 12:14:54 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-04 12:14:54 +00:00
array_set
2020-01-22 20:17:52 +00:00
<a name="std__collections__IsArray"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::IsArray`
2020-01-22 20:17:52 +00:00
```sh
2020-02-01 11:28:29 +00:00
var = is_array handle
2020-01-22 20:17:52 +00:00
```
2020-02-01 11:28:29 +00:00
Returns true if the provided value is an array handle.
2020-01-22 20:17:52 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-22 20:17:52 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-22 20:17:52 +00:00
2020-02-01 11:28:29 +00:00
True if the provided value is an array handle.
2020-01-22 20:17:52 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-22 20:17:52 +00:00
```sh
2020-02-01 11:28:29 +00:00
arr = array 1 2 3
2020-01-22 20:17:52 +00:00
2020-02-01 11:28:29 +00:00
value = is_array ${arr}
assert ${value}
released = release ${arr}
assert ${released}
2020-01-22 20:17:52 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-22 20:17:52 +00:00
is_array
2020-02-01 11:28:29 +00:00
<a name="std__collections__IsMap"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::IsMap`
2020-02-01 11:28:29 +00:00
```sh
var = is_map handle
```
Returns true if the provided value is a map handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 11:28:29 +00:00
The map handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 11:28:29 +00:00
True if the provided value is a map handle.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 11:28:29 +00:00
```sh
map_handle = map
value = is_map ${map_handle}
assert ${value}
released = release ${map_handle}
assert ${released}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 11:28:29 +00:00
is_map
2020-05-05 06:33:27 +00:00
<a name="std__collections__IsSet"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::IsSet`
2020-05-05 06:33:27 +00:00
```sh
var = is_set handle
```
Returns true if the provided value is a set handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-05 06:33:27 +00:00
The set handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-05 06:33:27 +00:00
True if the provided value is a set handle.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-05 06:33:27 +00:00
```sh
handle = set_new 1 2 3
value = is_set ${handle}
assert ${value}
released = release ${handle}
assert ${released}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-05 06:33:27 +00:00
is_set
2020-02-01 11:00:18 +00:00
<a name="std__collections__Map"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::Map`
2020-02-01 11:00:18 +00:00
```sh
handle = map
```
Creates an empty map and returns a handle to that array.<br>
This handle can be passed to other commands which support maps using handles.<br>
Once the map is no longer used, it should be released using the **release** command.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 11:00:18 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 11:00:18 +00:00
A handle to the map.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 11:00:18 +00:00
```sh
handle = map
# once done we should release the handle
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 11:00:18 +00:00
map
2020-02-01 14:22:11 +00:00
<a name="std__collections__MapClear"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapClear`
2020-02-01 14:22:11 +00:00
```sh
result = map_clear handle
```
Clears the provided map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 14:22:11 +00:00
The map handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 14:22:11 +00:00
True if successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 14:22:11 +00:00
```sh
handle = map
result = map_put ${handle} a 1
result = map_is_empty ${handle}
assert_false ${result}
result map_clear ${handle}
assert ${result}
result = map_is_empty ${handle}
assert ${result}
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 14:22:11 +00:00
map_clear
2020-05-03 20:57:59 +00:00
<a name="std__collections__MapContainsKey"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapContainsKey`
2020-05-03 20:57:59 +00:00
```sh
var = map_contains_key handle key
```
Returns true if the provided key was found in the map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-03 20:57:59 +00:00
* The map handle.
* The key
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-03 20:57:59 +00:00
True if the key was found in the map.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-03 20:57:59 +00:00
```sh
handle = map
map_put ${handle} key value
found = map_contains_key ${handle} key
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-05-03 20:57:59 +00:00
```sh
2020-05-04 05:43:05 +00:00
scope::map_contains_key::value = map_get ${scope::map_contains_key::argument::1} ${scope::map_contains_key::argument::2}
is_defined scope::map_contains_key::value
2020-05-03 20:57:59 +00:00
2020-05-04 05:43:05 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-05-04 05:43:05 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-04 05:43:05 +00:00
map_contains_key
<a name="std__collections__MapContainsValue"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapContainsValue`
2020-05-04 05:43:05 +00:00
```sh
var = map_contains_value handle value
```
Returns true if the provided value was found in the map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-04 05:43:05 +00:00
* The map handle.
* The value
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-03 20:57:59 +00:00
2020-05-04 05:43:05 +00:00
True if the value was found in the map.
2020-05-03 20:57:59 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-05-04 05:43:05 +00:00
```sh
handle = map
map_put ${handle} key value
found = map_contains_value ${handle} value
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-05-04 05:43:05 +00:00
```sh
scope::map_contains_value::found = set false
scope::map_contains_value::not_empty = not map_is_empty ${scope::map_contains_value::argument::1}
if ${scope::map_contains_value::not_empty}
scope::map_contains_value::value = set ${scope::map_contains_value::argument::2}
scope::map_contains_value::key_array_handle = map_keys ${scope::map_contains_value::argument::1}
for scope::map_contains_value::item in ${scope::map_contains_value::key_array_handle}
scope::map_contains_value::next_value = map_get ${scope::map_contains_value::argument::1} ${scope::map_contains_value::item}
scope::map_contains_value::found = equals ${scope::map_contains_value::next_value} ${scope::map_contains_value::value}
if ${scope::map_contains_value::found}
release ${scope::map_contains_value::key_array_handle}
2020-05-03 20:57:59 +00:00
end
end
end
2020-05-04 05:43:05 +00:00
release ${scope::map_contains_value::key_array_handle}
set ${scope::map_contains_value::found}
2020-05-03 20:57:59 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-05-03 20:57:59 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-04 05:43:05 +00:00
map_contains_value
2020-05-03 20:57:59 +00:00
2020-02-01 11:23:19 +00:00
<a name="std__collections__MapGet"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapGet`
2020-02-01 11:23:19 +00:00
```sh
value = map_get handle key
```
Returns a the value corresponding to the key from the map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 11:23:19 +00:00
* The map handle.
* The key.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 11:23:19 +00:00
The value corresponding to the key from the map.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 11:23:19 +00:00
```sh
handle = map
result = map_put ${handle} key value
assert_eq ${result} true
value = map_get ${handle} key
assert_eq ${value} value
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 11:23:19 +00:00
map_get
2020-02-01 13:21:31 +00:00
<a name="std__collections__MapIsEmpty"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapIsEmpty`
2020-02-01 13:21:31 +00:00
```sh
var = map_is_empty handle
```
Returns true if the provided map handle is an empty map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 13:21:31 +00:00
The map handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 13:21:31 +00:00
True if the provided handle belongs to an empty map.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 13:21:31 +00:00
```sh
handle = map
map_put ${handle} key value
empty = map_is_empty ${handle}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-02-01 13:21:31 +00:00
```sh
scope::map_is_empty::length = map_size ${scope::map_is_empty::argument::1}
equals 0 ${scope::map_is_empty::length}
```
2021-09-21 13:31:05 +00:00
</details>
2020-02-01 13:21:31 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 13:21:31 +00:00
map_is_empty
2020-04-14 11:08:34 +00:00
<a name="std__collections__MapKeys"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapKeys`
2020-04-14 11:08:34 +00:00
```sh
keys = map_keys handle
```
Returns a handle to an array holding all keys in the provided map handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-14 11:08:34 +00:00
* The map handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-14 11:08:34 +00:00
A handle to an array holding all map keys.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-14 11:08:34 +00:00
```sh
handle = map
result = map_put ${handle} key1 value1
assert_eq ${result} true
result = map_put ${handle} key2 value2
assert_eq ${result} true
keys = map_keys ${handle}
for key in ${keys}
value = map_get ${handle} ${key}
echo Key: ${key} Value: ${value}
end
release ${handle}
release ${keys}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-14 11:08:34 +00:00
map_keys
2020-02-01 13:44:18 +00:00
<a name="std__collections__MapLoadProperties"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapLoadProperties`
2020-02-01 13:44:18 +00:00
```sh
var = map_load_properties [--prefix prefix] handle text
```
Parsers and loads all properties to the provided map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 13:44:18 +00:00
* Optional --prefix and the prefix value
* The map handle.
* The properties text.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 13:44:18 +00:00
True if successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 13:44:18 +00:00
```sh
handle = map
result = map_put ${handle} key value
assert_eq ${result} true
value = map_get ${handle} key
assert_eq ${value} value
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 13:44:18 +00:00
map_load_properties
2020-02-01 11:23:19 +00:00
<a name="std__collections__MapPut"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapPut`
2020-02-01 11:23:19 +00:00
```sh
var = map_put handle key value
```
Inserts a key-value pair into the map.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 11:23:19 +00:00
* The map handle.
* The key.
* The new value.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 11:23:19 +00:00
True if a new value was inserted.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 11:23:19 +00:00
```sh
handle = map
result = map_put ${handle} key value
assert_eq ${result} true
value = map_get ${handle} key
assert_eq ${value} value
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
map_put, map_add
2020-02-01 11:23:19 +00:00
2020-02-01 11:35:37 +00:00
<a name="std__collections__MapRemove"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapRemove`
2020-02-01 11:35:37 +00:00
```sh
value = map_remove handle key
```
Removes a the value corresponding to the key from the map and returns it.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 11:35:37 +00:00
* The map handle.
* The key.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 11:35:37 +00:00
The value corresponding to the key from the map.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 11:35:37 +00:00
```sh
handle = map
result = map_put ${handle} key value
assert_eq ${result} true
value = map_remove ${handle} key
assert_eq ${value} value
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 11:35:37 +00:00
map_remove
2020-02-01 11:52:13 +00:00
<a name="std__collections__MapSize"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapSize`
2020-02-01 11:52:13 +00:00
```sh
var = map_size handle
```
Returns the map size based on the provided map handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 11:52:13 +00:00
The map handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 11:52:13 +00:00
The map size.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 11:52:13 +00:00
```sh
handle = map
result = map_put ${handle} a 1
result = map_put ${handle} b 2
result = map_put ${handle} c 3
result = map_size ${handle}
assert_eq ${result} 3
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 11:52:13 +00:00
map_size
2020-02-01 14:13:36 +00:00
<a name="std__collections__MapToProperties"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::MapToProperties`
2020-02-01 14:13:36 +00:00
```sh
2020-02-01 14:22:11 +00:00
text = map_to_properties [--prefix prefix] handle
2020-02-01 14:13:36 +00:00
```
2020-02-01 14:22:11 +00:00
Converts the provided map to properties text.
2020-02-01 14:13:36 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-01 14:13:36 +00:00
* Optional --prefix and the prefix value
* The map handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-01 14:13:36 +00:00
2020-02-01 14:22:11 +00:00
The properties text.
2020-02-01 14:13:36 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-02-01 14:13:36 +00:00
```sh
handle = map
map_put ${handle} a 1
map_put ${handle} b 2
map_put ${handle} a.b.c 123
text = map_to_properties ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-01 14:13:36 +00:00
map_to_properties
<a name="std__collections__Range"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::Range`
2020-01-05 17:02:30 +00:00
```sh
handle = range start end
```
Creates an array from the input start and end range values and returns a handle to that array.<br>
This handle can be passed to other commands which support arrays using handles.<br>
Once the array is no longer used, it should be released using the **release** command.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-05 17:02:30 +00:00
* The start numeric value
* The end numeric value which cannot be smaller than the start value.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-05 17:02:30 +00:00
A handle to the array.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-05 17:02:30 +00:00
```sh
handle = range 1 10
# once done we should release the handle
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-05 17:02:30 +00:00
range
2020-01-17 10:39:50 +00:00
<a name="std__collections__ReadProperties"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::ReadProperties`
2020-01-17 10:39:50 +00:00
```sh
count = read_properties [--prefix key] text
2020-01-17 10:39:50 +00:00
```
Parses the properties (based on java properties format) text and sets them as variables.<br>
This command will also return the count of properties read.<br>
If prefix is provided, all properties read, will be stored as variables with the **prefix.** as their prefix.
2020-01-17 10:39:50 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-17 10:39:50 +00:00
* Optional --prefix and the prefix value
* The text to parse.
2020-01-17 10:39:50 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-17 10:39:50 +00:00
The properties count.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-17 10:39:50 +00:00
```sh
count = read_properties "a=1\nb=2\na.b.c=3"
assert_eq ${count} 3
assert_eq ${a} 1
assert_eq ${b} 2
assert_eq ${a.b.c} 3
count = read_properties --prefix config a=1\nb=2\na.b.c=3
assert_eq ${count} 3
assert_eq ${config.a} 1
assert_eq ${config.b} 2
assert_eq ${config.a.b.c} 3
2020-01-17 10:39:50 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-17 10:39:50 +00:00
read_properties
2020-05-05 06:33:27 +00:00
<a name="std__collections__Set"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::Set`
2020-05-05 06:33:27 +00:00
```sh
handle = set_new value1 value2 value3 ...
```
Creates a new set from the input arguments and returns a handle to that set.<br>
This handle can be passed to other commands which support sets using handles.<br>
Once the set is no longer used, it should be released using the **release** command.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-05 06:33:27 +00:00
Any number of arguments which will construct the set.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-05 06:33:27 +00:00
A handle to the set.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-05 06:33:27 +00:00
```sh
handle = set_new ${var} "hello world" 5 ${another_var}
# once done we should release the handle
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-05 06:33:27 +00:00
set_new
2020-05-06 07:42:26 +00:00
<a name="std__collections__SetClear"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetClear`
2020-05-06 07:42:26 +00:00
```sh
result = set_clear handle
```
Clears the provided set.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 07:42:26 +00:00
The set handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 07:42:26 +00:00
True if successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 07:42:26 +00:00
```sh
handle = set
result = set_put ${handle} 1
result = set_is_empty ${handle}
assert_false ${result}
result set_clear ${handle}
assert ${result}
result = set_is_empty ${handle}
assert ${result}
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
set_clear
<a name="std__collections__SetContains"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetContains`
2020-05-06 07:42:26 +00:00
```sh
var = set_contains handle value
```
Returns true if the set contains the provided value.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 07:42:26 +00:00
* The set handle.
* The value
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 07:42:26 +00:00
True if the value was found in the set.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 07:42:26 +00:00
```sh
handle = set_new value1 value2 value3
found = set_contains ${handle} value2
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
set_contains
2020-05-07 16:29:32 +00:00
<a name="std__collections__SetFromArray"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetFromArray`
2020-05-07 16:29:32 +00:00
```sh
set_handle = set_from_array array_handle
```
Returns a set handle created from the provided array values.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-07 16:29:32 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-07 16:29:32 +00:00
The new set handle.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-07 16:29:32 +00:00
```sh
array_handle = array value1 value2 value3
set_handle = set_from_array ${handle}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-05-07 16:29:32 +00:00
```sh
if not is_array ${scope::set_from_array::argument::1}
trigger_error "Invalid input, non array handle or array not found."
end
scope::set_from_array::set = set_new
for scope::set_from_array::next_value in ${scope::set_from_array::argument::1}
set_put ${scope::set_from_array::set} ${scope::set_from_array::next_value}
end
set ${scope::set_from_array::set}
```
2021-09-21 13:31:05 +00:00
</details>
2020-05-07 16:29:32 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-07 16:29:32 +00:00
set_from_array
2020-05-06 07:42:26 +00:00
<a name="std__collections__SetIsEmpty"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetIsEmpty`
2020-05-06 07:42:26 +00:00
```sh
var = set_is_empty handle
```
Returns true if the provided set handle is an empty set.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 07:42:26 +00:00
The set handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 07:42:26 +00:00
True if the provided handle belongs to an empty set.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 07:42:26 +00:00
```sh
handle = set
set_put ${handle} value
empty = set_is_empty ${handle}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-05-06 07:42:26 +00:00
```sh
scope::set_is_empty::length = set_size ${scope::set_is_empty::argument::1}
equals 0 ${scope::set_is_empty::length}
```
2021-09-21 13:31:05 +00:00
</details>
2020-05-06 07:42:26 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
set_is_empty
<a name="std__collections__SetPut"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetPut`
2020-05-06 07:42:26 +00:00
```sh
var = set_put handle value
```
Pushes an additional value to an existing set.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 07:42:26 +00:00
The set handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 07:42:26 +00:00
True if a new value was pushed.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 07:42:26 +00:00
```sh
handle = set_new 1 2 3
set_put ${handle} 4
size = set_size ${handle}
assert_eq ${size} 4
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
set_put, set_add
<a name="std__collections__SetRemove"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetRemove`
2020-05-06 07:42:26 +00:00
```sh
removed = set_remove handle value
```
Removes a the value from the set and returns true/false if it was removed.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 07:42:26 +00:00
* The set handle.
* The value to remove.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 07:42:26 +00:00
True if the value was found and removed from the set.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 07:42:26 +00:00
```sh
handle = set_new
result = set_put ${handle} value
assert_eq ${result} true
removed = set_remove ${handle} value
assert ${removed}
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
set_remove
<a name="std__collections__SetSize"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetSize`
2020-05-06 07:42:26 +00:00
```sh
var = set_size handle
```
Returns the set size based on the provided set handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 07:42:26 +00:00
The set handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 07:42:26 +00:00
The set size.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 07:42:26 +00:00
```sh
handle = set
result = set_put ${handle} 1
result = set_put ${handle} 2
result = set_put ${handle} 3
result = set_size ${handle}
assert_eq ${result} 3
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 07:42:26 +00:00
set_size
2020-05-06 16:23:40 +00:00
<a name="std__collections__SetToArray"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::SetToArray`
2020-05-06 16:23:40 +00:00
```sh
array_handle = set_to_array set_handle
```
Converts the provided set to an array and returns the new array handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-06 16:23:40 +00:00
The set handle.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-06 16:23:40 +00:00
The array handle or false in case of error.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-06 16:23:40 +00:00
```sh
set_handle = set_new value1 value2 value3
array_handle = set_to_array ${set_handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-06 16:23:40 +00:00
set_to_array
2020-01-17 10:39:50 +00:00
<a name="std__collections__WriteProperties"></a>
2021-09-21 13:44:25 +00:00
## `std::collections::WriteProperties`
2020-01-17 10:39:50 +00:00
```sh
text = write_properties [--prefix prefix] [names]
2020-01-17 10:39:50 +00:00
```
Creates a properties string from the provided list of variable names (not values).
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-17 10:39:50 +00:00
* Optional prefix which will be added to all written properties.
* A list of variable names.
2020-01-17 10:39:50 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-17 10:39:50 +00:00
The properties text value.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-17 10:39:50 +00:00
```sh
a = set 1
b = set 2
a.b.c = set 3
# text will be equal to:
# a=1
# b=2
# a.b.c=3
text = write_properties a b a.b.c
# text will be equal to:
# P.a=1
# P.b=2
# P.a.b.c=3
text = write_properties --prefix P a b a.b.c
2020-01-17 10:39:50 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-17 10:39:50 +00:00
write_properties
<a name="std__debug__DuckscriptSDKVersion"></a>
2021-09-21 13:44:25 +00:00
## `std::debug::DuckscriptSDKVersion`
```sh
var = duckscript_sdk_version
```
Returns the duckscript SDK version.
2021-09-21 13:47:41 +00:00
### Parameters
None
2021-09-21 13:47:41 +00:00
### Return Value
The duckscript SDK version.
2021-09-21 13:47:41 +00:00
### Examples
```sh
version = duckscript_sdk_version
```
2021-09-21 13:45:27 +00:00
### Aliases:
duckscript_sdk_version
<a name="std__debug__DuckscriptVersion"></a>
2021-09-21 13:44:25 +00:00
## `std::debug::DuckscriptVersion`
```sh
var = duckscript_version
```
Returns the duckscript runtime version.
2021-09-21 13:47:41 +00:00
### Parameters
None
2021-09-21 13:47:41 +00:00
### Return Value
The duckscript runtime version.
2021-09-21 13:47:41 +00:00
### Examples
```sh
version = duckscript_version
```
2021-09-21 13:45:27 +00:00
### Aliases:
duckscript_version
<a name="std__debug__DumpInstructions"></a>
2021-09-21 13:44:25 +00:00
## `std::debug::DumpInstructions`
```sh
value = dump_instructions
```
Returns all script instructions structure (not script text) in textual form.
2021-09-21 13:47:41 +00:00
### Parameters
None
2021-09-21 13:47:41 +00:00
### Return Value
The script instructions.
2021-09-21 13:47:41 +00:00
### Examples
```sh
value = dump_instructions
found = contains ${value} dump_instructions
assert found
```
2021-09-21 13:45:27 +00:00
### Aliases:
dump_instructions
<a name="std__debug__DumpState"></a>
2021-09-21 13:44:25 +00:00
## `std::debug::DumpState`
```sh
value = dump_state
```
Returns all script state in textual form.
2021-09-21 13:47:41 +00:00
### Parameters
None
2021-09-21 13:47:41 +00:00
### Return Value
The script state.
2021-09-21 13:47:41 +00:00
### Examples
```sh
numbers = range -5 15
text = dump_instructions
found = contains ${text} -5
assert found
```
2021-09-21 13:45:27 +00:00
### Aliases:
dump_state
<a name="std__debug__DumpVariables"></a>
2021-09-21 13:44:25 +00:00
## `std::debug::DumpVariables`
```sh
value = dump_variables
```
Returns all script variables in textual form.
2021-09-21 13:47:41 +00:00
### Parameters
None
2021-09-21 13:47:41 +00:00
### Return Value
The script variables.
2021-09-21 13:47:41 +00:00
### Examples
```sh
one = set 1
two = set 2
values = array 1 2 yes true
numbers = range -5 15
text = dump_variables
found = contains ${text} two
assert found
found = contains ${text} 2
assert found
found = contains ${text} handle
assert found
```
2021-09-21 13:45:27 +00:00
### Aliases:
dump_variables
2020-04-14 13:36:27 +00:00
<a name="std__env__EnvToMap"></a>
2021-09-21 13:44:25 +00:00
## `std::env::EnvToMap`
2020-04-14 13:36:27 +00:00
```sh
handle = env_to_map
```
Converts all environment variables to a map and returns the map handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-14 13:36:27 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-14 13:36:27 +00:00
The map handle.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-14 13:36:27 +00:00
```sh
set_env env_to_map_test test_value
handle = env_to_map
value = map_get ${handle} env_to_map_test
assert_eq ${value} test_value
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-14 13:36:27 +00:00
env_to_map
2020-04-14 22:55:58 +00:00
<a name="std__env__FindExecutable"></a>
2021-09-21 13:44:25 +00:00
## `std::env::FindExecutable`
2020-04-14 22:55:58 +00:00
```sh
var = which executable
```
2020-10-06 18:42:45 +00:00
Returns the path to the executable if it exists.<br>
2020-04-14 22:55:58 +00:00
If not found it will return an empty string.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-14 22:55:58 +00:00
The executable to find.
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-14 22:55:58 +00:00
The executable path or empty string if not found.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-14 22:55:58 +00:00
```sh
path = which echo
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-14 22:55:58 +00:00
which
2020-04-14 22:15:34 +00:00
<a name="std__env__GetCpuCount"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetCpuCount`
2020-04-14 22:15:34 +00:00
```sh
var = cpu_count
```
Returns the number of CPUs.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-14 22:15:34 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-14 22:15:34 +00:00
The CPU count.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-14 22:15:34 +00:00
```sh
count = cpu_count
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-14 22:15:34 +00:00
cpu_count, get_cpu_count
2020-01-25 16:34:22 +00:00
<a name="std__env__GetHomeDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetHomeDirectory`
2020-01-25 16:34:22 +00:00
```sh
var = get_home_dir
```
Returns the user home directory path.<br>
In case of any error, false will be returned.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-25 16:34:22 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-25 16:34:22 +00:00
The user home directory path or false in case of any error.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-25 16:34:22 +00:00
```sh
directory = get_home_dir
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-25 16:34:22 +00:00
get_home_dir
2020-03-07 21:13:39 +00:00
<a name="std__env__GetOSFamily"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetOSFamily`
2020-03-07 21:13:39 +00:00
```sh
var = os_family
```
Returns the OS family (windows, linux, mac).
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:13:39 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 21:13:39 +00:00
The OS family (windows, linux, mac).
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 21:13:39 +00:00
```sh
name = os_family
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 21:13:39 +00:00
os_family
<a name="std__env__GetOSName"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetOSName`
2020-03-07 21:13:39 +00:00
```sh
var = os_name
```
Returns the OS name.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:13:39 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 21:13:39 +00:00
The OS name.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 21:13:39 +00:00
```sh
name = os_name
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 21:13:39 +00:00
os_name
<a name="std__env__GetOSRelease"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetOSRelease`
2020-03-07 21:13:39 +00:00
```sh
var = os_release
```
2020-03-07 21:28:47 +00:00
Returns the OS release.<br>
**This command is not supported on windows.**
2020-03-07 21:13:39 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:13:39 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 21:13:39 +00:00
The OS release.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 21:13:39 +00:00
```sh
release = os_release
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 21:13:39 +00:00
os_release
<a name="std__env__GetOSVersion"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetOSVersion`
2020-03-07 21:13:39 +00:00
```sh
var = os_version
```
2020-03-07 21:28:47 +00:00
Returns the OS version.<br>
**This command is not supported on windows.**
2020-03-07 21:13:39 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:13:39 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 21:13:39 +00:00
The OS version.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 21:13:39 +00:00
```sh
version = os_version
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 21:13:39 +00:00
os_version
<a name="std__env__GetUserName"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetUserName`
2020-03-07 21:13:39 +00:00
```sh
var = whoami
```
Returns the current user name.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:13:39 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 21:13:39 +00:00
The current user name.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 21:13:39 +00:00
```sh
name = whoami
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 21:13:39 +00:00
whoami, get_user_name
<a name="std__env__GetVar"></a>
2021-09-21 13:44:25 +00:00
## `std::env::GetVar`
2019-12-30 10:45:28 +00:00
```sh
var = get_env key
```
Returns the environment variable value for the provided key.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
First argument is the environment variable key.
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The environment variable value.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
home = get_env HOME
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
get_env
2020-03-07 21:13:39 +00:00
<a name="std__env__IsWindows"></a>
2021-09-21 13:44:25 +00:00
## `std::env::IsWindows`
2020-03-07 21:13:39 +00:00
```sh
var = is_windows
```
Returns true if the current OS family is windows.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:13:39 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 21:13:39 +00:00
True if the current OS family is windows.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 21:13:39 +00:00
```sh
windows = is_windows
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-03-07 21:13:39 +00:00
```sh
scope::is_windows::os = os_family
equals ${scope::is_windows::os} windows
```
2021-09-21 13:31:05 +00:00
</details>
2020-03-07 21:13:39 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 21:13:39 +00:00
is_windows
<a name="std__env__PrintCurrentDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::env::PrintCurrentDirectory`
2019-12-30 10:45:28 +00:00
```sh
var = pwd
```
Prints and also returns the current directory.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The current directory path.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:32:48 +00:00
# Print the current directory:
2019-12-30 10:45:28 +00:00
pwd
2020-01-02 22:32:48 +00:00
# Print and also store the current directory:
2019-12-30 10:45:28 +00:00
directory = pwd
```
2021-09-21 13:45:27 +00:00
### Aliases:
pwd, print_current_directory
2019-12-30 10:45:28 +00:00
2020-04-14 13:51:24 +00:00
<a name="std__env__PrintEnv"></a>
2021-09-21 13:44:25 +00:00
## `std::env::PrintEnv`
2020-04-14 13:51:24 +00:00
```sh
var = printenv
```
Prints and returns all environment variables.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-14 13:51:24 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-14 13:51:24 +00:00
All environment variables printout text.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-14 13:51:24 +00:00
```sh
set_env TEST_PRINT_ENV TRUE
text = printenv
valid = contains ${text} TEST_PRINT_ENV=TRUE
assert ${valid}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-04-14 13:51:24 +00:00
```sh
scope::print_env::map = env_to_map
scope::print_env::text = map_to_properties ${scope::print_env::map}
release ${scope::print_env::map}
echo ${scope::print_env::text}
set ${scope::print_env::text}
```
2021-09-21 13:31:05 +00:00
</details>
2020-04-14 13:51:24 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-14 13:51:24 +00:00
print_env, printenv
<a name="std__env__SetCurrentDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::env::SetCurrentDirectory`
2020-01-02 22:40:24 +00:00
```sh
cd path
```
Sets the current directory based on the input path.<br>
If no path is provided, it will default to the user home directory.<br>
If the path does not exist, it will return none.
2020-01-02 22:40:24 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 22:40:24 +00:00
The new current directory.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 22:40:24 +00:00
The new current directory or none in case of any error such as target directory not found.
2020-01-02 22:40:24 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 22:40:24 +00:00
```sh
# Move to user home directory and store the path in the home variable
home = cd
# Move to the requested directory
cd ./scripts
```
2021-09-21 13:45:27 +00:00
### Aliases:
cd, set_current_dir, set_current_directory
2020-01-02 22:40:24 +00:00
<a name="std__env__SetVar"></a>
2021-09-21 13:44:25 +00:00
## `std::env::SetVar`
2019-12-30 10:45:28 +00:00
```sh
var = set_env (key value | --handle map_handle)
2019-12-30 10:45:28 +00:00
```
Sets the environment variable defined by the provided key to the provided value.<br>
If --handle is provided, the second arg will be used as a handle to a map and all keys/values in the map will be set.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
The function can be invoked in the following ways:
* Key/Value pair - Two arguments are required:
* key - The name of the environment variable to set
* value - The new environment variable value
* Map handle - Two arguments are required:
* --handle
* The map handle
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
2020-01-22 20:08:11 +00:00
true if successful
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
set_env HOME /usr/me
2021-09-13 17:05:33 +00:00
handle = map
map_put ${handle} mapkey1 mapvalue1
map_put ${handle} mapkey2 mapvalue2
set_env --handle ${handle}
# load env file
text = readfile ./test.env
handle = map
map_load_properties ${handle} ${text}
set_env --handle ${handle}
2019-12-30 10:45:28 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
set_env
<a name="std__env__UName"></a>
2021-09-21 13:44:25 +00:00
## `std::env::UName`
```sh
var = uname [-a]
```
Acts similar to uname on unix like systems.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 21:28:47 +00:00
* Optional -a for extended information (not supported on windows).
2021-09-21 13:47:41 +00:00
### Return Value
The OS name and optionally extra information.
2021-09-21 13:47:41 +00:00
### Examples
```sh
value = uname -a
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
```sh
scope::uname::extended_info = equals -a ${scope::uname::argument::1}
scope::uname::info = os_name
2020-03-07 21:28:47 +00:00
scope::uname::not_windows = not is_windows
if ${scope::uname::extended_info} and ${scope::uname::not_windows}
scope::uname::release = os_release
scope::uname::version = os_version
scope::uname::info = set "${scope::uname::info} ${scope::uname::release} ${scope::uname::version}"
end
set ${scope::uname::info}
```
2021-09-21 13:31:05 +00:00
</details>
2021-09-21 13:45:27 +00:00
### Aliases:
uname
<a name="std__env__UnsetVar"></a>
2021-09-21 13:44:25 +00:00
## `std::env::UnsetVar`
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:40:24 +00:00
unset_env key
2019-12-30 10:45:28 +00:00
```
2020-01-02 22:40:24 +00:00
Removes the environment variable defined by the provided key.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
2020-01-02 22:40:24 +00:00
The name of the environment variable to remove
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
2020-01-02 22:40:24 +00:00
None
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:40:24 +00:00
unset_env HOME
2019-12-30 10:45:28 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 22:40:24 +00:00
unset_env
2019-12-30 10:45:28 +00:00
2020-01-08 22:06:42 +00:00
<a name="std__error__GetLastError"></a>
2021-09-21 13:44:25 +00:00
## `std::error::GetLastError`
2020-01-08 22:06:42 +00:00
```sh
var = get_last_error
```
In case of any runtime error, this function will return the error message.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-08 22:06:42 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-08 22:06:42 +00:00
The last error message or none
2021-09-21 13:47:41 +00:00
### Examples
2020-01-08 22:06:42 +00:00
```sh
# This will trigger an error
assert_fail
error = get_last_error
echo Error Message: ${error}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-08 22:06:42 +00:00
get_last_error
<a name="std__error__GetLastErrorLine"></a>
2021-09-21 13:44:25 +00:00
## `std::error::GetLastErrorLine`
2020-01-08 22:06:42 +00:00
```sh
var = get_last_error_line
```
In case of any runtime error, this function will return the error line (if available).
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-08 22:06:42 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-08 22:06:42 +00:00
The last error line or none
2021-09-21 13:47:41 +00:00
### Examples
2020-01-08 22:06:42 +00:00
```sh
# This will trigger an error
assert_fail
line = get_last_error_line
echo Error Line: ${line}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-08 22:06:42 +00:00
get_last_error_line
<a name="std__error__GetLastErrorSource"></a>
2021-09-21 13:44:25 +00:00
## `std::error::GetLastErrorSource`
2020-01-08 22:06:42 +00:00
```sh
var = get_last_error_source
```
In case of any runtime error, this function will return the error source (such as file name) if available.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-08 22:06:42 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-08 22:06:42 +00:00
The last error source or none
2021-09-21 13:47:41 +00:00
### Examples
2020-01-08 22:06:42 +00:00
```sh
# This will trigger an error
assert_fail
source = get_last_error_source
echo Error Source File: ${source}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-08 22:06:42 +00:00
get_last_error_source
2020-01-22 20:28:55 +00:00
<a name="std__error__SetError"></a>
2021-09-21 13:44:25 +00:00
## `std::error::SetError`
2020-01-22 20:28:55 +00:00
```sh
set_error message
```
Sets the last error which is accessible via get_last_error.<br>
This command will not trigger the on_error command flow.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-22 20:28:55 +00:00
The error message.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-22 20:28:55 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-01-22 20:28:55 +00:00
```sh
set_error "my error message"
error = get_last_error
assert_eq ${error} "my error message"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-22 20:28:55 +00:00
set_error
2020-01-10 16:19:31 +00:00
<a name="std__error__SetExitOnError"></a>
2021-09-21 13:44:25 +00:00
## `std::error::SetExitOnError`
2020-01-10 16:19:31 +00:00
```sh
var = exit_on_error value
```
Enables to cause the script execution to stop in case of any error.<br>
By default all errors simply trigger the on_error command which the default SDK stores and provides access to.<br>
However, with this command you can change the on_error command to instead stop the script execution.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-10 16:19:31 +00:00
If no argument is provided, it will return the current state.<br>
If an argument is provided, it will modify the state and return it as true/false.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-10 16:19:31 +00:00
The current/updated state as true/false value
2021-09-21 13:47:41 +00:00
### Examples
2020-01-10 16:19:31 +00:00
```sh
# Get current state
will_exit = exit_on_error
echo Current state: ${will_exit}
# Update the current state
will_exit = exit_on_error true
echo Current state: ${will_exit}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-10 16:19:31 +00:00
exit_on_error, set_exit_on_error
2020-01-24 16:45:15 +00:00
<a name="std__error__TriggerError"></a>
2021-09-21 13:44:25 +00:00
## `std::error::TriggerError`
2020-01-24 16:45:15 +00:00
```sh
trigger_error [message]
```
Triggers an error that will trigger the on_error flow.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-24 16:45:15 +00:00
Optional error message.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-24 16:45:15 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-01-24 16:45:15 +00:00
```sh
trigger_error "my error message"
error = get_last_error
assert_eq ${error} "my error message"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-24 16:45:15 +00:00
trigger_error
2020-02-05 19:14:39 +00:00
<a name="std__flowcontrol__ForIn"></a>
2021-09-21 13:44:25 +00:00
## `std::flowcontrol::ForIn`
2020-02-05 19:13:09 +00:00
```sh
args = array a b c
for arg in ${args}
# commands
end
release args
```
The for/in command enables to iterate over an array (see [array command](#std__collections__Array)).<br>
The first argument will contain the current iteration value from the array.<br>
Once all values have been read, it will exit the loop.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-05 19:13:09 +00:00
* for
* The variable name which will hold the current iteration value
* The string "in"
* The handle to the array of values to iterate
* end - no parameters
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-05 19:13:09 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-02-05 19:13:09 +00:00
```sh
# Simple example iteration over the list of letters:
args = array a b c
for arg in ${args}
echo current arg is: ${arg}
end
release args
# Example nested loops:
args = array 1 2 3
for i in ${args}
for j in ${args}
echo i: ${i} j: ${j}
end
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
for
2020-02-05 19:14:39 +00:00
<a name="std__flowcontrol__Function"></a>
2021-09-21 13:44:25 +00:00
## `std::flowcontrol::Function`
2020-02-05 19:13:09 +00:00
```sh
2020-07-24 14:51:06 +00:00
fn my_function
2020-02-05 19:13:09 +00:00
# function content
return output
end
2020-07-24 14:51:06 +00:00
fn <scope> another_function
# function content
end
2020-02-05 19:13:09 +00:00
```
This command provides the function language feature as a set of commands:
2020-07-24 14:51:06 +00:00
* function/fn - Defines a function start block
2020-02-05 19:13:09 +00:00
* end - Defines the end of the function block
2020-10-06 08:54:20 +00:00
* return - Allows to exit a function at any point and return an output
2020-07-24 15:23:33 +00:00
* *&lt;scope&gt;* - Optional annotation which enables to use a new scope during the function invocation.
2020-02-05 19:13:09 +00:00
* *function name* - Dynamically created commands based on the function name which are used to invoke the function code.
When a function command is detected, it will search for the end command that comes after.<br>
That entire block is considered the function code block (functions cannot be nested in outer functions)<br>
2020-11-18 23:05:39 +00:00
In order to invoke the function, simply call the function name with any amount of parameters.<br>
2020-05-02 11:24:54 +00:00
Those parameters will be set as ${1}, ${2}, ... and so on.<br>
2020-02-05 19:13:09 +00:00
Since variables are global, it will overwrite any older values stored in those variables.<br>
2020-10-06 08:54:20 +00:00
To exit a function and return a value, simply use the **return** command with the value you want to return.<br>
2020-02-05 19:13:09 +00:00
The variable that was used when the function was originally called, will now store that value.<br>
2020-10-06 08:54:20 +00:00
The return command can be used to exit early without any value.<br>
In case the code reached the **end** call, the function will exit but will not return a value.<br>
2020-07-24 14:51:06 +00:00
2020-07-24 15:23:33 +00:00
The *&lt;scope&gt;* annotation enables to start a new scope when running the function.<br>
2020-07-24 14:51:06 +00:00
All variables defined will not be available except the variables provided to the function as arguments.<br>
All variables created during the function invocation will be deleted once the function ends, except the return value.<br>
This enables a clean function invocation without impacting the global variables.
2020-02-05 19:13:09 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-05 19:13:09 +00:00
* function - The function name used later on to invoke the function
* end - no parameters
2020-11-19 11:36:41 +00:00
* return - optional single parameter to return as an output of the function call
2020-07-24 15:23:33 +00:00
* *&lt;scope&gt;* - Optional annotation which enables to use a new scope during the function invocation.
2020-05-02 11:24:54 +00:00
* *function name* - Any number of arguments which will automatically be set as global variables: ${1}, ${2}, ... as so on.
2020-02-05 19:13:09 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-05 19:13:09 +00:00
The function invocation returns the output provided by the return command.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-05 19:13:09 +00:00
```sh
2020-10-06 08:54:20 +00:00
# Simple example of a function definition which echo 'hello world' and exits.
2020-02-05 19:13:09 +00:00
# function start
2020-04-03 10:34:00 +00:00
fn hello_world
2020-02-05 19:13:09 +00:00
echo hello world
end
# function invocation
hello_world
# Example of calling a function and returning a value
2020-04-03 10:34:00 +00:00
fn get_hello_world
2020-02-05 19:13:09 +00:00
return "hello world"
end
# function invocation
text = get_hello_world
# this will print "hello world"
echo ${text}
# Example of passing arguments
2020-07-24 15:23:33 +00:00
# Also the function is with scope annotation so it has no access
# to any variable except those provided during the function invocation.
fn <scope> print_input
2020-05-02 11:24:54 +00:00
# ${1} is set with the value 'hello'
# ${2} is set with the value 'world'
2020-02-05 19:13:09 +00:00
echo ${1} ${2}
end
print_input hello world
# Functions can call other functions
2020-04-03 10:34:00 +00:00
fn get_one
2020-02-05 19:13:09 +00:00
return 1
end
2020-04-03 10:34:00 +00:00
fn get_number
2020-02-05 19:13:09 +00:00
number = get_one
return ${number}
end
output = get_number
# this will print 1
echo ${output}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
function, fn
2020-02-05 19:14:39 +00:00
<a name="std__flowcontrol__GoTo"></a>
2021-09-21 13:44:25 +00:00
## `std::flowcontrol::GoTo`
2020-02-05 19:13:09 +00:00
```sh
goto :label
```
The goto command enables you to jump to any position in the script, if that position has a label value.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-05 19:13:09 +00:00
A single valid label value.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-05 19:13:09 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-02-05 19:13:09 +00:00
```sh
goto :good
echo bad
:good echo good
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
goto
2020-02-05 19:14:39 +00:00
<a name="std__flowcontrol__If"></a>
2021-09-21 13:44:25 +00:00
## `std::flowcontrol::If`
2020-02-05 19:13:09 +00:00
```sh
if [command|value|condition]
# commands
2020-04-03 10:34:00 +00:00
elseif [command|value|condition]
2020-02-05 19:13:09 +00:00
# commands
else
# commands
end
```
This command provides the if/elseif/else condition language feature as a set of commands:
* if - Defines an if condition
* elseif - Defines optional secondary condition blocks
* else - Optinoal fallback block
* end - Defines the end of the entire if/else block
if and elseif commands accept either:
* A command with optional arguments and invokes it
* A single value which doesn't match any known command
* A condition statement
If the result is one of the following:
* No output
* false (case insensitive)
* 0
* no (case insensitive)
* Empty value
It is considered falsy.<br>
In case of falsy value, it will skip to the next elseif/else block.<br>
If a truthy (non falsy) output is found, it will invoke the commands of that code block and ignore all other elseif/else blocks.<br>
if blocks can be nested in other if blocks (see examples).
A condition statement is made up of values, or/and keywords and '('/')' groups.<br>
Each must be separated with a space character.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-05 19:13:09 +00:00
* if/elseif - A command and its arguments to invoke and evaluate its output, if a single value is provided an no such command exists, it is evaluated as a value.
* else/end - no parameters
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-05 19:13:09 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-02-05 19:13:09 +00:00
```sh
# Simple example of an if statement that evaluates the argument value as true and echos "in if"
if true
echo in if
end
# Example of using **not** command to reverse the output value
if not false
echo in if
end
# Example of an if statement that evaluates the command as true and echos "in if"
if set true
echo in if
end
# Example of if condition returning a falsy result and navigation goes to the else block which echos "in else"
if set false
echo should not be here
else
echo in else
end
# Example of if condition returning a falsy result and navigation goes to the elseif block has a truthy condition
if set false
echo should not be here
elseif set true
echo in else if
else
echo should not be here
end
# Nested if example:
if set false
echo should not be here
elseif set true
echo in else if but not done yet
if set true
echo nested if
end
else
echo should not be here
end
valid = set false
if true and false or true and false or ( true and true or false )
valid = set true
end
assert ${valid}
if true and false or true and false or ( true and true or false ) and false
assert_fail
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-05 19:13:09 +00:00
if
2020-11-15 14:01:00 +00:00
<a name="std__flowcontrol__While"></a>
2021-09-21 13:44:25 +00:00
## `std::flowcontrol::While`
2020-11-15 14:01:00 +00:00
```sh
while [command|value|condition]
# commands
end
```
This command provides the while loop language feature as a set of commands:
* while - Defines a while condition and start of loop
* end - Defines the end of the while block
The while command accept either:
* A command with optional arguments and invokes it
* A single value which doesn't match any known command
* A condition statement
If the result is one of the following:
* No output
* false (case insensitive)
* 0
* no (case insensitive)
* Empty value
It is considered falsy.<br>
In case of falsy value, it will skip to the next line after the while block.<br>
If a truthy (non falsy) output is found, it will invoke the commands of that code block and go back to the start of the while condition.<br>
while blocks can be nested in other while blocks (see examples).
A condition statement is made up of values, or/and keywords and '('/')' groups.<br>
Each must be separated with a space character.
2021-09-21 13:47:41 +00:00
### Parameters
2020-11-15 14:01:00 +00:00
* while - A command and its arguments to invoke and evaluate its output, if a single value is provided an no such command exists, it is evaluated as a value.
* end - no parameters
2021-09-21 13:47:41 +00:00
### Return Value
2020-11-15 14:01:00 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-11-15 14:01:00 +00:00
```sh
top_count = set 0
inner_count = set 0
counter = set 0
while not equals ${top_count} 10
top_count = calc ${top_count} + 1
inner_count = set 0
while not equals ${inner_count} 10
inner_count = calc ${inner_count} + 1
counter = calc ${counter} + 1
end
end
assert_eq ${counter} 100
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-11-15 14:01:00 +00:00
while
2020-01-26 21:26:25 +00:00
<a name="std__fs__Append"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::Append`
2020-01-26 21:26:25 +00:00
```sh
result = appendfile file text
```
This command enables to write the provided text into the requested file.<br>
It will return true/false value based if it was able to write the text to the file.<br>
In case the file doesn't exist, it will create it.<br>
If the file exists, it will append the text to it.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-26 21:26:25 +00:00
* The target file
* The text content to write
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-26 21:26:25 +00:00
true/false based if it was able to write the text to the file.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-26 21:26:25 +00:00
```sh
out = appendfile ./target/tests/writefile.txt "line 1\nline 2"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-26 21:26:25 +00:00
appendfile
2021-09-13 15:41:26 +00:00
<a name="std__fs__CPGlob"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::CPGlob`
2021-09-13 15:41:26 +00:00
```sh
result = glob_cp source_glob target
```
This command will copy all files that match the given glob.
2021-09-21 13:47:41 +00:00
### Parameters
2021-09-13 15:41:26 +00:00
* The source glob, for example ./*.txt
* The target path
2021-09-21 13:47:41 +00:00
### Return Value
2021-09-13 15:41:26 +00:00
The amount of paths (files) copied or false in case of any error.
2021-09-21 13:47:41 +00:00
### Examples
2021-09-13 15:41:26 +00:00
```sh
count = glob_cp ./**/*.txt ../target
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2021-09-13 15:41:26 +00:00
```sh
2021-09-20 13:50:11 +00:00
scope::glob_cp::contains_glob = contains ${scope::glob_cp::argument::1} *
2021-09-13 15:41:26 +00:00
scope::glob_cp::target = set ${scope::glob_cp::argument::2}
2021-09-20 13:50:11 +00:00
scope::glob_cp::output = set 0
2021-09-13 15:41:26 +00:00
2021-09-20 13:50:11 +00:00
if ${scope::glob_cp::contains_glob}
scope::glob_cp::handle = glob_array ${scope::glob_cp::argument::1}
scope::glob_cp::glob_empty = array_is_empty ${scope::glob_cp::handle}
2021-09-13 15:41:26 +00:00
2021-09-20 13:50:11 +00:00
if not ${scope::glob_cp::glob_empty}
scope::glob_cp::is_relative = starts_with ${scope::glob_cp::argument::1} .
if not ${scope::glob_cp::is_relative}
scope::glob_cp::top_dir_without_glob = set ${scope::glob_cp::argument::1}
while contains ${scope::glob_cp::top_dir_without_glob} *
scope::glob_cp::top_dir_without_glob = dirname ${scope::glob_cp::top_dir_without_glob}
end
scope::glob_cp::absolute_prefix_length = strlen ${scope::glob_cp::top_dir_without_glob}
end
for scope::glob_cp::entry in ${scope::glob_cp::handle}
scope::glob_cp::is_file = is_file ${scope::glob_cp::entry}
if ${scope::glob_cp::is_file}
if ${scope::glob_cp::is_relative}
scope::glob_cp::target_file = join_path ${scope::glob_cp::target} ${scope::glob_cp::entry}
else
scope::glob_cp::target_file = substring ${scope::glob_cp::entry} ${scope::glob_cp::absolute_prefix_length}
scope::glob_cp::target_file = join_path ${scope::glob_cp::target} ${scope::glob_cp::target_file}
end
scope::glob_cp::done = cp ${scope::glob_cp::entry} ${scope::glob_cp::target_file}
2021-09-13 15:41:26 +00:00
2021-09-20 13:50:11 +00:00
if ${scope::glob_cp::done}
scope::glob_cp::output = calc ${scope::glob_cp::output} + 1
end
end
end
2021-09-13 15:41:26 +00:00
end
2021-09-20 13:50:11 +00:00
release ${scope::glob_cp::handle}
else
scope::glob_cp::is_file = is_file ${scope::glob_cp::argument::1}
if ${scope::glob_cp::is_file}
scope::glob_cp::filename = basename ${scope::glob_cp::argument::1}
scope::glob_cp::done = cp ${scope::glob_cp::argument::1} ${scope::glob_cp::target}/${scope::glob_cp::filename}
if ${scope::glob_cp::done}
scope::glob_cp::output = set 1
end
end
end
2021-09-13 15:41:26 +00:00
set ${scope::glob_cp::output}
```
2021-09-21 13:31:05 +00:00
</details>
2021-09-13 15:41:26 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-09-13 15:41:26 +00:00
glob_cp, cp_glob
<a name="std__fs__CopyPath"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::CopyPath`
2020-01-03 10:07:43 +00:00
```sh
var = cp source target
```
This command copies the requested file or directory to the target location.<br>
If the source directory is not empty, its entire contents will be copied as well.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-03 10:07:43 +00:00
* The source path to copy
* The target path
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-03 10:07:43 +00:00
**true** if the path was copied.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-03 10:07:43 +00:00
```sh
# copy a single file
copied = cp ./file1.txt ./file2.txt
# copy a directory
copied = cp ./source ./target
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-03 10:07:43 +00:00
cp
<a name="std__fs__CreateDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::CreateDirectory`
2020-01-01 18:59:33 +00:00
```sh
var = mkdir directory
```
This command will create the requested directory (and needed parent directories) and return true/false if it was successful.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-01 18:59:33 +00:00
The directory name to create.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-01 18:59:33 +00:00
The operation success value - true if directory exists, else false.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-01 18:59:33 +00:00
```sh
exists = mkdir ./dir/subdir
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-01 18:59:33 +00:00
mkdir
<a name="std__fs__CreateEmptyFile"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::CreateEmptyFile`
2020-01-01 19:40:19 +00:00
```sh
var = touch file
```
This command will create an empty file and return true/false if the file exists.<br>
If file exits, it will not be modified.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-01 19:40:19 +00:00
The file path.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-01 19:40:19 +00:00
If the file exists after the command, it will return true.<br>
In case of any error, it will return false.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-01 19:40:19 +00:00
```sh
exists = touch ./dir/file.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-01 19:40:19 +00:00
touch
<a name="std__fs__DeleteEmptyDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::DeleteEmptyDirectory`
2020-01-02 17:03:26 +00:00
```sh
var = rmdir path
```
This command delete the requested empty directory and returns true if successful.<br>
2020-01-02 19:35:06 +00:00
If the path leads to a file or a directory which is not empty, this command will fail.
2020-01-02 17:03:26 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 17:03:26 +00:00
A single parameter holding the directory path.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 17:03:26 +00:00
**true** if the directory was deleted.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 17:03:26 +00:00
```sh
deleted = rmdir ./mydir
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 17:03:26 +00:00
rmdir
<a name="std__fs__DeletePath"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::DeletePath`
2020-01-02 19:35:06 +00:00
```sh
2021-01-20 16:57:57 +00:00
var = rm [-r] [path]+
2020-01-02 19:35:06 +00:00
```
2021-01-20 16:57:57 +00:00
This command delete the requested file/s, empty directories or recursively deletes directories
and all their content (files and sub directories) if the **-r** flag is provided.
2020-01-02 19:35:06 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 19:35:06 +00:00
* Optional flags (currently only -r is supported which indicates recursive deletion)
2021-01-20 16:57:57 +00:00
* The path/s to delete
2020-01-02 19:35:06 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 19:35:06 +00:00
2021-01-20 16:57:57 +00:00
**true** if all paths were deleted.
2020-01-02 19:35:06 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 19:35:06 +00:00
```sh
# delete a file or empty directory
deleted = rm ./target
# deletes a directory and all its content
deleted = rm -r ./target
2021-01-20 16:57:57 +00:00
# delete all provided paths
deleted = rm -r ./dir ./somefile ./anotherdir/subdir/file
2020-01-02 19:35:06 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 19:35:06 +00:00
rm
2020-03-06 11:08:51 +00:00
<a name="std__fs__Exists"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::Exists`
2020-03-06 11:08:51 +00:00
```sh
var = is_path_exists path
```
This command will return true/false based if the provided path points to an existing file system entry.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-06 11:08:51 +00:00
The path to check.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-06 11:08:51 +00:00
True if the path points to an existing file system entry.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-06 11:08:51 +00:00
```sh
existing = is_path_exists ./dir
existing = is_path_exists ./dir/somefile.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-06 11:08:51 +00:00
is_path_exists
<a name="std__fs__GetCanonicalPath"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::GetCanonicalPath`
2020-01-01 18:59:33 +00:00
```sh
var = canonicalize path
```
This command will return the c path for the provided input.<br>
In case unable, it will return the original input.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-01 18:59:33 +00:00
The file/directory path to canonicalize.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-01 18:59:33 +00:00
The canonicalized path, or if unsuccessful, the original path.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-01 18:59:33 +00:00
```sh
path = canonicalize ./target
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-01 18:59:33 +00:00
canonicalize
<a name="std__fs__GetFileName"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::GetFileName`
2020-01-01 18:59:33 +00:00
```sh
var = basename path
```
This command will return the last path element of the provided path.<br>
If unable, it will return none.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-01 18:59:33 +00:00
The path to extract the last element from.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-01 18:59:33 +00:00
The last path element or none if unsuccessful.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-01 18:59:33 +00:00
```sh
file = basename ./dir/file.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-01 18:59:33 +00:00
basename
2022-04-20 07:17:21 +00:00
<a name="std__fs__GetFileSize"></a>
## `std::fs::GetFileSize`
```sh
var = get_file_size path
```
This command will return the size of the file in bytes.
### Parameters
The path to check.
### Return Value
The size of the file in bytes or false in case path is a directory or does not exist.
### Examples
```sh
size = get_file_size ./dir/somefile.txt
```
### Aliases:
get_file_size, filesize
2020-07-07 21:25:27 +00:00
<a name="std__fs__GetLastModifiedTime"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::GetLastModifiedTime`
2020-07-07 21:25:27 +00:00
```sh
var = get_last_modified_time path
```
This command will return the last modified time in millies from unix epoch.
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-07 21:25:27 +00:00
The path to check.
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-07 21:25:27 +00:00
The last modified time in millies from unix epoch or false in case path does not exist.
2021-09-21 13:47:41 +00:00
### Examples
2020-07-07 21:25:27 +00:00
```sh
time = get_last_modified_time ./dir/somefile.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-07 21:25:27 +00:00
get_last_modified_time
<a name="std__fs__GetParentDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::GetParentDirectory`
2020-01-01 19:09:57 +00:00
```sh
var = dirname path
```
This command will return the parent path of the provided path.<br>
If the parent path is empty, it will return none.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-01 19:09:57 +00:00
The path to extract the parent path from.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-01 19:09:57 +00:00
The parent path or none.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-01 19:09:57 +00:00
```sh
directory = dirname ./dir/file.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-01 19:09:57 +00:00
dirname
2021-04-09 15:48:25 +00:00
<a name="std__fs__GitIgnorePathArray"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::GitIgnorePathArray`
2021-04-09 15:48:25 +00:00
```sh
2022-04-20 07:17:21 +00:00
handle = gitignore_path_array path
2021-04-09 15:48:25 +00:00
```
Returns an array handle containing all path entries found from the provided root path that should be included based on the gitignore definitions.
2021-09-21 13:47:41 +00:00
### Parameters
2021-04-09 15:48:25 +00:00
The root path.
2021-09-21 13:47:41 +00:00
### Return Value
2021-04-09 15:48:25 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Examples
2021-04-09 15:48:25 +00:00
```sh
handle = gitignore_path_array ./src
for path in ${handle}
echo ${path}
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2021-04-09 15:48:25 +00:00
gitignore_path_array
2020-03-07 17:52:23 +00:00
<a name="std__fs__GlobArray"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::GlobArray`
2020-03-07 17:52:23 +00:00
```sh
2022-04-18 21:23:16 +00:00
handle = glob_array pattern
2020-03-07 17:52:23 +00:00
```
Returns an array handle containing all path entries found from the provided glob pattern.<br>
The pattern can be a relative path from current directory or an absolute path.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 17:52:23 +00:00
The glob pattern.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 17:52:23 +00:00
The array handle.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 17:52:23 +00:00
```sh
handle = glob_array ./somedir/**/*.txt
for path in ${handle}
echo ${path}
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-07 17:52:23 +00:00
glob_array, globarray
2020-03-06 11:02:52 +00:00
<a name="std__fs__IsDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::IsDirectory`
2020-03-06 11:02:52 +00:00
```sh
var = is_dir path
```
This command will return true/false based if the provided path points to an existing directory.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-06 11:02:52 +00:00
The path to check.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-06 11:02:52 +00:00
True if the path points to an existing directory.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-06 11:02:52 +00:00
```sh
existing_dir = is_dir ./dir
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-06 11:02:52 +00:00
is_directory, is_dir
<a name="std__fs__IsFile"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::IsFile`
2020-03-06 11:02:52 +00:00
```sh
var = is_file path
```
This command will return true/false based if the provided path points to an existing file.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-06 11:02:52 +00:00
The path to check.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-06 11:02:52 +00:00
True if the path points to an existing file.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-06 11:02:52 +00:00
```sh
existing_file = is_file ./dir/somefile.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-06 11:02:52 +00:00
is_file
2020-07-07 22:24:26 +00:00
<a name="std__fs__IsPathNewer"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::IsPathNewer`
2020-07-07 22:24:26 +00:00
```sh
var = is_path_newer newer older
```
This command will return true if the 'newer' path last modified time is after the 'older' path last modified time.
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-07 22:24:26 +00:00
* newer - The file/directory path to check.
* older - The file/directory path to check.
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-07 22:24:26 +00:00
True if the 'newer' path last modified time is after the 'older' path last modified time.
Otherwise or in case of an error, false will be returned.
2021-09-21 13:47:41 +00:00
### Examples
2020-07-07 22:24:26 +00:00
```sh
newer = is_path_newer ./new_file.txt ./old_file.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-07 22:24:26 +00:00
is_path_newer
2020-03-06 13:20:54 +00:00
<a name="std__fs__IsReadonly"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::IsReadonly`
2020-03-06 13:20:54 +00:00
```sh
var = is_readonly path
```
This command will return true/false based if the provided path exists and is set to readonly.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-06 13:20:54 +00:00
The path to check.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-06 13:20:54 +00:00
True if the provided path exists and is set to readonly.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-06 13:20:54 +00:00
```sh
readonly = is_readonly ./dir/somefile.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-06 13:20:54 +00:00
is_readonly
2021-09-13 15:41:26 +00:00
<a name="std__fs__JoinPath"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::JoinPath`
2021-09-13 15:41:26 +00:00
```sh
result = join_path path [path]*
```
Concats all paths and makes sure there is a / character between each path element.
2021-09-21 13:47:41 +00:00
### Parameters
2021-09-13 15:41:26 +00:00
* A list of paths to join
2021-09-21 13:47:41 +00:00
### Return Value
2021-09-13 15:41:26 +00:00
The joined path
2021-09-21 13:47:41 +00:00
### Examples
2021-09-13 15:41:26 +00:00
```sh
joined = join_path /test /dir1 /dir2 dir3 //dir4// /dir5
assert_eq ${joined} /test/dir1/dir2/dir3/dir4/dir5
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2021-09-13 15:41:26 +00:00
```sh
scope::join_path::added = set false
for scope::join_path::path in ${scope::join_path::arguments}
if ${scope::join_path::added}
scope::join_path::output = set "${scope::join_path::output}/${scope::join_path::path}"
else
scope::join_path::output = set ${scope::join_path::path}
scope::join_path::added = set true
end
end
while contains ${scope::join_path::output} //
scope::join_path::output = replace ${scope::join_path::output} // /
end
set ${scope::join_path::output}
```
2021-09-21 13:31:05 +00:00
</details>
2021-09-13 15:41:26 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-09-13 15:41:26 +00:00
join_path
<a name="std__fs__List"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::List`
2020-01-03 11:38:45 +00:00
```sh
var = ls [flags] [path]
```
Lists the file/directory contents.<br>
If no path is provided, the current working directory will be used.<br>
The supported flags are:
* -l - Shows extended information
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-03 11:38:45 +00:00
* Optional flags (currently only -l is supported)
* Optional path (if not provided, current working directory is used)
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-03 11:38:45 +00:00
**true** is operation was successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-03 11:38:45 +00:00
```sh
# prints current directory content
ls
# prints current directory content
ls .
# prints examples directory content
ls ./examples
# prints examples directory content with extended info
ls -l ./examples
# prints current directory content with extended info
ls -l
# prints file name
ls ./examples/ls.ds
# prints file name with extended info
ls -l ./examples/ls.ds
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-03 11:38:45 +00:00
ls
<a name="std__fs__MovePath"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::MovePath`
2020-01-02 22:32:48 +00:00
```sh
var = mv source target
```
This command moves the requested source path to the target path.
* If the source and target paths define a file, it will move the file as defined.
* If target path is a directory path, it will move the source file/directory into that target directory path.
All missing parent directories in the target path will be created as needed.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 22:32:48 +00:00
* The source path to copy
* The target path
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 22:32:48 +00:00
**true** if the move was successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 22:32:48 +00:00
```sh
# move a single file
moved = mv ./file1.txt ./file2.txt
# move a single file into the target directory
moved = mv ./file1.txt ./somedir
# move entire directory into another directory
moved = mv ./source ./target/subdir
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 22:32:48 +00:00
mv
<a name="std__fs__Print"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::Print`
2019-12-30 10:45:28 +00:00
```sh
var = cat [file]+
2019-12-30 10:45:28 +00:00
```
The cat command will print out the requested file/s.<br>
2019-12-30 10:45:28 +00:00
In addition it will also return the value to the output variable.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
Multiple file paths.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The file content or none if the file does not exist.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
cat ./docs/sdk.md
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
cat
<a name="std__fs__ReadBytes"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::ReadBytes`
```sh
handle = read_binary_file file
```
Reads a raw file and returns a handle to the binary data.
2021-09-21 13:47:41 +00:00
### Parameters
A single parameter holding the file path.
2021-09-21 13:47:41 +00:00
### Return Value
The binary data handle.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = read_binary_file ./Cargo.toml
text = bytes_to_string ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
readbinfile, read_binary_file
2020-01-30 22:56:17 +00:00
<a name="std__fs__ReadText"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::ReadText`
2019-12-30 10:45:28 +00:00
```sh
var = readfile file
```
The readfile command will read the requested file and return the value to the output variable.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
A single parameter holding the file path.
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The file content or none in case file does not exist.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
text = readfile ./Cargo.toml
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-30 22:56:17 +00:00
readfile, read_text_file
2019-12-30 10:45:28 +00:00
2020-03-06 15:57:00 +00:00
<a name="std__fs__SetMode"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::SetMode`
2020-03-06 15:57:00 +00:00
```sh
result = chmod mode path
```
This command will update the mode for the given path.<br>
**This command is currently only available for unix like systems and will return false for all others such as windows.**
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-06 15:57:00 +00:00
* The new mode, for example 755
* The path
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-06 15:57:00 +00:00
The new mode as decimal number or false in case of any error.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-06 15:57:00 +00:00
```sh
chmod 777 ./myfile.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-06 15:57:00 +00:00
chmod
2020-03-07 18:56:48 +00:00
<a name="std__fs__SetModeGlob"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::SetModeGlob`
2020-03-07 18:56:48 +00:00
```sh
result = glob_chmod mode glob
```
This command will update the mode for the given glob pattern.<br>
**This command is currently only available for unix like systems and will return false for all others such as windows.**
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-07 18:56:48 +00:00
* The new mode, for example 755
* The path glob
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-07 18:56:48 +00:00
The amount of path entries affected by the operation or false in case of any error.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-07 18:56:48 +00:00
```sh
2020-03-23 19:08:10 +00:00
file1 = set ./target/_duckscript_test/glob_chmod/modify1.txt
2020-03-07 18:56:48 +00:00
touch ${file1}
2020-03-23 19:08:10 +00:00
file2 = set ./target/_duckscript_test/glob_chmod/modify2.txt
2020-03-07 18:56:48 +00:00
touch ${file2}
2020-03-23 19:08:10 +00:00
count = glob_chmod 777 ./target/_duckscript_test/glob_chmod/**/*.txt
2020-03-07 18:56:48 +00:00
assert_eq ${count} 2
readonly = is_readonly ${file1}
assert_false ${readonly}
readonly = is_readonly ${file2}
assert_false ${readonly}
2020-03-23 19:08:10 +00:00
count = glob_chmod 444 ./target/_duckscript_test/glob_chmod/**/*.txt
2020-03-07 18:56:48 +00:00
assert_eq ${count} 2
readonly = is_readonly ${file1}
assert ${readonly}
readonly = is_readonly ${file2}
assert ${readonly}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-03-07 18:56:48 +00:00
```sh
scope::glob_chmod::handle = glob_array ${scope::glob_chmod::argument::2}
scope::glob_chmod::output = array_length ${scope::glob_chmod::handle}
2020-03-07 18:56:48 +00:00
for scope::glob_chmod::entry in ${scope::glob_chmod::handle}
scope::glob_chmod::result = chmod ${scope::glob_chmod::argument::1} ${scope::glob_chmod::entry}
if equals ${scope::glob_chmod::result} false
release ${scope::glob_chmod::handle}
scope::glob_chmod::output = set false
end
2020-03-07 18:56:48 +00:00
end
release ${scope::glob_chmod::handle}
set ${scope::glob_chmod::output}
2020-03-07 18:56:48 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-03-07 18:56:48 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-09-13 15:41:26 +00:00
glob_chmod, chmod_glob
2020-03-07 18:56:48 +00:00
2020-04-14 07:29:53 +00:00
<a name="std__fs__TempDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::TempDirectory`
2020-04-14 07:29:53 +00:00
```sh
path = temp_dir
```
This command will return the system temporary directory path.
2021-09-21 13:47:41 +00:00
### Parameters
2020-04-14 07:29:53 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-04-14 07:29:53 +00:00
The directory path.
2021-09-21 13:47:41 +00:00
### Examples
2020-04-14 07:29:53 +00:00
```sh
path = temp_dir
echo ${path}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-04-14 07:29:53 +00:00
temp_dir
2020-02-19 18:19:12 +00:00
<a name="std__fs__TempFile"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::TempFile`
2020-02-19 18:19:12 +00:00
```sh
path = temp_file [extension]
```
This command will create a new empty temporary file and return its path.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-19 18:19:12 +00:00
Optional file extension.
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-19 18:19:12 +00:00
The file path.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-19 18:19:12 +00:00
```sh
path = temp_file toml
echo ${path}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-19 18:19:12 +00:00
temp_file
<a name="std__fs__WriteBytes"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::WriteBytes`
```sh
result = write_binary_file file handle
```
This command enables to write binary data of the provided binary handle into the requested file.<br>
It will return true/false value based if it was able to write the binary data to the file.
2021-09-21 13:47:41 +00:00
### Parameters
* The target file
* The binary data handle
2021-09-21 13:47:41 +00:00
### Return Value
true/false based if it was able to write the binary data to the file.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = string_to_bytes "some text"
result = write_binary_file ./target/tests/data.bin ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
writebinfile, write_binary_file
2020-01-30 22:56:17 +00:00
<a name="std__fs__WriteText"></a>
2021-09-21 13:44:25 +00:00
## `std::fs::WriteText`
2019-12-30 10:45:28 +00:00
```sh
result = writefile file text
```
This command enables to write the provided text into the requested file.<br>
It will return true/false value based if it was able to write the text to the file.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
* The target file
* The text content to write
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
true/false based if it was able to write the text to the file.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
result = writefile ./target/tests/writefile.txt "line 1\nline 2"
2019-12-30 10:45:28 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-30 22:56:17 +00:00
writefile, write_text_file
2019-12-30 10:45:28 +00:00
2021-09-21 13:26:52 +00:00
<a name="std__hash__Digest"></a>
2021-09-21 13:44:25 +00:00
## `std::hash::Digest`
2021-09-21 13:26:52 +00:00
```sh
var = digest --algo (sha256|sha512) (--file path|content)
```
Runs the requested hash on the provided file or string content and returns the hashed value in hex.
2021-09-21 13:47:41 +00:00
### Parameters
2021-09-21 13:26:52 +00:00
* --algo and algorithm to use (currently sha256 and sha512 are supported)
* Optional --file and file path
* Optional the string content to hash (if file is not provided)
2021-09-21 13:47:41 +00:00
### Return Value
2021-09-21 13:26:52 +00:00
The hash value in hex or false in case of error.
2021-09-21 13:47:41 +00:00
### Examples
2021-09-21 13:26:52 +00:00
```sh
hashed = digest --algo sha256 "hello world\n"
assert_eq ${hashed} A948904F2F0F479B8F8197694B30184B0D2ED1C1CD2A1EC0FB85D299A192A447
hashed = digest --algo sha512 --file ./myfile.txt
```
2021-09-21 13:45:27 +00:00
### Aliases:
2021-09-21 13:26:52 +00:00
digest
<a name="std__hash__Sha256Sum"></a>
2021-09-21 13:44:25 +00:00
## `std::hash::Sha256Sum`
2021-09-21 13:26:52 +00:00
```sh
var = sha256sum file
```
Runs SHA-256 hash on the provided file returns the hashed value in hex.
2021-09-21 13:47:41 +00:00
### Parameters
2021-09-21 13:26:52 +00:00
The file to hash
2021-09-21 13:47:41 +00:00
### Return Value
2021-09-21 13:26:52 +00:00
The hash value in hex or false in case of error.
The result will be in lowercase, same as with the core utils with the same name.
2021-09-21 13:47:41 +00:00
### Examples
2021-09-21 13:26:52 +00:00
```sh
hashed = sha256sum ./myfile.txt
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2021-09-21 13:26:52 +00:00
```sh
scope::sha256sum::output = digest --algo sha256 --file ${scope::sha256sum::argument::1}
scope::sha256sum::output = lowercase ${scope::sha256sum::output}
```
2021-09-21 13:31:05 +00:00
</details>
2021-09-21 13:26:52 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-09-21 13:26:52 +00:00
sha256sum, sha256sum
<a name="std__hash__Sha512Sum"></a>
2021-09-21 13:44:25 +00:00
## `std::hash::Sha512Sum`
2021-09-21 13:26:52 +00:00
```sh
var = sha512sum file
```
Runs SHA-512 hash on the provided file returns the hashed value in hex.
2021-09-21 13:47:41 +00:00
### Parameters
2021-09-21 13:26:52 +00:00
The file to hash
2021-09-21 13:47:41 +00:00
### Return Value
2021-09-21 13:26:52 +00:00
The hash value in hex or false in case of error.
The result will be in lowercase, same as with the core utils with the same name.
2021-09-21 13:47:41 +00:00
### Examples
2021-09-21 13:26:52 +00:00
```sh
hashed = sha512sum ./myfile.txt
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2021-09-21 13:26:52 +00:00
```sh
scope::sha512sum::output = digest --algo sha512 --file ${scope::sha512sum::argument::1}
scope::sha512sum::output = lowercase ${scope::sha512sum::output}
```
2021-09-21 13:31:05 +00:00
</details>
2021-09-21 13:26:52 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-09-21 13:26:52 +00:00
sha512sum, sha512sum
2020-07-31 09:07:20 +00:00
<a name="std__json"></a>
2021-09-21 13:44:25 +00:00
## `std::json`
2020-07-31 09:07:20 +00:00
The json module provides json parsing and encoding capabilities.<br>
Parsing and encoding JSONs can be do to/from simple variables or to collections (maps/arrays).<br>
By default, when parsing a JSON string, the structure will be represented by simple variables.<br>
2020-07-31 09:07:20 +00:00
The root object (or simple value) will be set in the json_parse output variable and any sub structure will be
defined as variables with prefix of the root variable name.<br>
Object nodes, will have the value of: **[OBJECT]**.<br>
Array nodes will have a length variable defined, for example: **arr.length**<br>
If the --collections flag is provided, parsing will return the JSON value or a handle to a collection which will hold the values (or sub collections).<br>
These collections are better way to handling unknown json structures but must be released with the **release --recursive** command.
2020-07-31 09:07:20 +00:00
Because duckscript variables have no type, the json_encode will define every boolean/numeric value as JSON string.<br>
Below is a simple example showing how to parse and encode values of all types when using the default behaviour of storing to variables.
2020-07-31 09:07:20 +00:00
```sh
fn test_simple_types
str = json_parse \"myvalue\"
assert_eq ${str} myvalue
jsonstring = json_encode str
assert_eq ${jsonstring} \"myvalue\"
number = json_parse 500
assert_eq ${number} 500
jsonstring = json_encode number
# numeric value is encoded as string
assert_eq ${jsonstring} \"500\"
bool = json_parse true
assert_eq ${bool} true
jsonstring = json_encode bool
# boolean value is encoded to string
assert_eq ${jsonstring} \"true\"
arr = json_parse "[1, 2, 3]"
# arr.length is not part of the JSON structure but added as a variable to enable
# to loop over the array using the range command
assert_eq ${arr.length} 3
# direct array location access example
assert_eq ${arr[0]} 1
assert_eq ${arr[1]} 2
assert_eq ${arr[2]} 3
# array loop example
arr_range = range 0 ${arr.length}
for index in ${arr_range}
expected_value = calc ${index} + 1
value = get_by_name arr[${index}]
assert_eq ${value} ${expected_value}
end
object = json_parse "{\"str\": \"my string value\", \"number\": 500, \"bool\": true, \"array\": [1, 2, 3]}"
assert_eq ${object} [OBJECT]
assert_eq ${object.str} "my string value"
assert_eq ${object.number} 500
assert_eq ${object.bool} true
assert_eq ${object.array.length} 3
assert_eq ${object.array[0]} 1
assert_eq ${object.array[1]} 2
assert_eq ${object.array[2]} 3
jsonstring = json_encode object
found = contains ${jsonstring} "\"str\":\"my string value\""
assert ${found}
found = contains ${jsonstring} "\"number\":\"500\""
assert ${found}
found = contains ${jsonstring} "\"bool\":\"true\""
assert ${found}
found = contains ${jsonstring} "\"array\":[\"1\",\"2\",\"3\"]"
assert ${found}
2020-07-31 09:35:55 +00:00
# we can cleanup all variables created from the json parse starting from the root object
unset_all_vars --prefix object
defined = is_defined object
assert_false ${defined}
defined = is_defined object.str
assert_false ${defined}
defined = is_defined object.array.length
assert_false ${defined}
2020-07-31 09:07:20 +00:00
end
```
2020-07-30 06:53:27 +00:00
<a name="std__json__Encode"></a>
2021-09-21 13:44:25 +00:00
## `std::json::Encode`
2020-07-30 06:53:27 +00:00
```sh
string = json_encode (--collection handle | var_name)
2020-07-30 06:53:27 +00:00
```
This function will encode all variables, starting from the root variable as a JSON string.<br>
Since duckscript is untyped, all boolean and numeric values will be encoded as strings.<br>
If --collection is passed, the provided value is considered as string or a map/array handle which is used to fetch
the tree data and create the json string.
2020-07-30 06:53:27 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-30 06:53:27 +00:00
* Option --collection flag to make the encoding use the maps/arrays and values
* The root variable name (or a handle/value in case --collection is provided)
2020-07-30 06:53:27 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-30 06:53:27 +00:00
The JSON string
2021-09-21 13:47:41 +00:00
### Examples
2020-07-30 06:53:27 +00:00
```sh
# will parse and encode to plain variables
2020-07-30 06:53:27 +00:00
package = json_parse "{\"name\": \"my package\", \"version\": 1, \"publish\": false, \"keywords\": [\"test1\", \"test2\"], \"directories\": {\"test\": \"spec\"}}"
jsonstring = json_encode package
# will parse and encode to maps/arrays
package = json_parse --collection "{\"name\": \"my package\", \"version\": 1, \"publish\": false, \"keywords\": [\"test1\", \"test2\"], \"directories\": {\"test\": \"spec\"}}"
jsonstring = json_encode --collection ${package}
2020-07-30 06:53:27 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-30 06:53:27 +00:00
json_encode
2020-07-28 16:53:57 +00:00
<a name="std__json__Parse"></a>
2021-09-21 13:44:25 +00:00
## `std::json::Parse`
2020-07-28 16:53:57 +00:00
```sh
var = json_parse [--collection] string
2020-07-28 16:53:57 +00:00
```
This function will parse the provided JSON string and will create variables based on the parsed data.<br>
The variables will reflect the json structure.<br>
Object keys will have name using the json path standard, for example root.child<br>
And arrays will have the array access annotation and length variable, for example:
```sh
root.child[5]
root.child.length
```
In case the --collection flag is provided, it will instead create maps/array as needed and return the root handle (or primitive value) of
the json data.
Make sure to use the release with the recursive flag on the root object to release the entire memory once done.
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-28 16:53:57 +00:00
* Optional --collection flag to parse and return value/map/array
* The JSON string to parse.
2020-07-28 16:53:57 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-28 16:53:57 +00:00
The root value/handle.
2020-07-28 16:53:57 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-07-28 16:53:57 +00:00
```sh
# parse to simple variables
2020-07-28 16:53:57 +00:00
package = json_parse "{\"name\": \"my package\", \"version\": 1, \"publish\": false, \"keywords\": [\"test1\", \"test2\"], \"directories\": {\"test\": \"spec\"}}"
2020-07-30 06:53:27 +00:00
assert_eq ${package} "[OBJECT]"
2020-07-28 16:53:57 +00:00
assert_eq ${package.name} "my package"
assert_eq ${package.version} 1
assert_eq ${package.publish} false
assert_eq ${package.keywords.length} 2
assert_eq ${package.keywords[0]} test1
assert_eq ${package.keywords[1]} test2
assert_eq ${package.directories.test} spec
# parse to maps/arrays
package = json_parse --collection "{\"name\": \"my package\", \"version\": 1, \"publish\": false, \"keywords\": [\"test1\", \"test2\"], \"directories\": {\"test\": \"spec\"}}"
name = map_get ${package} name
assert_eq ${name} "my package"
version = map_get ${package} version
assert_eq ${version} 1
public = map_get ${package} public
assert_false ${public}
keywords_handle = map_get ${package} keywords
length = array_length ${keywords_handle}
assert_eq ${length} 2
value = array_pop ${keywords_handle}
assert_eq ${value} test2
value = array_pop ${keywords_handle}
assert_eq ${value} test1
directories = map_get ${package} directories
directory = map_get ${directories} test
assert_eq ${directory} spec
release --recursive ${package}
2020-07-28 16:53:57 +00:00
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-28 16:53:57 +00:00
json_parse
2020-03-08 17:09:47 +00:00
<a name="std__lib__alias__Set"></a>
2021-09-21 13:44:25 +00:00
## `std::lib::alias::Set`
2020-03-08 17:09:47 +00:00
```sh
var = alias command arguments
```
This command enables to define new commands with default arguments.<br>
The new alias can be invoked with additional arguments that will be appended to the default set.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-08 17:09:47 +00:00
Any number of arguments which will be added to the already defined arguments set during the aliasing.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-08 17:09:47 +00:00
**true** if the alias was created, else **false**.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-08 17:09:47 +00:00
```sh
# This example creates a new **my_echo** alias that will print the prefix before the requested arguments.
created = alias my_echo echo [ECHO]
# This will print "[ECHO] hello world "
created = my_echo hello world
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-08 17:09:47 +00:00
alias
<a name="std__lib__alias__Unset"></a>
2021-09-21 13:44:25 +00:00
## `std::lib::alias::Unset`
2020-03-08 17:09:47 +00:00
```sh
unalias name
```
Removes previously defined alias and return true/false based if an alias was actually removed.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-08 17:09:47 +00:00
The alias name to remove.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-08 17:09:47 +00:00
A true/false value in case an alias with the provided name existed.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-08 17:09:47 +00:00
```sh
alias my_echo echo [ECHO]
# This will print "[ECHO] hello world "
my_echo hello world
unalias my_echo
# This will error
echo The script will now error as my_echo is no longer defined
my_echo hello world
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-08 17:09:47 +00:00
unalias
2020-03-08 17:51:49 +00:00
<a name="std__lib__command__Remove"></a>
2021-09-21 13:44:25 +00:00
## `std::lib::command::Remove`
2020-03-08 17:51:49 +00:00
```sh
remove_command name
```
Removes a command and all its aliases.
2021-09-21 13:47:41 +00:00
### Parameters
2020-03-08 17:51:49 +00:00
The command or alias name to remove.
2021-09-21 13:47:41 +00:00
### Return Value
2020-03-08 17:51:49 +00:00
A true/false value in case a command was removed.
2021-09-21 13:47:41 +00:00
### Examples
2020-03-08 17:51:49 +00:00
```sh
remove_command set
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-03-08 17:51:49 +00:00
remove_command
<a name="std__math__Calc"></a>
2021-09-21 13:44:25 +00:00
## `std::math::Calc`
2020-01-03 08:17:05 +00:00
```sh
var = calc [operation]
```
The calc command accepts multiple arguments which make up a mathematical operation which will be
calculated and its result will be returned.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-03 08:17:05 +00:00
Any number of arguments which will construct a line to calculate.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-03 08:17:05 +00:00
The result of the mathematical calculation.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-03 08:17:05 +00:00
```sh
# result is 36
result = calc 1 + 5 * 7
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-03 08:17:05 +00:00
calc
<a name="std__math__GreaterThan"></a>
2021-09-21 13:44:25 +00:00
## `std::math::GreaterThan`
```sh
var = greater_than left right
```
This command returns true/false based on left > right calculation.
2021-09-21 13:47:41 +00:00
### Parameters
Two numeric values to compare.
2021-09-21 13:47:41 +00:00
### Return Value
True if first argument is bigger than second argument.
2021-09-21 13:47:41 +00:00
### Examples
```sh
result = greater_than 2 1.5
```
2021-09-21 13:45:27 +00:00
### Aliases:
greater_than
2021-03-01 17:33:36 +00:00
<a name="std__math__HexDecode"></a>
2021-09-21 13:44:25 +00:00
## `std::math::HexDecode`
2021-03-01 17:33:36 +00:00
```sh
num = hex_decode str
```
Decode a hexadecimal string to the corresponding integer number.<br>
No support for negative numbers.
2021-09-21 13:47:41 +00:00
### Parameters
2021-03-01 17:33:36 +00:00
A hexadecimal string.
2021-09-21 13:47:41 +00:00
### Return Value
2021-03-01 17:33:36 +00:00
The corresponding integer number.
2021-09-21 13:47:41 +00:00
### Examples
2021-03-01 17:33:36 +00:00
```sh
hex_num = set 0xff
num = hex_decode ${hex_num}
res = calc ${num} + 1
assert_eq ${res} 256
```
2021-09-21 13:45:27 +00:00
### Aliases:
2021-03-01 17:33:36 +00:00
hex_decode
<a name="std__math__HexEncode"></a>
2021-09-21 13:44:25 +00:00
## `std::math::HexEncode`
2021-03-01 17:33:36 +00:00
```sh
str = hex_encode num
```
Converts an integer number to the corresponding hexadecimal string.<br>
No support for negative numbers.
2021-09-21 13:47:41 +00:00
### Parameters
2021-03-01 17:33:36 +00:00
An integer number.
2021-09-21 13:47:41 +00:00
### Return Value
2021-03-01 17:33:36 +00:00
The corresponding hexadecimal string.
2021-09-21 13:47:41 +00:00
### Examples
2021-03-01 17:33:36 +00:00
```sh
str = hex_encode 255
assert_eq ${str} 0xff
```
2021-09-21 13:45:27 +00:00
### Aliases:
2021-03-01 17:33:36 +00:00
hex_encode
<a name="std__math__LessThan"></a>
2021-09-21 13:44:25 +00:00
## `std::math::LessThan`
```sh
var = less_than left right
```
This command returns true/false based on left < right calculation.
2021-09-21 13:47:41 +00:00
### Parameters
Two numeric values to compare.
2021-09-21 13:47:41 +00:00
### Return Value
True if first argument is smaller than second argument.
2021-09-21 13:47:41 +00:00
### Examples
```sh
result = less_than 1 1.5
```
2021-09-21 13:45:27 +00:00
### Aliases:
less_than
<a name="std__net__Hostname"></a>
2021-09-21 13:44:25 +00:00
## `std::net::Hostname`
2020-01-05 17:25:53 +00:00
```sh
var = hostname
```
2020-01-25 17:29:26 +00:00
Returns the hostname.
2020-01-05 17:25:53 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-05 17:25:53 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-05 17:25:53 +00:00
2020-01-25 17:29:26 +00:00
The hostname
2020-01-05 17:25:53 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-05 17:25:53 +00:00
```sh
name = hostname
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-05 17:25:53 +00:00
hostname
2020-01-18 16:41:03 +00:00
<a name="std__net__HttpClient"></a>
2021-09-21 13:44:25 +00:00
## `std::net::HttpClient`
2020-01-18 16:41:03 +00:00
```sh
2020-01-23 19:37:16 +00:00
var = http_client [--method method] [--payload payload] [--output-file file] URL
```
Invokes a HTTP request.<br>
The request method by default is GET but can be modified by the ```--method``` parameter.<br>
The ```--output-file``` parameter will redirect a valid response output to the provided file, otherwise all response text will be set to the
output variable.<br>
When redirecting to file, the output would be the response size.<br>
The ```--payload``` parameter enables to pass a payload to POST http requests.<br>
In case of errors or error HTTP response codes, false will be returned.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-23 19:37:16 +00:00
* Optional HTTP Method, for example ```--method GET``` or ```--method POST``` (currently only GET and POST are supported).
* Optional post payload via ```--payload``` parameter.
* Optional redirection of output to file via ```--output-file``` parameter.
* The target URL
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-23 19:37:16 +00:00
The response text or in case of output redirection to file, the response size.<br>
In case of errors, it will return false.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-23 19:37:16 +00:00
```sh
function test_get
response = http_client https://www.rust-lang.org/
found = contains ${response} Rust
assert ${found}
end
function test_get_to_file
file = set ./target/_duckscript_test/http_client/page.html
rm ${file}
response_size = http_client --output-file ${file} https://www.rust-lang.org/
response = readfile ${file}
found = contains ${response} Rust
assert ${found}
assert ${response_size}
end
function test_post
payload = set {\"login\":\"login\",\"password\":\"password\"}
response = http_client --method POST --payload ${payload} https://reqbin.com/echo/post/json
found = contains ${response} success
assert ${found}
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-23 19:37:16 +00:00
http_client
<a name="std__net__WGet"></a>
2021-09-21 13:44:25 +00:00
## `std::net::WGet`
2020-01-23 19:37:16 +00:00
```sh
var = wget [--method=HTTP-method] [--post-data=payload] [-O file] URL
2020-01-18 16:41:03 +00:00
```
Invokes a HTTP request.<br>
The request method by default is GET but can be modified by the ```--method``` parameter.<br>
The ```-O``` parameter will redirect a valid response output to the provided file, otherwise all response text will be set to the
output variable.<br>
When redirecting to file, the output would be the response size.<br>
The ```--post-data``` parameter enables to pass a payload to POST http requests.<br>
In case of errors or error HTTP response codes, false will be returned.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-18 16:41:03 +00:00
* Optional HTTP Method, for example --method=HTTP-GET or --method=HTTP-POST (currently only GET and POST are supported).
* Optional post payload via ```--post-data``` parameter.
* Optional redirection of output to file via ```-O``` parameter.
* The target URL
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-18 16:41:03 +00:00
The response text or in case of output redirection to file, the response size.<br>
In case of errors, it will return false.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-18 16:41:03 +00:00
```sh
function test_get
2020-01-23 19:37:16 +00:00
response = wget https://www.rust-lang.org/
2020-01-18 16:41:03 +00:00
found = contains ${response} Rust
assert ${found}
end
function test_get_to_file
2020-01-23 19:37:16 +00:00
file = set ./target/_duckscript_test/wget/page.html
2020-01-18 16:41:03 +00:00
rm ${file}
2020-01-23 19:37:16 +00:00
response_size = wget -O ${file} https://www.rust-lang.org/
2020-01-18 16:41:03 +00:00
response = readfile ${file}
found = contains ${response} Rust
assert ${found}
assert ${response_size}
end
function test_post
payload = set {\"login\":\"login\",\"password\":\"password\"}
2020-01-23 19:37:16 +00:00
response = wget --method=HTTP-POST --post-data=${payload} https://reqbin.com/echo/post/json
2020-01-18 16:41:03 +00:00
found = contains ${response} success
assert ${found}
end
```
2020-01-23 19:37:16 +00:00
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-01-23 19:37:16 +00:00
```sh
2020-01-31 14:05:30 +00:00
2020-01-23 19:37:16 +00:00
scope::wget::url = array_pop ${scope::wget::arguments}
scope::wget::method = set GET
scope::wget::lookingfor = set flag
for scope::wget::arg in ${scope::wget::arguments}
if equals ${scope::wget::lookingfor} flag
if starts_with ${scope::wget::arg} --method=HTTP-
scope::wget::len = strlen --method=HTTP-
scope::wget::method = substring ${scope::wget::arg} ${scope::wget::len}
elif starts_with ${scope::wget::arg} --post-data=
scope::wget::len = strlen --post-data=
scope::wget::payload = substring ${scope::wget::arg} ${scope::wget::len}
2020-01-24 15:37:12 +00:00
elif equals ${scope::wget::arg} -O
2020-01-23 19:37:16 +00:00
scope::wget::lookingfor = set file
end
elif equals ${scope::wget::lookingfor} file
scope::wget::file = set ${scope::wget::arg}
scope::wget::lookingfor = set flag
end
end
http_client --method "${scope::wget::method}" --output-file "${scope::wget::file}" --payload "${scope::wget::payload}" ${scope::wget::url}
2020-01-31 14:05:30 +00:00
2020-01-23 19:37:16 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-01-23 19:37:16 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-23 19:37:16 +00:00
wget
2020-01-18 16:41:03 +00:00
<a name="std__net__ftp__Get"></a>
2021-09-21 13:44:25 +00:00
## `std::net::ftp::Get`
```sh
result = ftp_get --host <hostname> [--port 21] [--username <user name>] [--password <password>] [--path <path>] [--type <A/I>] --remote-file <file name> --local-file <file name>
```
Invokes the FTP GET command from the given connection and file details.
2021-09-21 13:47:41 +00:00
### Parameters
* --host - The host name or IP to connect to
* --port - Optional port number to use (by default 21)
* --username - Optional user name used to login (if not user or password provided, no login operation will be invoked)
* --password - Optional password used to login (if not user or password provided, no login operation will be invoked)
* --path - Optional path on the remote server to invoke operation on
* --type - Optional setting of the transfer type as A (ascii) I (image, binary)
* --remote-file - The remote file to download
* --local-file - The target local file name
2021-09-21 13:47:41 +00:00
### Return Value
true if operation was completed.
2021-09-21 13:47:41 +00:00
### Examples
```sh
ftp_get --host myhost --username someuser --password 12345 --remote-file README.md --local-file README.md
```
2021-09-21 13:45:27 +00:00
### Aliases:
ftp_get
<a name="std__net__ftp__GetInMemory"></a>
2021-09-21 13:44:25 +00:00
## `std::net::ftp::GetInMemory`
```sh
handle = ftp_get_in_memory --host <hostname> [--port 21] [--username <user name>] [--password <password>] [--path <path>] [--type <A/I>] --remote-file <file name>
```
Invokes the FTP GET command from the given connection and file details.
2021-09-21 13:47:41 +00:00
### Parameters
* --host - The host name or IP to connect to
* --port - Optional port number to use (by default 21)
* --username - Optional user name used to login (if not user or password provided, no login operation will be invoked)
* --password - Optional password used to login (if not user or password provided, no login operation will be invoked)
* --path - Optional path on the remote server to invoke operation on
* --type - Optional setting of the transfer type as A (ascii) I (image, binary)
* --remote-file - The remote file to download
2021-09-21 13:47:41 +00:00
### Return Value
The binary data handle.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = ftp_get_in_memory --host myhost --username someuser --password 12345 --remote-file README.md
text = bytes_to_string ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
ftp_get_in_memory
2020-06-26 18:03:54 +00:00
<a name="std__net__ftp__List"></a>
2021-09-21 13:44:25 +00:00
## `std::net::ftp::List`
2020-06-26 18:03:54 +00:00
```sh
handle = ftp_list --host <hostname> [--port 21] [--username <user name>] [--password <password>] [--path <path>]
```
Invokes the FTP LIST command from the given connection details and path.<br>
Returns a handle to an array of all response entries.
2021-09-21 13:47:41 +00:00
### Parameters
2020-06-26 18:03:54 +00:00
* --host - The host name or IP to connect to
* --port - Optional port number to use (by default 21)
* --username - Optional user name used to login (if not user or password provided, no login operation will be invoked)
* --password - Optional password used to login (if not user or password provided, no login operation will be invoked)
* --path - Optional path on the remote server to invoke operation on
2021-09-21 13:47:41 +00:00
### Return Value
2020-06-26 18:03:54 +00:00
A handle to an array holding all entries.
2021-09-21 13:47:41 +00:00
### Examples
2020-06-26 18:03:54 +00:00
```sh
handle = ftp_list --host myhost --username someuser --password 12345
for entry in ${handle}
echo ${entry}
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-06-26 18:03:54 +00:00
ftp_list
<a name="std__net__ftp__NLst"></a>
2021-09-21 13:44:25 +00:00
## `std::net::ftp::NLst`
2020-06-26 18:03:54 +00:00
```sh
handle = ftp_nlst --host <hostname> [--port 21] [--username <user name>] [--password <password>] [--path <path>]
```
Invokes the FTP NLST command from the given connection details and path.<br>
Returns a handle to an array of all response entries.
2021-09-21 13:47:41 +00:00
### Parameters
2020-06-26 18:03:54 +00:00
* --host - The host name or IP to connect to
* --port - Optional port number to use (by default 21)
* --username - Optional user name used to login (if not user or password provided, no login operation will be invoked)
* --password - Optional password used to login (if not user or password provided, no login operation will be invoked)
* --path - Optional path on the remote server to invoke operation on
2021-09-21 13:47:41 +00:00
### Return Value
2020-06-26 18:03:54 +00:00
A handle to an array holding all entries.
2021-09-21 13:47:41 +00:00
### Examples
2020-06-26 18:03:54 +00:00
```sh
handle = ftp_nlst --host myhost --username someuser --password 12345
for entry in ${handle}
echo ${entry}
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-06-26 18:03:54 +00:00
ftp_nlst
<a name="std__net__ftp__Put"></a>
2021-09-21 13:44:25 +00:00
## `std::net::ftp::Put`
```sh
result = ftp_put --host <hostname> [--port 21] [--username <user name>] [--password <password>] [--path <path>] [--type <A/I>] --remote-file <file name> --local-file <file name>
```
Invokes the FTP PUT command from the given connection and file details.
2021-09-21 13:47:41 +00:00
### Parameters
* --host - The host name or IP to connect to
* --port - Optional port number to use (by default 21)
* --username - Optional user name used to login (if not user or password provided, no login operation will be invoked)
* --password - Optional password used to login (if not user or password provided, no login operation will be invoked)
* --path - Optional path on the remote server to invoke operation on
* --type - Optional setting of the transfer type as A (ascii) I (image, binary)
* --remote-file - The remote file to upload
* --local-file - The source local file to upload
2021-09-21 13:47:41 +00:00
### Return Value
true if operation was completed.
2021-09-21 13:47:41 +00:00
### Examples
```sh
ftp_put --host myhost --username someuser --password 12345 --remote-file README.md --local-file README.md
```
2021-09-21 13:45:27 +00:00
### Aliases:
ftp_put
<a name="std__net__ftp__PutInMemory"></a>
2021-09-21 13:44:25 +00:00
## `std::net::ftp::PutInMemory`
```sh
result = ftp_put_in_memory --host <hostname> [--port 21] [--username <user name>] [--password <password>] [--path <path>] [--type <A/I>] --remote-file <file name> --content <content>
```
Invokes the FTP PUT command from the given connection and file details.
2021-09-21 13:47:41 +00:00
### Parameters
* --host - The host name or IP to connect to
* --port - Optional port number to use (by default 21)
* --username - Optional user name used to login (if not user or password provided, no login operation will be invoked)
* --password - Optional password used to login (if not user or password provided, no login operation will be invoked)
* --path - Optional path on the remote server to invoke operation on
* --type - Optional setting of the transfer type as A (ascii) I (image, binary)
* --remote-file - The remote file to upload
* --content - The textual content to upload
2021-09-21 13:47:41 +00:00
### Return Value
true if operation was completed.
2021-09-21 13:47:41 +00:00
### Examples
```sh
ftp_put_in_memory --host myhost --username someuser --password 12345 --remote-file README.md --content "This is the README content"
```
2021-09-21 13:45:27 +00:00
### Aliases:
ftp_put_in_memory
<a name="std__process__Execute"></a>
2021-09-21 13:44:25 +00:00
## `std::process::Execute`
2019-12-30 10:45:28 +00:00
```sh
exec [--fail-on-error|--get-exit-code] [--input value] command [args]*
2019-12-30 10:45:28 +00:00
output = exec command [args]*
stdout = set ${output.stdout}
stderr = set ${output.stderr}
exit_code = set ${output.code}
exit_code = exec --get-exit-code command [args]*
2019-12-30 10:45:28 +00:00
```
Executes the provided native command and arguments.<br>
If no output variable is set, the command output will be flushed to the main out/err stream of the parent process.<br>
In addition, in order to fail the command in case of the child process failed, add the --fail-on-error flag.<br>
2019-12-30 10:45:28 +00:00
If an output variable is set, it will be used as a base variable name from which the command stout, stderr and exit code information can be pulled from.<br>
The actual output variable name will not be modified, instead new variables will be created using that variable name as a baseline:
* *output*.stdout - Will hold the stdout text content.
* *output*.stderr - Will hold the stderr text content.
* *output*.code - Will hold the process exit code.
If an output variable is set and the --get-exit-code flag is provided, the output will only contain the exit code.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
2020-10-06 18:42:45 +00:00
* --fail-on-error - If no output variable is provided, it will cause an error in case the executed process exits with an error exit code.
* --get-exit-code - If an output variable is provided, it will contain the exit code.
* --input - Optional content to be sent to the child process input stream.
* The command to execute and its arguments.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
Optionally a base name to access the process stout, stderr and exit code information.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:32:48 +00:00
# Example of running a command and flushing its output to the parent process.
2019-12-30 10:45:28 +00:00
exec echo hello world
2020-01-02 22:32:48 +00:00
# Example of running a command and storing its output.
2019-12-30 10:45:28 +00:00
output = exec echo hello world
stdout = set ${output.stdout}
stderr = set ${output.stderr}
exit_code = set ${output.code}
echo stdout: ${stdout}
echo stderr: ${stderr}
echo exit code: ${exit_code}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
exec
<a name="std__process__Exit"></a>
2021-09-21 13:44:25 +00:00
## `std::process::Exit`
2019-12-30 10:45:28 +00:00
```sh
code = exit [code]
```
Exits the script with the given code stored in the output variable.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
A number as exit code or none for 0.
2019-12-30 10:45:28 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The exit code.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:32:48 +00:00
# exit with code '0'
2019-12-30 10:45:28 +00:00
code = exit
2020-01-02 22:32:48 +00:00
# exit with code '1'
2019-12-30 10:45:28 +00:00
code = exit 1
```
2021-09-21 13:45:27 +00:00
### Aliases:
exit, quit, q
2019-12-30 10:45:28 +00:00
2020-01-26 14:43:55 +00:00
<a name="std__process__ProcessID"></a>
2021-09-21 13:44:25 +00:00
## `std::process::ProcessID`
2020-01-26 14:43:55 +00:00
```sh
var = pid
```
Returns the current process ID.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-26 14:43:55 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-26 14:43:55 +00:00
The current process ID.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-26 14:43:55 +00:00
```sh
id = pid
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-26 14:43:55 +00:00
pid, process_id
2020-02-19 17:51:11 +00:00
<a name="std__process__Spawn"></a>
2021-09-21 13:44:25 +00:00
## `std::process::Spawn`
2020-02-19 17:51:11 +00:00
```sh
pid = spawn [--silent] [--input value] command [args]*
2020-02-19 17:51:11 +00:00
```
Executes the provided native command and arguments.<br>
It will not wait for the process to finish and will return the process pid.
2021-09-21 13:47:41 +00:00
### Parameters
2020-02-19 17:51:11 +00:00
* Optional --silent flag to suppress any output.
* --input - Optional content to be sent to the child process input stream.
* The command to execute and its arguments.
2020-02-19 17:51:11 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-02-19 17:51:11 +00:00
The process pid.
2021-09-21 13:47:41 +00:00
### Examples
2020-02-19 17:51:11 +00:00
```sh
pid = spawn echo test
echo PID: ${pid}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-02-19 17:51:11 +00:00
spawn
2020-01-26 18:32:59 +00:00
<a name="std__process__Watchdog"></a>
2021-09-21 13:44:25 +00:00
## `std::process::Watchdog`
2020-01-26 18:32:59 +00:00
```sh
count = watchdog [--max-retries value] [--interval value] [--input value] -- command [arguments]*
2020-01-26 18:32:59 +00:00
```
Executes the provided native command and arguments.<br>
2020-10-06 18:42:45 +00:00
In case the command exited it will be executed again up to the max retries provided.<br>
The watchdog will wait the specified interval in milliseconds between invocations.<br>
2020-01-26 18:32:59 +00:00
In case of an invalid command, the watchdog will not reattempt the invocation and will exit without retries.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-26 18:32:59 +00:00
* --max-retries - Value of max retries (excluding the first invocation). value < 0 for unlimited retries. Default is unlimited.
2020-01-26 18:32:59 +00:00
* --interval - The amount in milliseconds between retries. 0 for no waiting between invocations. Default is no wait.
* --input - Optional content to be sent to the child process input stream.
2020-10-06 18:42:45 +00:00
* The command to execute (preceded by a **--** separator).
2020-01-26 18:32:59 +00:00
* The command arguments.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-26 18:32:59 +00:00
The amount of invocations or false in case of any error.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-26 18:32:59 +00:00
```sh
count = watchdog --max-retries 0 -- echo test
assert_eq ${count} 1
count = watchdog --max-retries 3 --interval 10 -- echo test
assert_eq ${count} 4
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-26 18:32:59 +00:00
watchdog
<a name="std__random__Range"></a>
2021-09-21 13:44:25 +00:00
## `std::random::Range`
```sh
output = random_range min max
```
Generate a random value in the range of min and max values provided, i.e. inclusive of min and exclusive of max.
2021-09-21 13:47:41 +00:00
### Parameters
* min - The min range value (inclusive)
* max - The max range value (exclusive)
2021-09-21 13:47:41 +00:00
### Return Value
The generated numeric value.
2021-09-21 13:47:41 +00:00
### Examples
```sh
value = random_range -10 10
echo ${value}
```
2021-09-21 13:45:27 +00:00
### Aliases:
random_range, rand_range
<a name="std__random__Text"></a>
2021-09-21 13:44:25 +00:00
## `std::random::Text`
```sh
output = random_text [length]
```
Generates random alphanumeric text with the requested length (length is 1 if not provided).
2021-09-21 13:47:41 +00:00
### Parameters
Optional text length. Length is defaulted to 1 if not provided.
2021-09-21 13:47:41 +00:00
### Return Value
The generated alphanumeric value.
2021-09-21 13:47:41 +00:00
### Examples
```sh
value = random_text 50
echo ${value}
```
2021-09-21 13:45:27 +00:00
### Aliases:
random_text, rand_text
2020-01-22 21:02:22 +00:00
<a name="std__scope__Clear"></a>
2021-09-21 13:44:25 +00:00
## `std::scope::Clear`
2020-01-22 21:02:22 +00:00
```sh
clear_scope name
```
Clears all variables which are prefixed with the provided name + ::.<br>
For example, if the value provided is **my_scope** all variables that start with **my_scope::** will be removed.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-22 21:02:22 +00:00
The scope name.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-22 21:02:22 +00:00
None.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-22 21:02:22 +00:00
```sh
testscope = set true
testscope::1 = set 1
testscope::subscope::1 = set 1
assert_eq ${testscope} true
defined = is_defined testscope::1
assert ${defined}
assert_eq ${testscope::1} 1
defined = is_defined testscope::subscope::1
assert ${defined}
assert_eq ${testscope::subscope::1} 1
clear_scope testscope
assert_eq ${testscope} true
defined = is_defined testscope::1
assert_false ${defined}
defined = is_defined testscope::subscope::1
assert_false ${defined}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-22 21:02:22 +00:00
clear_scope
<a name="std__scope__PopStack"></a>
2021-09-21 13:44:25 +00:00
## `std::scope::PopStack`
```sh
scope_pop_stack [--copy name1 name2 ...]
```
Removes all known variables except for the variables provided by the optional --copy argument and than restores the
previously pushed stack.<br>
Functions with the **<scope>** annotation will automatically invoke this command when they end or return a value.
2021-09-21 13:47:41 +00:00
### Parameters
Optional variable names to keep.
2021-09-21 13:47:41 +00:00
### Return Value
None.
2021-09-21 13:47:41 +00:00
### Examples
```sh
var1 = set 1
var2 = set 2
scope_push_stack --copy var2
defined = is_defined var1
echo ${defined}
defined = is_defined var2
echo ${defined}
var3 = set 3
var4 = set 4
scope_pop_stack --copy var4
defined = is_defined var1
echo ${defined}
defined = is_defined var2
echo ${defined}
defined = is_defined var3
echo ${defined}
defined = is_defined var4
echo ${defined}
```
2021-09-21 13:45:27 +00:00
### Aliases:
scope_pop_stack
<a name="std__scope__PushStack"></a>
2021-09-21 13:44:25 +00:00
## `std::scope::PushStack`
```sh
scope_push_stack [--copy name1 name2 ...]
```
Removes all known variables except for the variables provided by the optional --copy argument.<br>
Functions with the **<scope>** annotation will automatically invoke this command and keep only the relevant
function arguments in the new scope.
2021-09-21 13:47:41 +00:00
### Parameters
Optional variable names to keep.
2021-09-21 13:47:41 +00:00
### Return Value
None.
2021-09-21 13:47:41 +00:00
### Examples
```sh
var1 = set 1
var2 = set 2
scope_push_stack --copy var2
defined = is_defined var1
echo ${defined}
defined = is_defined var2
echo ${defined}
```
2021-09-21 13:45:27 +00:00
### Aliases:
scope_push_stack
<a name="std__semver__IsEqual"></a>
2021-09-21 13:44:25 +00:00
## `std::semver::IsEqual`
```sh
output = semver_is_equal value1 value2
```
Returns true if both semver values are valid and equal.
2021-09-21 13:47:41 +00:00
### Parameters
Two semver values to compare.
2021-09-21 13:47:41 +00:00
### Return Value
True if both semver values are valid and equal, else false.
2021-09-21 13:47:41 +00:00
### Examples
```sh
equal = semver_is_equal 1.2.3 1.2.3
assert ${equal}
equal = semver_is_equal 1.2.3 2.2.3
assert_false ${equal}
```
2021-09-21 13:45:27 +00:00
### Aliases:
semver_is_equal
<a name="std__semver__IsNewer"></a>
2021-09-21 13:44:25 +00:00
## `std::semver::IsNewer`
```sh
output = semver_is_newer newer older
```
Returns true if both semver values are valid and first value is newer.
2021-09-21 13:47:41 +00:00
### Parameters
* The expected newer value
* The expected older value
2021-09-21 13:47:41 +00:00
### Return Value
True if both semver values are valid and first value is newer, else false.
2021-09-21 13:47:41 +00:00
### Examples
```sh
newer = semver_is_newer 3.2.3 2.2.3
assert ${newer}
newer = semver_is_newer 1.2.3 2.2.3
assert_false ${newer}
newer = semver_is_newer 1.2.3 1.2.3
assert_false ${newer}
```
2021-09-21 13:45:27 +00:00
### Aliases:
semver_is_newer
<a name="std__semver__Parse"></a>
2021-09-21 13:44:25 +00:00
## `std::semver::Parse`
```sh
base = semver_parse value
```
Parses the provided value and sets the major, minor and patch variables.<br>
The variable names are based on the output variable name, for example if the output variable name is out:
* out.major - Holds the output major version
* out.minor - Holds the output minor version
* out.patch - Holds the output patch version
2021-09-21 13:47:41 +00:00
### Parameters
The semver value.
2021-09-21 13:47:41 +00:00
### Return Value
The major, minor and patch values.
2021-09-21 13:47:41 +00:00
### Examples
```sh
version = semver_parse 1.2.3
echo ${version.major}
echo ${version.minor}
echo ${version.patch}
```
2021-09-21 13:45:27 +00:00
### Aliases:
semver_parse
2020-01-31 14:05:30 +00:00
<a name="std__string__Base64"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Base64`
2020-01-31 14:05:30 +00:00
```sh
2020-01-31 14:11:00 +00:00
var = base64 [-e] [-encode] [-d] [-decode] value
2020-01-31 14:05:30 +00:00
```
2020-01-31 14:11:00 +00:00
Invokes the base64 encode/decode command with the provided value.<br>
This command allows for a more similar cli command which wraps the base64_encode and base64_decode commands.
2020-01-31 14:05:30 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-31 14:05:30 +00:00
2020-01-31 14:11:00 +00:00
* Optional -e or -encode flags to set the mode to encode (default)
* Optional -d or -decode flags to set the mode to decode
* The value, in case of encoding this is the binary handle, in case of decoding this is the base64 textual value.
2020-01-31 14:05:30 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-31 14:05:30 +00:00
2020-01-31 14:11:00 +00:00
* In case of encoding, the base64 textual value will be returned.
* In case of decoding, a handle to the binary data will be returned.
2020-01-31 14:05:30 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-31 14:05:30 +00:00
```sh
2020-01-31 14:12:20 +00:00
handle = string_to_bytes "hello world"
text = base64 ${handle}
release ${handle}
assert_eq ${text} aGVsbG8gd29ybGQ=
2020-01-31 14:05:30 +00:00
2020-01-31 14:12:20 +00:00
handle = base64 -decode ${text}
text = bytes_to_string ${handle}
release ${handle}
assert_eq ${text} "hello world"
2020-01-31 14:05:30 +00:00
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-01-31 14:05:30 +00:00
```sh
scope::base64::input_data = array_pop ${scope::base64::arguments}
scope::base64::encode = set true
for scope::base64::arg in ${scope::base64::arguments}
if equals ${scope::base64::arg} -e
scope::base64::encode = set true
elif equals ${scope::base64::arg} -encode
scope::base64::encode = set true
elif equals ${scope::base64::arg} -d
scope::base64::encode = set false
elif equals ${scope::base64::arg} -decode
scope::base64::encode = set false
end
end
if ${scope::base64::encode}
scope::base64::output = base64_encode ${scope::base64::input_data}
else
scope::base64::output = base64_decode ${scope::base64::input_data}
end
scope::base64::output = set ${scope::base64::output}
```
2021-09-21 13:31:05 +00:00
</details>
2020-01-31 14:05:30 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-31 14:05:30 +00:00
base64
<a name="std__string__Base64Decode"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Base64Decode`
```sh
text = base64_encode handle
```
Encodes using base64 the provided binary data and returns the encoded text value.<br>
The binary data is provided as a handle.
2021-09-21 13:47:41 +00:00
### Parameters
The handle to the binary data to encode.
2021-09-21 13:47:41 +00:00
### Return Value
The encoded textual value.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = string_to_bytes "hello world"
text = base64_encode ${handle}
release ${handle}
assert_eq ${text} "hello world"
```
2021-09-21 13:45:27 +00:00
### Aliases:
base64_decode
<a name="std__string__Base64Encode"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Base64Encode`
```sh
text = base64_encode handle
```
Encodes using base64 the provided binary data and returns the encoded text value.<br>
The binary data is provided as a handle.
2021-09-21 13:47:41 +00:00
### Parameters
The handle to the binary data to encode.
2021-09-21 13:47:41 +00:00
### Return Value
The encoded textual value.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = string_to_bytes "hello world"
text = base64_encode ${handle}
release ${handle}
assert_eq ${text} "hello world"
```
2021-09-21 13:45:27 +00:00
### Aliases:
base64_encode
<a name="std__string__BytesToString"></a>
2021-09-21 13:44:25 +00:00
## `std::string::BytesToString`
```sh
text = bytes_to_string handle
```
Converts the provided UTF-8 binary array to string and returns it.
2021-09-21 13:47:41 +00:00
### Parameters
A handle to a binary array holding UTF-8 text.
2021-09-21 13:47:41 +00:00
### Return Value
The textual data.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = string_to_bytes "hello world"
text = bytes_to_string ${handle}
release ${handle}
assert_eq ${text} "hello world"
```
2021-09-21 13:45:27 +00:00
### Aliases:
bytes_to_string
2021-07-14 03:44:47 +00:00
<a name="std__string__CamelCase"></a>
2021-09-21 13:44:25 +00:00
## `std::string::CamelCase`
2021-07-14 03:44:47 +00:00
```sh
var = camelcase text
2021-07-14 03:44:47 +00:00
```
Converts the provided string into camel case.
All non-alphanumeric characters are ignored.
2021-09-21 13:47:41 +00:00
### Parameters
2021-07-14 03:44:47 +00:00
The string to convert.
2021-09-21 13:47:41 +00:00
### Return Value
2021-07-14 03:44:47 +00:00
The converted string.
2021-09-21 13:47:41 +00:00
### Examples
2021-07-14 03:44:47 +00:00
```sh
string = camelcase "hello, world!"
2021-07-14 03:44:47 +00:00
assert_eq ${string} "HelloWorld"
```
2021-07-23 12:48:57 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
camelcase
2021-07-14 03:44:47 +00:00
2020-01-24 15:45:36 +00:00
<a name="std__string__Concat"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Concat`
2020-01-24 15:45:36 +00:00
```sh
2020-01-24 15:50:58 +00:00
var = concat [value]*
2020-01-24 15:45:36 +00:00
```
2020-01-24 15:50:58 +00:00
Concats the provided input into a single string and returns it.
2020-01-24 15:45:36 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-24 15:45:36 +00:00
2020-01-24 15:50:58 +00:00
Any number of values to concat.
2020-01-24 15:45:36 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-24 15:45:36 +00:00
2020-01-24 15:50:58 +00:00
The result of the concatenation of all input values.
2020-01-24 15:45:36 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-24 15:45:36 +00:00
```sh
2020-01-24 15:50:58 +00:00
output = concat 1 2 3 4
assert_eq ${output} 1234
2020-01-24 15:45:36 +00:00
2020-01-24 15:50:58 +00:00
output = concat 1 "2 3" 4
assert_eq ${output} "12 34"
2020-01-24 15:45:36 +00:00
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-01-24 15:45:36 +00:00
```sh
2020-01-31 14:05:30 +00:00
2020-01-24 15:45:36 +00:00
scope::concat::output = set ""
for scope::concat::arg in ${scope::concat::arguments}
scope::concat::output = set "${scope::concat::output}${scope::concat::arg}"
end
set ${scope::concat::output}
2020-01-31 14:05:30 +00:00
2020-01-24 15:45:36 +00:00
```
2021-09-21 13:31:05 +00:00
</details>
2020-01-24 15:45:36 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-24 15:45:36 +00:00
concat
<a name="std__string__Contains"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Contains`
```sh
var = contains all partial
```
Returns true if the first argument contains the value of the second argument.
2021-09-21 13:47:41 +00:00
### Parameters
* The full text to search in
* The text to search for
2021-09-21 13:47:41 +00:00
### Return Value
**true** if contains.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# valid conditions
result = contains abcd bc
value = set "some text"
result = contains ${value} "me tex"
# will return false
result = contains abcd b1c
```
2021-09-21 13:45:27 +00:00
### Aliases:
contains
<a name="std__string__EndsWith"></a>
2021-09-21 13:44:25 +00:00
## `std::string::EndsWith`
```sh
var = ends_with all partial
```
Returns true if the first argument ends with the value of the second argument.
2021-09-21 13:47:41 +00:00
### Parameters
* The full text to search in
* The suffix text to search for
2021-09-21 13:47:41 +00:00
### Return Value
**true** if ends with.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# valid conditions
result = ends_with abcd abc
value = set "some text"
result = ends_with ${value} "me text"
# will return false
result = ends_with abcd abc
```
2021-09-21 13:45:27 +00:00
### Aliases:
ends_with
<a name="std__string__Equals"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Equals`
```sh
var = eq value1 value2
```
Returns true if both provided values are equal.
2021-09-21 13:47:41 +00:00
### Parameters
Two values to evaluate if they are equal
2021-09-21 13:47:41 +00:00
### Return Value
**true** if equal.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# valid conditions
is_same = eq yes yes
is_same = eq false false
value = set "some text"
is_same = eq ${value} "some text"
# will return false
is_same = eq 1 2
```
2021-09-21 13:45:27 +00:00
### Aliases:
equals, eq
<a name="std__string__IndexOf"></a>
2021-09-21 13:44:25 +00:00
## `std::string::IndexOf`
```sh
var = indexof full_text text_to_find
```
This command will attempt to find the text from the second argument inside the text in the first argument.<br>
If found, an index value will be returned, otherwise none is returned.
2021-09-21 13:47:41 +00:00
### Parameters
* The text to search in
* The text to find
2021-09-21 13:47:41 +00:00
### Return Value
The index of the text found or none if not found.
2021-09-21 13:47:41 +00:00
### Examples
```sh
index = indexof " some text " some
```
2021-09-21 13:45:27 +00:00
### Aliases:
indexof
<a name="std__string__IsEmpty"></a>
2021-09-21 13:44:25 +00:00
## `std::string::IsEmpty`
```sh
var = is_empty value
```
Returns true if the provided value is none or an empty string.
2021-09-21 13:47:41 +00:00
### Parameters
The value to validate.
2021-09-21 13:47:41 +00:00
### Return Value
True if the provided value is none or an empty string.
2021-09-21 13:47:41 +00:00
### Examples
```sh
value = set "hello world"
empty = is_empty ${value}
```
2021-09-21 13:45:27 +00:00
### Aliases:
is_empty
2021-07-23 12:48:57 +00:00
<a name="std__string__KebabCase"></a>
2021-09-21 13:44:25 +00:00
## `std::string::KebabCase`
```sh
2021-07-23 12:48:57 +00:00
var = kebobcase text
```
2021-07-23 12:48:57 +00:00
Converts the provided string into kebob case.
All non-alphanumeric characters are ignored.
2021-09-21 13:47:41 +00:00
### Parameters
2021-07-23 12:48:57 +00:00
The string to convert.
2021-09-21 13:47:41 +00:00
### Return Value
2021-07-23 12:48:57 +00:00
The converted string.
2021-09-21 13:47:41 +00:00
### Examples
```sh
2021-07-23 12:48:57 +00:00
string = kebobcase "Hello, World!"
assert_eq ${string} "hello-world"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2021-07-23 12:48:57 +00:00
kebabcase
2021-07-23 12:48:57 +00:00
<a name="std__string__LastIndexOf"></a>
2021-09-21 13:44:25 +00:00
## `std::string::LastIndexOf`
```sh
2021-07-23 12:48:57 +00:00
var = last_indexof full_text text_to_find
```
2021-07-23 12:48:57 +00:00
This command will attempt to find the text from the second argument inside the text in the first argument.<br>
If found, an index value will be returned, otherwise none is returned.<br>
Unlike the **indexof** command, this command will search for text starting at the end, going backwards.
2021-09-21 13:47:41 +00:00
### Parameters
2021-07-23 12:48:57 +00:00
* The text to search in
* The text to find
2021-09-21 13:47:41 +00:00
### Return Value
2021-07-23 12:48:57 +00:00
The index of the text found or none if not found.
2021-09-21 13:47:41 +00:00
### Examples
```sh
2021-07-23 12:48:57 +00:00
index = last_indexof " some text " some
```
2021-09-21 13:45:27 +00:00
### Aliases:
2021-07-23 12:48:57 +00:00
last_indexof
2020-01-08 23:21:06 +00:00
<a name="std__string__Length"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Length`
2020-01-08 23:21:06 +00:00
```sh
var = length text
```
Returns the text length.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-08 23:21:06 +00:00
The text to extract the length from.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-08 23:21:06 +00:00
The text length value.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-08 23:21:06 +00:00
```sh
len = length "Hello World"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-08 23:21:06 +00:00
length, strlen
2021-07-23 12:48:57 +00:00
<a name="std__string__Lowercase"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Lowercase`
2021-07-14 16:00:25 +00:00
```sh
var = lowercase text
```
Converts the provided string into lowercase.
2021-09-21 13:47:41 +00:00
### Parameters
2021-07-14 16:00:25 +00:00
The string to convert.
2021-09-21 13:47:41 +00:00
### Return Value
2021-07-14 16:00:25 +00:00
The converted string.
2021-09-21 13:47:41 +00:00
### Examples
2021-07-14 16:00:25 +00:00
```sh
string = lowercase "Hello World"
assert_eq ${string} "hello world"
```
2021-07-23 12:48:57 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-07-14 16:00:25 +00:00
lowercase
2020-01-18 17:36:26 +00:00
<a name="std__string__Replace"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Replace`
2020-01-18 17:36:26 +00:00
```sh
var = replace text from to
```
Returns new value of text after replacing all from values to the provided to values.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-18 17:36:26 +00:00
* The full text
* The from text
* The to text
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-18 17:36:26 +00:00
The updated text.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-18 17:36:26 +00:00
```sh
text = set "my large text value with lots of text"
updated = replace ${text} text stuff
assert_eq ${updated} "my large stuff value with lots of stuff"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-18 17:36:26 +00:00
replace
2021-07-14 03:44:47 +00:00
<a name="std__string__SnakeCase"></a>
2021-09-21 13:44:25 +00:00
## `std::string::SnakeCase`
2021-07-14 03:44:47 +00:00
```sh
var = snakecase text
2021-07-14 03:44:47 +00:00
```
Converts the provided string into snake case.
All non-alphanumeric characters are ignored.
2021-09-21 13:47:41 +00:00
### Parameters
2021-07-14 03:44:47 +00:00
The string to convert.
2021-09-21 13:47:41 +00:00
### Return Value
2021-07-14 03:44:47 +00:00
The converted string.
2021-09-21 13:47:41 +00:00
### Examples
2021-07-14 03:44:47 +00:00
```sh
string = snakecase "Hello, World!"
2021-07-14 03:44:47 +00:00
assert_eq ${string} "hello_world"
```
2021-07-23 12:48:57 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
snakecase
2021-07-14 03:44:47 +00:00
2020-01-30 21:10:36 +00:00
<a name="std__string__Split"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Split`
2020-01-30 21:10:36 +00:00
```sh
handle = split text pattern
```
Splits the provided text based on the provided pattern and return a handle the
2022-06-11 10:48:47 +00:00
created array with all the split values.
2020-01-30 21:10:36 +00:00
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-30 21:10:36 +00:00
* The text to split
* The pattern to split by
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-30 21:10:36 +00:00
A handle to the values array.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-30 21:10:36 +00:00
```sh
handle = split a23b23c23d23e 23
len = array_length ${handle}
value = array_pop ${handle}
assert_eq ${value} e
value = array_pop ${handle}
assert_eq ${value} d
value = array_pop ${handle}
assert_eq ${value} c
value = array_pop ${handle}
assert_eq ${value} b
value = array_pop ${handle}
assert_eq ${value} a
release ${handle}
assert_eq ${len} 5
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-30 21:10:36 +00:00
split
<a name="std__string__StartsWith"></a>
2021-09-21 13:44:25 +00:00
## `std::string::StartsWith`
```sh
var = starts_with all partial
```
Returns true if the first argument starts with the value of the second argument.
2021-09-21 13:47:41 +00:00
### Parameters
* The full text to search in
* The prefix text to search for
2021-09-21 13:47:41 +00:00
### Return Value
**true** if starts with.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# valid conditions
result = starts_with abcd abc
value = set "some text"
result = starts_with ${value} "some te"
# will return false
result = starts_with abcd bcd
```
2021-09-21 13:45:27 +00:00
### Aliases:
starts_with
<a name="std__string__StringToBytes"></a>
2021-09-21 13:44:25 +00:00
## `std::string::StringToBytes`
```sh
handle = string_to_bytes text
```
Converts the provided string into binary format and returns a handle to the binary data.
2021-09-21 13:47:41 +00:00
### Parameters
The text to convert.
2021-09-21 13:47:41 +00:00
### Return Value
A handle to the binary data.
2021-09-21 13:47:41 +00:00
### Examples
```sh
handle = string_to_bytes "hello world"
text = bytes_to_string ${handle}
release ${handle}
assert_eq ${text} "hello world"
```
2021-09-21 13:45:27 +00:00
### Aliases:
string_to_bytes
2020-01-08 23:11:10 +00:00
<a name="std__string__SubString"></a>
2021-09-21 13:44:25 +00:00
## `std::string::SubString`
2020-01-08 23:11:10 +00:00
```sh
var = substring text
var = substring text start end
var = substring text start
var = substring text -end
```
The substring command will create a new string value from the text provided in the range requested.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-08 23:11:10 +00:00
* The text to substring from
* Additional parameters
* None - start index is 0 and end index is the text length
* Two arguments - First is the start index and second is the end index
* One argument
* If >= 0 it defines the start index and end index is the text length
* If < 0 it defines the end index going backwards from the end of the text. Start index is 0.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-08 23:11:10 +00:00
The substring value or false in case of error.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-08 23:11:10 +00:00
```sh
# string is 'Hello World'
string = substring "Hello World"
echo ${string}
# string is 'll'
string = substring "Hello World" 2 4
echo ${string}
# string is 'llo World'
string = substring "Hello World" 2
echo ${string}
# string is 'Hello W'
string = substring "Hello World" -4
echo ${string}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-08 23:11:10 +00:00
substring
<a name="std__string__Trim"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Trim`
```sh
var = trim value
```
Returns the provided value with leading and trailing whitespace removed.
2021-09-21 13:47:41 +00:00
### Parameters
The value to trim.
2021-09-21 13:47:41 +00:00
### Return Value
The trimmed value. If no input provided, this command will return none.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# trimmed will now hold "some text"
trimmed = trim " some text "
```
2021-09-21 13:45:27 +00:00
### Aliases:
trim
<a name="std__string__TrimEnd"></a>
2021-09-21 13:44:25 +00:00
## `std::string::TrimEnd`
```sh
var = trim_end value
```
Returns the provided value with trailing whitespace removed.
2021-09-21 13:47:41 +00:00
### Parameters
The value to trim.
2021-09-21 13:47:41 +00:00
### Return Value
The trimmed value. If no input provided, this command will return none.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# trimmed will now hold " some text"
trimmed = trim_end " some text "
```
2021-09-21 13:45:27 +00:00
### Aliases:
trim_end
<a name="std__string__TrimStart"></a>
2021-09-21 13:44:25 +00:00
## `std::string::TrimStart`
```sh
var = trim_start value
```
Returns the provided value with leading whitespace removed.
2021-09-21 13:47:41 +00:00
### Parameters
The value to trim.
2021-09-21 13:47:41 +00:00
### Return Value
The trimmed value. If no input provided, this command will return none.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# trimmed will now hold "some text "
trimmed = trim_start " some text "
```
2021-09-21 13:45:27 +00:00
### Aliases:
trim_start
2021-07-14 16:00:25 +00:00
<a name="std__string__Uppercase"></a>
2021-09-21 13:44:25 +00:00
## `std::string::Uppercase`
2021-07-14 16:00:25 +00:00
```sh
var = uppercase text
```
Converts the provided string into uppercase.
2021-09-21 13:47:41 +00:00
### Parameters
2021-07-14 16:00:25 +00:00
The string to convert.
2021-09-21 13:47:41 +00:00
### Return Value
2021-07-14 16:00:25 +00:00
The converted string.
2021-09-21 13:47:41 +00:00
### Examples
2021-07-14 16:00:25 +00:00
```sh
string = uppercase "Hello World"
assert_eq ${string} "HELLO WORLD"
```
2021-07-23 12:48:57 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2021-07-14 16:00:25 +00:00
uppercase
<a name="std__test__Assert"></a>
2021-09-21 13:44:25 +00:00
## `std::test::Assert`
2020-01-02 15:48:13 +00:00
```sh
assert value [error message]
```
Used to validate the input is truthy.<br>
If the value is one of the following:
* No output
* false (case insensitive)
* 0
* no (case insensitive)
* Empty value
It is considered falsy and will exist with an error.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 15:48:13 +00:00
* The value to evaluate
* Optional error message
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 15:48:13 +00:00
2020-01-02 16:17:57 +00:00
**true** if truthy.
2020-01-02 15:48:13 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 15:48:13 +00:00
```sh
2020-01-02 22:32:48 +00:00
# valid conditions
2020-01-02 15:48:13 +00:00
assert ok
assert true
assert yes
value = set "some text"
assert ${value}
# error conditions (each one will break the execution)
2020-01-02 15:48:13 +00:00
assert
assert false
assert 0
assert false "This is my error message"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 15:48:13 +00:00
assert
<a name="std__test__AssertEquals"></a>
2021-09-21 13:44:25 +00:00
## `std::test::AssertEquals`
2020-01-02 16:32:24 +00:00
```sh
assert_eq value1 value2 [error message]
```
Used to validate the input is the same.<br>
If they are not, the command will exist with an error.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 16:32:24 +00:00
* Two values to evaluate if they are equal
* Optional error message
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 16:32:24 +00:00
**true** if equal.
2020-01-02 16:32:24 +00:00
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 16:32:24 +00:00
```sh
2020-01-02 22:32:48 +00:00
# valid conditions
2020-01-02 16:32:24 +00:00
assert_eq yes yes
assert_eq false false
value = set "some text"
assert_eq ${value} "some text"
# error conditions (each one will break the execution)
2020-01-02 16:32:24 +00:00
assert_eq 1 2
assert_eq 1 2 "This is my error message"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 16:32:24 +00:00
assert_eq
2020-01-10 16:19:31 +00:00
<a name="std__test__AssertError"></a>
2021-09-21 13:44:25 +00:00
## `std::test::AssertError`
2020-01-10 16:19:31 +00:00
```sh
assert_error [error message]
```
This command will cause a runtime error which will not stop the script execution.<br>
If error message is provided, it will be used as part of the error output.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-10 16:19:31 +00:00
Optional error message.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-10 16:19:31 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-01-10 16:19:31 +00:00
```sh
assert_error
assert_error "This is my error message"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-10 16:19:31 +00:00
assert_error
<a name="std__test__AssertFail"></a>
2021-09-21 13:44:25 +00:00
## `std::test::AssertFail`
2020-01-02 16:17:57 +00:00
```sh
assert_fail [error message]
```
This command will exist with an error.<br>
If error message is provided, it will be used as part of the error output.
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-02 16:17:57 +00:00
Optional error message.
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-02 16:17:57 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-01-02 16:17:57 +00:00
```sh
assert_fail
assert_fail "This is my error message"
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-02 16:17:57 +00:00
assert_fail
<a name="std__test__AssertFalse"></a>
2021-09-21 13:44:25 +00:00
## `std::test::AssertFalse`
```sh
assert_false value [error message]
```
Used to validate the input is falsy.<br>
If the value is one of the following:
* No output
* false (case insensitive)
* 0
* no (case insensitive)
* Empty value
It is considered falsy.
2021-09-21 13:47:41 +00:00
### Parameters
* The value to evaluate
* Optional error message
2021-09-21 13:47:41 +00:00
### Return Value
**true** if falsy.
2021-09-21 13:47:41 +00:00
### Examples
```sh
# valid conditions
assert_false
assert_false false
assert_false 0
assert_false false "This is my error message"
# error conditions (each one will break the execution)
assert_false ok
assert_false true
assert_false yes
value = set "some text"
assert_false ${value}
```
2021-09-21 13:45:27 +00:00
### Aliases:
assert_false
<a name="std__test__TestDirectory"></a>
2021-09-21 13:44:25 +00:00
## `std::test::TestDirectory`
```sh
test_directory directory [pattern]
```
This command can be used to run unit tests written in duckscript.<br>
It will run all duckscript files in the directory tree ending with **test.ds** and for each file, it will run
all functions that start with **test_**.<br>
Each such function is considered as a test and can run any type of code and check itself using assert commands.
2021-09-21 13:47:41 +00:00
### Parameters
* The root directory of all test files (all files ending with **test.ds** in the directory tree will be checked)
* Optional pattern for the file name or test function to limit invocation of only those tests.
2021-09-21 13:47:41 +00:00
### Return Value
**true** if successful.
2021-09-21 13:47:41 +00:00
### Examples
This is an example of a test function:
```sh
function test_set_get_unset
unset_env TEST_SET_GET_UNSET
value = get_env TEST_SET_GET_UNSET
assert_false ${value}
value = set_env TEST_SET_GET_UNSET "test value"
assert ${value}
value = get_env TEST_SET_GET_UNSET
assert_eq ${value} "test value"
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
test_directory
2020-07-31 09:07:20 +00:00
<a name="std__test__TestFile"></a>
2021-09-21 13:44:25 +00:00
## `std::test::TestFile`
2020-07-31 09:07:20 +00:00
```sh
test_file file [test name]
```
This command can be used to run unit tests written in duckscript.<br>
It will run all test functions that start with **test_** in the given file.<br>
Each such function is considered as a test and can run any type of code and check itself using assert commands.
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-31 09:07:20 +00:00
* The file name containing the test functions.
* Optional pattern for the test function to limit invocation of only those tests.
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-31 09:07:20 +00:00
**true** if successful.
2021-09-21 13:47:41 +00:00
### Examples
2020-07-31 09:07:20 +00:00
This is an example of a test function:
```sh
function test_set_get_unset
unset_env TEST_SET_GET_UNSET
value = get_env TEST_SET_GET_UNSET
assert_false ${value}
value = set_env TEST_SET_GET_UNSET "test value"
assert ${value}
value = get_env TEST_SET_GET_UNSET
assert_eq ${value} "test value"
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-31 09:07:20 +00:00
test_file
<a name="std__thread__Sleep"></a>
2021-09-21 13:44:25 +00:00
## `std::thread::Sleep`
2019-12-30 10:45:28 +00:00
```sh
sleep millies
```
Will cause the script execution to half for the given amount of milliseconds.<br>
The command will also return the amount of milliseconds waited.
2021-09-21 13:47:41 +00:00
### Parameters
2019-12-30 10:45:28 +00:00
A positive numeric value.
2021-09-21 13:47:41 +00:00
### Return Value
2019-12-30 10:45:28 +00:00
The amount of milliseconds waited.
2021-09-21 13:47:41 +00:00
### Examples
2019-12-30 10:45:28 +00:00
```sh
2020-01-02 22:32:48 +00:00
# will sleep for 10 milliseconds
2019-12-30 10:45:28 +00:00
time = sleep 10
echo Waited for ${time} milliseconds.
```
2021-09-21 13:45:27 +00:00
### Aliases:
2019-12-30 10:45:28 +00:00
sleep
2020-01-18 17:10:44 +00:00
<a name="std__time__CurrentTimeMillies"></a>
2021-09-21 13:44:25 +00:00
## `std::time::CurrentTimeMillies`
2020-01-18 17:10:44 +00:00
```sh
var = current_time
```
Returns the current time in milliseconds (from January 1, 1970 UTC).
2021-09-21 13:47:41 +00:00
### Parameters
2020-01-18 17:10:44 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-01-18 17:10:44 +00:00
The current time in milliseconds.
2021-09-21 13:47:41 +00:00
### Examples
2020-01-18 17:10:44 +00:00
```sh
result = current_time
echo ${result}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-01-18 17:10:44 +00:00
current_time
2020-05-03 19:36:09 +00:00
<a name="std__var__GetAllVarNames"></a>
2021-09-21 13:44:25 +00:00
## `std::var::GetAllVarNames`
2020-05-03 19:36:09 +00:00
```sh
handle = get_all_var_names
```
Creates an array holding all currently known variable names and returns the array handle.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-03 19:36:09 +00:00
None
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-03 19:36:09 +00:00
A handle to the array.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-03 19:36:09 +00:00
```sh
handle = get_all_var_names
# once done we should release the handle
release ${handle}
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-03 19:36:09 +00:00
get_all_var_names
2020-05-02 11:24:54 +00:00
<a name="std__var__GetByName"></a>
2021-09-21 13:44:25 +00:00
## `std::var::GetByName`
2020-05-02 11:24:54 +00:00
```sh
var = get_by_name name
```
This command returns the variable value based on the given variable name.<br>
It is similar to
```sh
var = set ${name}
```
However, it allows for a dynamic variable name.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-02 11:24:54 +00:00
The variable name.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-02 11:24:54 +00:00
The variable value or none if no such variable exists.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-02 11:24:54 +00:00
```sh
var = set test
value = get_by_name var
defined = is_defined value
assert ${defined}
assert_eq ${value} test
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-02 11:24:54 +00:00
get_by_name
<a name="std__var__IsDefined"></a>
2021-09-21 13:44:25 +00:00
## `std::var::IsDefined`
```sh
var = is_defined key
```
Returns true if the provided variable name (not value) exists.
2021-09-21 13:47:41 +00:00
### Parameters
The variable name.
2021-09-21 13:47:41 +00:00
### Return Value
True if the variable is defined.
2021-09-21 13:47:41 +00:00
### Examples
```sh
key = set "hello world"
exists = is_defined key
```
2021-09-21 13:45:27 +00:00
### Aliases:
is_defined
2020-05-02 11:24:54 +00:00
<a name="std__var__Set"></a>
2021-09-21 13:44:25 +00:00
## `std::var::Set`
2020-05-02 11:24:54 +00:00
```sh
var = set arg [or arg]*
```
The set command will simply return the provided argument and set it to the output variable.<br>
In case the argument is falsy it will attempt to provide another value if an 'or' keyword is set.
A value is considered falsy if it is one of the following:
* false (case insensitive)
* 0
* no (case insensitive)
* Empty value
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-02 11:24:54 +00:00
The argument to set or an 'or' conditional arguments.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-02 11:24:54 +00:00
The first truthy value
2021-09-21 13:47:41 +00:00
### Examples
2020-05-02 11:24:54 +00:00
```sh
# Return simple 'hello' text value
var = set hello
# Return expanded value: 'home: ....'
var = set "home: ${HOME}"
value = set test or false
assert_eq ${value} test
value = set 0 or no or false or NO or FALSE
assert_eq ${value} FALSE
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-02 11:24:54 +00:00
set
2020-05-02 12:13:27 +00:00
<a name="std__var__SetByName"></a>
2021-09-21 13:44:25 +00:00
## `std::var::SetByName`
2020-05-02 12:13:27 +00:00
```sh
2020-05-04 07:23:12 +00:00
var = set_by_name name [value]
2020-05-02 12:13:27 +00:00
```
This command sets the variable value based on the variable name.<br>
It is similar to
```sh
name = set ${value}
```
However, it allows for a dynamic variable name.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-02 12:13:27 +00:00
* The variable name.
2020-05-04 07:23:12 +00:00
* The new variable value, if not provided, the variable will be unset.
2020-05-02 12:13:27 +00:00
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-02 12:13:27 +00:00
The new variable value.
2021-09-21 13:47:41 +00:00
### Examples
2020-05-02 12:13:27 +00:00
```sh
var = set test
value = get_by_name var
defined = is_defined value
assert ${defined}
assert_eq ${value} test
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-02 12:13:27 +00:00
set_by_name
2020-05-04 07:23:12 +00:00
<a name="std__var__Unset"></a>
2021-09-21 13:44:25 +00:00
## `std::var::Unset`
2020-05-04 07:23:12 +00:00
```sh
unset [names]*
```
Undefines all the variable names provided.
2021-09-21 13:47:41 +00:00
### Parameters
2020-05-04 07:23:12 +00:00
A list of variable names to undefine.
2021-09-21 13:47:41 +00:00
### Return Value
2020-05-04 07:23:12 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-05-04 07:23:12 +00:00
```sh
var = set 1
defined = is_defined var
assert ${defined}
unset var
defined = is_defined var
assert_false ${defined}
```
#### Source:
2021-09-21 13:31:05 +00:00
<details>
<summary>Show Source</summary>
2020-05-04 07:23:12 +00:00
```sh
for scope::unset::name in ${scope::unset::arguments}
set_by_name ${scope::unset::name}
end
```
2021-09-21 13:31:05 +00:00
</details>
2020-05-04 07:23:12 +00:00
2021-09-21 13:45:27 +00:00
### Aliases:
2020-05-04 07:23:12 +00:00
unset
2020-07-31 09:31:27 +00:00
<a name="std__var__UnsetAllVars"></a>
2021-09-21 13:44:25 +00:00
## `std::var::UnsetAllVars`
2020-07-31 09:31:27 +00:00
```sh
handle = unset_all_vars [--prefix value]
```
Removes all known variables.<br>
If the prefix is provided, only variables starting with the prefix value will be removed.
2021-09-21 13:47:41 +00:00
### Parameters
2020-07-31 09:31:27 +00:00
* Optional variable name prefix
2021-09-21 13:47:41 +00:00
### Return Value
2020-07-31 09:31:27 +00:00
None
2021-09-21 13:47:41 +00:00
### Examples
2020-07-31 09:31:27 +00:00
```sh
fn test_remove_all
a = set 1
b = set 2
defined = is_defined a
assert ${defined}
defined = is_defined b
assert ${defined}
unset_all_vars
defined = is_defined a
assert_false ${defined}
defined = is_defined b
assert_false ${defined}
end
fn test_remove_by_prefix
root1 = set true
root1.child = set true
root12 = set true
root2 = set true
defined = is_defined root1
assert ${defined}
defined = is_defined root1.child
assert ${defined}
defined = is_defined root12
assert ${defined}
defined = is_defined root2
assert ${defined}
unset_all_vars --prefix root1
defined = is_defined root1
assert_false ${defined}
defined = is_defined root1.child
assert_false ${defined}
defined = is_defined root12
assert_false ${defined}
defined = is_defined root2
assert ${defined}
end
```
2021-09-21 13:45:27 +00:00
### Aliases:
2020-07-31 09:31:27 +00:00
unset_all_vars
2019-12-30 10:45:28 +00:00
### License
Developed by Sagie Gur-Ari and licensed under the
[Apache 2](https://github.com/sagiegurari/duckscript/blob/master/LICENSE) open source license.