mirror of
https://github.com/sagiegurari/duckscript
synced 2024-09-29 20:54:34 +00:00
This commit is contained in:
parent
b36050fbb2
commit
0f75fafb21
|
@ -8,6 +8,7 @@
|
|||
* Default command run implementation should crash and not error #63
|
||||
* \[Breaking Change\] Invoking a command that does not exist should crash and not error
|
||||
* cat command to support multiple files #62
|
||||
* New debug commands (dump_instructions, dump_state, dump_variables) #58 #59 #60
|
||||
|
||||
### v0.1.6 (2020-01-12)
|
||||
|
||||
|
|
104
docs/sdk.md
104
docs/sdk.md
|
@ -20,6 +20,9 @@
|
|||
* [std::collections::Range (range)](#std__collections__Range)
|
||||
* [std::collections::ReadProperties (read_properties)](#std__collections__ReadProperties)
|
||||
* [std::collections::WriteProperties (write_properties)](#std__collections__WriteProperties)
|
||||
* [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::GetVar (get_env)](#std__env__GetVar)
|
||||
* [std::env::PrintCurrentDirectory (pwd)](#std__env__PrintCurrentDirectory)
|
||||
* [std::env::SetCurrentDirectory (cd, set_current_dir)](#std__env__SetCurrentDirectory)
|
||||
|
@ -865,6 +868,101 @@ text = write_properties a b a.b.c
|
|||
#### Aliases:
|
||||
write_properties
|
||||
|
||||
<a name="std__debug__DumpInstructions"></a>
|
||||
## std::debug::DumpInstructions
|
||||
```sh
|
||||
value = dump_instructions
|
||||
```
|
||||
|
||||
Returns all script instructions structure (not script text) in textual form.
|
||||
|
||||
#### Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Return Value
|
||||
|
||||
The script instructions.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
value = dump_instructions
|
||||
found = contains ${value} dump_instructions
|
||||
assert found
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
dump_instructions
|
||||
|
||||
<a name="std__debug__DumpState"></a>
|
||||
## std::debug::DumpState
|
||||
```sh
|
||||
value = dump_state
|
||||
```
|
||||
|
||||
Returns all script state in textual form.
|
||||
|
||||
#### Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Return Value
|
||||
|
||||
The script state.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
numbers = range -5 15
|
||||
|
||||
text = dump_instructions
|
||||
found = contains ${text} -5
|
||||
assert found
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
dump_state
|
||||
|
||||
<a name="std__debug__DumpVariables"></a>
|
||||
## std::debug::DumpVariables
|
||||
```sh
|
||||
value = dump_variables
|
||||
```
|
||||
|
||||
Returns all script variables in textual form.
|
||||
|
||||
#### Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Return Value
|
||||
|
||||
The script variables.
|
||||
|
||||
#### 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
|
||||
```
|
||||
|
||||
|
||||
#### Aliases:
|
||||
dump_variables
|
||||
|
||||
<a name="std__env__GetVar"></a>
|
||||
## std::env::GetVar
|
||||
```sh
|
||||
|
@ -1451,15 +1549,15 @@ mv
|
|||
<a name="std__fs__Print"></a>
|
||||
## std::fs::Print
|
||||
```sh
|
||||
var = cat file
|
||||
var = cat [file]+
|
||||
```
|
||||
|
||||
The cat command will print out the requested file.<br>
|
||||
The cat command will print out the requested file/s.<br>
|
||||
In addition it will also return the value to the output variable.
|
||||
|
||||
#### Parameters
|
||||
|
||||
A single parameter holding the file path.
|
||||
Multiple file paths.
|
||||
|
||||
#### Return Value
|
||||
|
||||
|
|
21
duckscript_sdk/src/sdk/std/debug/dump_instructions/help.md
Normal file
21
duckscript_sdk/src/sdk/std/debug/dump_instructions/help.md
Normal file
|
@ -0,0 +1,21 @@
|
|||
```sh
|
||||
value = dump_instructions
|
||||
```
|
||||
|
||||
Returns all script instructions structure (not script text) in textual form.
|
||||
|
||||
#### Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Return Value
|
||||
|
||||
The script instructions.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
value = dump_instructions
|
||||
found = contains ${value} dump_instructions
|
||||
assert found
|
||||
```
|
52
duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs
Executable file
52
duckscript_sdk/src/sdk/std/debug/dump_instructions/mod.rs
Executable file
|
@ -0,0 +1,52 @@
|
|||
use crate::utils::pckg;
|
||||
use duckscript::types::command::{Command, CommandResult, Commands};
|
||||
use duckscript::types::instruction::Instruction;
|
||||
use duckscript::types::runtime::StateValue;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "./mod_test.rs"]
|
||||
mod mod_test;
|
||||
|
||||
struct CommandImpl {
|
||||
package: String,
|
||||
}
|
||||
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> String {
|
||||
pckg::concat(&self.package, "DumpInstructions")
|
||||
}
|
||||
|
||||
fn aliases(&self) -> Vec<String> {
|
||||
vec!["dump_instructions".to_string()]
|
||||
}
|
||||
|
||||
fn help(&self) -> String {
|
||||
include_str!("help.md").to_string()
|
||||
}
|
||||
|
||||
fn requires_context(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn run_with_context(
|
||||
&self,
|
||||
_arguments: Vec<String>,
|
||||
_state: &mut HashMap<String, StateValue>,
|
||||
_variables: &mut HashMap<String, String>,
|
||||
_output_variable: Option<String>,
|
||||
instructions: &Vec<Instruction>,
|
||||
_commands: &mut Commands,
|
||||
_line: usize,
|
||||
) -> CommandResult {
|
||||
let string_value = format!("{:#?}", instructions).to_string();
|
||||
|
||||
CommandResult::Continue(Some(string_value))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||
Box::new(CommandImpl {
|
||||
package: package.to_string(),
|
||||
})
|
||||
}
|
|
@ -0,0 +1,17 @@
|
|||
use super::*;
|
||||
use crate::test;
|
||||
use crate::test::CommandValidation;
|
||||
|
||||
#[test]
|
||||
fn common_functions() {
|
||||
test::test_common_command_functions(create(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_no_args() {
|
||||
test::run_script_and_validate(
|
||||
vec![create("")],
|
||||
"out = dump_instructions",
|
||||
CommandValidation::Contains("out".to_string(), "dump_instructions".to_string()),
|
||||
);
|
||||
}
|
23
duckscript_sdk/src/sdk/std/debug/dump_state/help.md
Normal file
23
duckscript_sdk/src/sdk/std/debug/dump_state/help.md
Normal file
|
@ -0,0 +1,23 @@
|
|||
```sh
|
||||
value = dump_state
|
||||
```
|
||||
|
||||
Returns all script state in textual form.
|
||||
|
||||
#### Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Return Value
|
||||
|
||||
The script state.
|
||||
|
||||
#### Examples
|
||||
|
||||
```sh
|
||||
numbers = range -5 15
|
||||
|
||||
text = dump_instructions
|
||||
found = contains ${text} -5
|
||||
assert found
|
||||
```
|
52
duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs
Executable file
52
duckscript_sdk/src/sdk/std/debug/dump_state/mod.rs
Executable file
|
@ -0,0 +1,52 @@
|
|||
use crate::utils::pckg;
|
||||
use duckscript::types::command::{Command, CommandResult, Commands};
|
||||
use duckscript::types::instruction::Instruction;
|
||||
use duckscript::types::runtime::StateValue;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "./mod_test.rs"]
|
||||
mod mod_test;
|
||||
|
||||
struct CommandImpl {
|
||||
package: String,
|
||||
}
|
||||
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> String {
|
||||
pckg::concat(&self.package, "DumpState")
|
||||
}
|
||||
|
||||
fn aliases(&self) -> Vec<String> {
|
||||
vec!["dump_state".to_string()]
|
||||
}
|
||||
|
||||
fn help(&self) -> String {
|
||||
include_str!("help.md").to_string()
|
||||
}
|
||||
|
||||
fn requires_context(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn run_with_context(
|
||||
&self,
|
||||
_arguments: Vec<String>,
|
||||
state: &mut HashMap<String, StateValue>,
|
||||
_variables: &mut HashMap<String, String>,
|
||||
_output_variable: Option<String>,
|
||||
_instructions: &Vec<Instruction>,
|
||||
_commands: &mut Commands,
|
||||
_line: usize,
|
||||
) -> CommandResult {
|
||||
let string_value = format!("{:#?}", state).to_string();
|
||||
|
||||
CommandResult::Continue(Some(string_value))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||
Box::new(CommandImpl {
|
||||
package: package.to_string(),
|
||||
})
|
||||
}
|
20
duckscript_sdk/src/sdk/std/debug/dump_state/mod_test.rs
Normal file
20
duckscript_sdk/src/sdk/std/debug/dump_state/mod_test.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use super::*;
|
||||
use crate::test;
|
||||
use crate::test::{ArrayCommand, CommandValidation};
|
||||
|
||||
#[test]
|
||||
fn common_functions() {
|
||||
test::test_common_command_functions(create(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_no_args() {
|
||||
test::run_script_and_validate(
|
||||
vec![create(""), Box::new(ArrayCommand {})],
|
||||
r#"
|
||||
test_var = test_array 1 2 3
|
||||
out = dump_state
|
||||
"#,
|
||||
CommandValidation::Contains("out".to_string(), "3".to_string()),
|
||||
);
|
||||
}
|
30
duckscript_sdk/src/sdk/std/debug/dump_variables/help.md
Normal file
30
duckscript_sdk/src/sdk/std/debug/dump_variables/help.md
Normal file
|
@ -0,0 +1,30 @@
|
|||
```sh
|
||||
value = dump_variables
|
||||
```
|
||||
|
||||
Returns all script variables in textual form.
|
||||
|
||||
#### Parameters
|
||||
|
||||
None
|
||||
|
||||
#### Return Value
|
||||
|
||||
The script variables.
|
||||
|
||||
#### 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
|
||||
```
|
52
duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs
Executable file
52
duckscript_sdk/src/sdk/std/debug/dump_variables/mod.rs
Executable file
|
@ -0,0 +1,52 @@
|
|||
use crate::utils::pckg;
|
||||
use duckscript::types::command::{Command, CommandResult, Commands};
|
||||
use duckscript::types::instruction::Instruction;
|
||||
use duckscript::types::runtime::StateValue;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "./mod_test.rs"]
|
||||
mod mod_test;
|
||||
|
||||
struct CommandImpl {
|
||||
package: String,
|
||||
}
|
||||
|
||||
impl Command for CommandImpl {
|
||||
fn name(&self) -> String {
|
||||
pckg::concat(&self.package, "DumpVariables")
|
||||
}
|
||||
|
||||
fn aliases(&self) -> Vec<String> {
|
||||
vec!["dump_variables".to_string()]
|
||||
}
|
||||
|
||||
fn help(&self) -> String {
|
||||
include_str!("help.md").to_string()
|
||||
}
|
||||
|
||||
fn requires_context(&self) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
fn run_with_context(
|
||||
&self,
|
||||
_arguments: Vec<String>,
|
||||
_state: &mut HashMap<String, StateValue>,
|
||||
variables: &mut HashMap<String, String>,
|
||||
_output_variable: Option<String>,
|
||||
_instructions: &Vec<Instruction>,
|
||||
_commands: &mut Commands,
|
||||
_line: usize,
|
||||
) -> CommandResult {
|
||||
let string_value = format!("{:#?}", variables).to_string();
|
||||
|
||||
CommandResult::Continue(Some(string_value))
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn create(package: &str) -> Box<dyn Command> {
|
||||
Box::new(CommandImpl {
|
||||
package: package.to_string(),
|
||||
})
|
||||
}
|
20
duckscript_sdk/src/sdk/std/debug/dump_variables/mod_test.rs
Normal file
20
duckscript_sdk/src/sdk/std/debug/dump_variables/mod_test.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
use super::*;
|
||||
use crate::test;
|
||||
use crate::test::{CommandValidation, SetCommand};
|
||||
|
||||
#[test]
|
||||
fn common_functions() {
|
||||
test::test_common_command_functions(create(""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn run_no_args() {
|
||||
test::run_script_and_validate(
|
||||
vec![create(""), Box::new(SetCommand {})],
|
||||
r#"
|
||||
test_var = test_set 1
|
||||
out = dump_variables
|
||||
"#,
|
||||
CommandValidation::Contains("out".to_string(), "test_var".to_string()),
|
||||
);
|
||||
}
|
19
duckscript_sdk/src/sdk/std/debug/mod.rs
Executable file
19
duckscript_sdk/src/sdk/std/debug/mod.rs
Executable file
|
@ -0,0 +1,19 @@
|
|||
mod dump_instructions;
|
||||
mod dump_state;
|
||||
mod dump_variables;
|
||||
|
||||
use crate::utils::pckg;
|
||||
use duckscript::types::command::Commands;
|
||||
use duckscript::types::error::ScriptError;
|
||||
|
||||
static PACKAGE: &str = "debug";
|
||||
|
||||
pub(crate) fn load(commands: &mut Commands, parent: &str) -> Result<(), ScriptError> {
|
||||
let package = pckg::concat(parent, PACKAGE);
|
||||
|
||||
commands.set(dump_instructions::create(&package))?;
|
||||
commands.set(dump_state::create(&package))?;
|
||||
commands.set(dump_variables::create(&package))?;
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
pub(crate) mod alias;
|
||||
pub(crate) mod collections;
|
||||
mod debug;
|
||||
mod echo;
|
||||
mod env;
|
||||
mod eval;
|
||||
|
@ -42,6 +43,7 @@ pub(crate) fn load(commands: &mut Commands) -> Result<(), ScriptError> {
|
|||
commands.set(unalias::create(PACKAGE))?;
|
||||
|
||||
collections::load(commands, PACKAGE)?;
|
||||
debug::load(commands, PACKAGE)?;
|
||||
env::load(commands, PACKAGE)?;
|
||||
flowcontrol::load(commands, PACKAGE)?;
|
||||
fs::load(commands, PACKAGE)?;
|
||||
|
|
29
examples/debug.ds
Normal file
29
examples/debug.ds
Normal file
|
@ -0,0 +1,29 @@
|
|||
|
||||
one = set 1
|
||||
two = set 2
|
||||
values = array 1 2 yes true
|
||||
numbers = range -5 15
|
||||
|
||||
text = dump_instructions
|
||||
found = contains ${text} -5
|
||||
assert found
|
||||
echo Script Instructions:
|
||||
echo ${text}
|
||||
|
||||
text = dump_variables
|
||||
found = contains ${text} two
|
||||
assert found
|
||||
found = contains ${text} 2
|
||||
assert found
|
||||
found = contains ${text} handle
|
||||
assert found
|
||||
echo Script Variables:
|
||||
echo ${text}
|
||||
|
||||
text = dump_state
|
||||
found = contains ${text} yes
|
||||
assert found
|
||||
found = contains ${text} 7
|
||||
assert found
|
||||
echo Script State:
|
||||
echo ${text}
|
25
test/std/debug/debug_test.ds
Normal file
25
test/std/debug/debug_test.ds
Normal file
|
@ -0,0 +1,25 @@
|
|||
|
||||
function test_dump
|
||||
one = set 1
|
||||
two = set 2
|
||||
values = array 1 2 yes true
|
||||
numbers = range -5 15
|
||||
|
||||
text = dump_instructions
|
||||
found = contains ${text} -5
|
||||
assert found
|
||||
|
||||
text = dump_variables
|
||||
found = contains ${text} two
|
||||
assert found
|
||||
found = contains ${text} 2
|
||||
assert found
|
||||
found = contains ${text} handle
|
||||
assert found
|
||||
|
||||
text = dump_state
|
||||
found = contains ${text} yes
|
||||
assert found
|
||||
found = contains ${text} 7
|
||||
assert found
|
||||
end
|
Loading…
Reference in a new issue