Skip to content

Commit 1111c91

Browse files
committed
release
1 parent c5f2212 commit 1111c91

File tree

7 files changed

+70
-74
lines changed

7 files changed

+70
-74
lines changed

.buildnumber

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
11
1+
12

CHANGELOG.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
## CHANGELOG
22

3-
### v0.10.0
3+
### v0.10.0 (2024-10-03)
44

5-
* Enhancement: Runtime - \[Breaking Change\] New Env struct enabling commands to redirect out/err to provided streams #440
65
* Enhancement: Runtime - \[Breaking Change\] Commands now get new CommandArgs struct instead of multiple fields.
7-
* Enhancement: Runtime - Enable to halt execution via env.
86

97
### v0.9.4 (2024-09-28)
108

9+
* Enhancement: Runtime - \[Breaking Change\] New Env struct enabling commands to redirect out/err to provided streams #440
1110
* Enhancement: Runtime - Adding halt interrupt to env #448 (thanks @nickheyer)
1211

1312
### v0.9.3 (2024-01-19)

Cargo.lock

Lines changed: 32 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 29 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@
3434
* [Full SDK Docs](https://github.com/sagiegurari/duckscript/blob/master/docs/sdk.md)
3535
* [Final Notes](#tutorial-final-notes)
3636
* [Duckscript Command Implementation Tutorial](#sdk-tutorial)
37-
* [Standard Commands](#sdk-tutorial-standard-commands)
38-
* [Context Commands](#sdk-tutorial-context-commands)
37+
* [Commands](#sdk-tutorial-commands)
38+
* [Access The Context](#sdk-tutorial-commands-context)
3939
* [Duckscript Embedding Tutorial](#embed-tutorial)
4040
* [Setting Up The Context](#embed-tutorial-setup-context)
4141
* [Running The Script](#embed-tutorial-running)
@@ -401,21 +401,16 @@ If you want to know how to write your own commands or embed the duckscript runti
401401
Want to write new custom commands so you can use them in your duckscripts? great!<br>
402402
Hopefully the following sections will help you gain the basic knowledge on how to write them.<br>
403403
404-
First of all it is important to understand that there are two types of commands:
405-
406-
* Commands which execute some action like copying files, printing some text to the console or returning an environment variable.
407-
* Commands which provide flow control or some more complex action and require modifying the internal context in runtime.
408-
409-
<a name="sdk-tutorial-standard-commands"></a>
410-
## Standard Commands
404+
<a name="sdk-tutorial-commands"></a>
405+
## Commands
411406
Commands are structs that must implement the Command trait.<br>
412407
413408
* They must have a name, which is used to invoke the command.<br>
414409
* They optionally may have aliases which can also be used to invoke the command.<br>
415410
* They should return help documentation in markdown format in order to generate SDK documentation (must for PRs to duckscript official SDK).<br>
416411
* They must implement the **run** function which holds the command logic.<br>
417412
418-
The run function accepts the command arguments (variables already replaced to actual values) and returns the command result.<br>
413+
The run function accepts the command arguments (args array contains actual values and not original variables) and returns the command result.<br>
419414
The command result can be one of the following:
420415
421416
* Continue(Option<String>) - Tells the runner to continue to the next command and optionally set the output variable the given value.
@@ -438,11 +433,15 @@ impl Command for SetCommand {
438433
"set".to_string()
439434
}
440435
441-
fn run(&self, arguments: Vec<String>) -> CommandResult {
442-
let output = if arguments.is_empty() {
436+
fn clone_and_box(&self) -> Box<dyn Command> {
437+
Box::new((*self).clone())
438+
}
439+
440+
fn run(&self, arguments: CommandArgs) -> CommandResult {
441+
let output = if arguments.args.is_empty() {
443442
None
444443
} else {
445-
Some(arguments[0].clone())
444+
Some(arguments.args[0].clone())
446445
};
447446
448447
CommandResult::Continue(output)
@@ -465,11 +464,15 @@ impl Command for GetEnvCommand {
465464
"get_env".to_string()
466465
}
467466
468-
fn run(&self, arguments: Vec<String>) -> CommandResult {
469-
if arguments.is_empty() {
467+
fn clone_and_box(&self) -> Box<dyn Command> {
468+
Box::new((*self).clone())
469+
}
470+
471+
fn run(&self, arguments: CommandArgs) -> CommandResult {
472+
if arguments.args.is_empty() {
470473
CommandResult::Error("Missing environment variable name.".to_string())
471474
} else {
472-
match env::var(&arguments[0]) {
475+
match env::var(&arguments.args[0]) {
473476
Ok(value) => CommandResult::Continue(Some(value)),
474477
Err(_) => CommandResult::Continue(None),
475478
}
@@ -480,38 +483,23 @@ impl Command for GetEnvCommand {
480483
481484
You can look at more examples in the duckscript_sdk folder.
482485
483-
<a name="sdk-tutorial-context-commands"></a>
484-
## Context Commands
485-
Context commands are exactly the same as standard commands except that they have access to the runtime context.<br>
486-
Therefore they implement the same Command trait but this time instead of implementing the run function, they need to implement the following:
487-
488-
* requires_context - Must return true
489-
* run_with_context - The same logic you would put in the run function but now you have access to a lot more of the runtime context.
490-
491-
The run_with_context signature is as follows:
486+
<a name="sdk-tutorial-commands-context"></a>
487+
## Access The Context
488+
The duckscript runtime context is available in the CommandArgs struc.<br>
492489
493490
```rust
494491
/// Run the instruction with access to the runtime context.
495492
///
496-
/// # Arguments
497-
///
498-
/// * `arguments` - The command arguments array
493+
/// The CommandArgs has the following members:
494+
/// * `args` - The command arguments array
499495
/// * `state` - Internal state which is only used by commands to store/pull data
500496
/// * `variables` - All script variables
501497
/// * `output_variable` - The output variable name (if defined)
502498
/// * `instructions` - The entire list of instructions which make up the currently running script
503499
/// * `commands` - The currently known commands
504500
/// * `line` - The current instruction line number (global line number after including all scripts into one global script)
505-
fn run_with_context(
506-
&self,
507-
arguments: Vec<String>,
508-
state: &mut HashMap<String, StateValue>,
509-
variables: &mut HashMap<String, String>,
510-
output_variable: Option<String>,
511-
instructions: &Vec<Instruction>,
512-
commands: &mut Commands,
513-
line: usize,
514-
) -> CommandResult;
501+
/// * `env` - The current runtime env with access to out/err writers, etc...
502+
fn run(&self, arguments: CommandArgs) -> CommandResult;
515503
```
516504
517505
With access to this context you can add/remove/switch commands in runtime, store/pull internal state, add/remove/change variables and so on...
@@ -524,7 +512,7 @@ The duckscript cli basically embeds duckscript so you can look at it as a refere
524512
```rust
525513
let mut context = Context::new();
526514
duckscriptsdk::load(&mut context.commands)?;
527-
runner::run_script_file(file, context)?;
515+
runner::run_script_file(file, context, None)?;
528516
```
529517
530518
That's it!<br>
@@ -547,10 +535,10 @@ The following public functions are available:
547535
548536
```rust
549537
/// Executes the provided script with the given context
550-
pub fn run_script(text: &str, context: Context) -> Result<Context, ScriptError>;
538+
pub fn run_script(text: &str, context: Context, env: Option<Env>) -> Result<Context, ScriptError>;
551539
552540
/// Executes the provided script file with the given context
553-
pub fn run_script_file(file: &str, context: Context) -> Result<Context, ScriptError>;
541+
pub fn run_script_file(file: &str, context: Context, env: Option<Env>) -> Result<Context, ScriptError>;
554542
```
555543
556544
<a name="editor-support"></a>

duckscript/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "duckscript"
3-
version = "0.8.1"
3+
version = "0.9.0"
44
authors = ["Sagie Gur-Ari <[email protected]>"]
55
description = "Simple, extendable and embeddable scripting language."
66
license = "Apache-2.0"

duckscript_cli/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "duckscript_cli"
3-
version = "0.9.4"
3+
version = "0.10.0"
44
authors = ["Sagie Gur-Ari <[email protected]>"]
55
description = "The duckscript command line executable."
66
license = "Apache-2.0"
@@ -27,8 +27,8 @@ name = "duck"
2727
path = "src/main.rs"
2828

2929
[dependencies]
30-
duckscript = { version = "^0.8.1", path = "../duckscript" }
31-
duckscriptsdk = { version = "^0.9.4", path = "../duckscript_sdk", default-features = false }
30+
duckscript = { version = "^0.9.0", path = "../duckscript" }
31+
duckscriptsdk = { version = "^0.10.0", path = "../duckscript_sdk", default-features = false }
3232

3333
[features]
3434
tls-rustls = ["duckscriptsdk/tls-rustls"]

duckscript_sdk/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "duckscriptsdk"
3-
version = "0.9.4"
3+
version = "0.10.0"
44
authors = ["Sagie Gur-Ari <[email protected]>"]
55
description = "The duckscript SDK."
66
license = "Apache-2.0"
@@ -29,7 +29,7 @@ attohttpc = { version = "^0.28", default-features = false, features = [
2929
base64 = "^0.22"
3030
cfg-if = "^1"
3131
colored = "^2"
32-
duckscript = { version = "^0.8.1", path = "../duckscript" }
32+
duckscript = { version = "^0.9.0", path = "../duckscript" }
3333
evalexpr = "^11"
3434
fs_extra = "^1"
3535
fsio = { version = "^0.4", features = ["temp-path"] }

0 commit comments

Comments
 (0)