Skip to content

Commit

Permalink
release
Browse files Browse the repository at this point in the history
  • Loading branch information
sagiegurari committed Oct 3, 2024
1 parent c5f2212 commit 1111c91
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .buildnumber
Original file line number Diff line number Diff line change
@@ -1 +1 @@
11
12
5 changes: 2 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
## CHANGELOG

### v0.10.0
### v0.10.0 (2024-10-03)

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

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

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

### v0.9.3 (2024-01-19)
Expand Down
55 changes: 32 additions & 23 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 29 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
* [Full SDK Docs](https://github.com/sagiegurari/duckscript/blob/master/docs/sdk.md)
* [Final Notes](#tutorial-final-notes)
* [Duckscript Command Implementation Tutorial](#sdk-tutorial)
* [Standard Commands](#sdk-tutorial-standard-commands)
* [Context Commands](#sdk-tutorial-context-commands)
* [Commands](#sdk-tutorial-commands)
* [Access The Context](#sdk-tutorial-commands-context)
* [Duckscript Embedding Tutorial](#embed-tutorial)
* [Setting Up The Context](#embed-tutorial-setup-context)
* [Running The Script](#embed-tutorial-running)
Expand Down Expand Up @@ -401,21 +401,16 @@ If you want to know how to write your own commands or embed the duckscript runti
Want to write new custom commands so you can use them in your duckscripts? great!<br>
Hopefully the following sections will help you gain the basic knowledge on how to write them.<br>
First of all it is important to understand that there are two types of commands:
* Commands which execute some action like copying files, printing some text to the console or returning an environment variable.
* Commands which provide flow control or some more complex action and require modifying the internal context in runtime.
<a name="sdk-tutorial-standard-commands"></a>
## Standard Commands
<a name="sdk-tutorial-commands"></a>
## Commands
Commands are structs that must implement the Command trait.<br>
* They must have a name, which is used to invoke the command.<br>
* They optionally may have aliases which can also be used to invoke the command.<br>
* They should return help documentation in markdown format in order to generate SDK documentation (must for PRs to duckscript official SDK).<br>
* They must implement the **run** function which holds the command logic.<br>
The run function accepts the command arguments (variables already replaced to actual values) and returns the command result.<br>
The run function accepts the command arguments (args array contains actual values and not original variables) and returns the command result.<br>
The command result can be one of the following:
* Continue(Option<String>) - Tells the runner to continue to the next command and optionally set the output variable the given value.
Expand All @@ -438,11 +433,15 @@ impl Command for SetCommand {
"set".to_string()
}
fn run(&self, arguments: Vec<String>) -> CommandResult {
let output = if arguments.is_empty() {
fn clone_and_box(&self) -> Box<dyn Command> {
Box::new((*self).clone())
}
fn run(&self, arguments: CommandArgs) -> CommandResult {
let output = if arguments.args.is_empty() {
None
} else {
Some(arguments[0].clone())
Some(arguments.args[0].clone())
};
CommandResult::Continue(output)
Expand All @@ -465,11 +464,15 @@ impl Command for GetEnvCommand {
"get_env".to_string()
}
fn run(&self, arguments: Vec<String>) -> CommandResult {
if arguments.is_empty() {
fn clone_and_box(&self) -> Box<dyn Command> {
Box::new((*self).clone())
}
fn run(&self, arguments: CommandArgs) -> CommandResult {
if arguments.args.is_empty() {
CommandResult::Error("Missing environment variable name.".to_string())
} else {
match env::var(&arguments[0]) {
match env::var(&arguments.args[0]) {
Ok(value) => CommandResult::Continue(Some(value)),
Err(_) => CommandResult::Continue(None),
}
Expand All @@ -480,38 +483,23 @@ impl Command for GetEnvCommand {
You can look at more examples in the duckscript_sdk folder.
<a name="sdk-tutorial-context-commands"></a>
## Context Commands
Context commands are exactly the same as standard commands except that they have access to the runtime context.<br>
Therefore they implement the same Command trait but this time instead of implementing the run function, they need to implement the following:
* requires_context - Must return true
* run_with_context - The same logic you would put in the run function but now you have access to a lot more of the runtime context.
The run_with_context signature is as follows:
<a name="sdk-tutorial-commands-context"></a>
## Access The Context
The duckscript runtime context is available in the CommandArgs struc.<br>
```rust
/// Run the instruction with access to the runtime context.
///
/// # Arguments
///
/// * `arguments` - The command arguments array
/// The CommandArgs has the following members:
/// * `args` - The command arguments array
/// * `state` - Internal state which is only used by commands to store/pull data
/// * `variables` - All script variables
/// * `output_variable` - The output variable name (if defined)
/// * `instructions` - The entire list of instructions which make up the currently running script
/// * `commands` - The currently known commands
/// * `line` - The current instruction line number (global line number after including all scripts into one global script)
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;
/// * `env` - The current runtime env with access to out/err writers, etc...
fn run(&self, arguments: CommandArgs) -> CommandResult;
```
With access to this context you can add/remove/switch commands in runtime, store/pull internal state, add/remove/change variables and so on...
Expand All @@ -524,7 +512,7 @@ The duckscript cli basically embeds duckscript so you can look at it as a refere
```rust
let mut context = Context::new();
duckscriptsdk::load(&mut context.commands)?;
runner::run_script_file(file, context)?;
runner::run_script_file(file, context, None)?;
```
That's it!<br>
Expand All @@ -547,10 +535,10 @@ The following public functions are available:
```rust
/// Executes the provided script with the given context
pub fn run_script(text: &str, context: Context) -> Result<Context, ScriptError>;
pub fn run_script(text: &str, context: Context, env: Option<Env>) -> Result<Context, ScriptError>;
/// Executes the provided script file with the given context
pub fn run_script_file(file: &str, context: Context) -> Result<Context, ScriptError>;
pub fn run_script_file(file: &str, context: Context, env: Option<Env>) -> Result<Context, ScriptError>;
```
<a name="editor-support"></a>
Expand Down
2 changes: 1 addition & 1 deletion duckscript/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "duckscript"
version = "0.8.1"
version = "0.9.0"
authors = ["Sagie Gur-Ari <[email protected]>"]
description = "Simple, extendable and embeddable scripting language."
license = "Apache-2.0"
Expand Down
6 changes: 3 additions & 3 deletions duckscript_cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "duckscript_cli"
version = "0.9.4"
version = "0.10.0"
authors = ["Sagie Gur-Ari <[email protected]>"]
description = "The duckscript command line executable."
license = "Apache-2.0"
Expand All @@ -27,8 +27,8 @@ name = "duck"
path = "src/main.rs"

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

[features]
tls-rustls = ["duckscriptsdk/tls-rustls"]
Expand Down
4 changes: 2 additions & 2 deletions duckscript_sdk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "duckscriptsdk"
version = "0.9.4"
version = "0.10.0"
authors = ["Sagie Gur-Ari <[email protected]>"]
description = "The duckscript SDK."
license = "Apache-2.0"
Expand Down Expand Up @@ -29,7 +29,7 @@ attohttpc = { version = "^0.28", default-features = false, features = [
base64 = "^0.22"
cfg-if = "^1"
colored = "^2"
duckscript = { version = "^0.8.1", path = "../duckscript" }
duckscript = { version = "^0.9.0", path = "../duckscript" }
evalexpr = "^11"
fs_extra = "^1"
fsio = { version = "^0.4", features = ["temp-path"] }
Expand Down

0 comments on commit 1111c91

Please sign in to comment.