Skip to content

Commit

Permalink
feat(standalone-runtime): allow passing Vars (#176)
Browse files Browse the repository at this point in the history
feat(standalone-runtime): allow passing `Vars`

With this change it will now be possible to pass and overwrite the `vars`
section of a data flow through command line options. For instance:

```sh
zenoh-flow-standalone-runtime --vars BUILD=release \
    ./examples/flow/getting-started.yaml
```

Signed-off-by: Julien Loudet <julien.loudet@zettascale.tech>
  • Loading branch information
J-Loudet authored Feb 7, 2024
1 parent 6958b09 commit 276e45d
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions zenoh-flow-standalone-runtime/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use anyhow::Context;
use async_std::io::ReadExt;
use clap::Parser;
use std::{path::PathBuf, sync::Arc};
use zenoh_flow_commons::{RuntimeId, Vars};
use zenoh_flow_commons::{parse_vars, RuntimeId, Vars};
use zenoh_flow_descriptors::{DataFlowDescriptor, FlattenedDataFlowDescriptor};
use zenoh_flow_records::DataFlowRecord;
use zenoh_flow_runtime::{
Expand All @@ -31,6 +31,13 @@ struct Cli {
/// The, optional, location of the configuration to load nodes implemented not in Rust.
#[arg(short, long, value_name = "path")]
extensions: Option<PathBuf>,
/// Variables to add / overwrite in the `vars` section of your data
/// flow, with the form `KEY=VALUE`. Can be repeated multiple times.
///
/// Example:
/// --vars HOME_DIR=/home/zenoh-flow --vars BUILD=debug
#[arg(long, value_parser = parse_vars::<String, String>, verbatim_doc_comment)]
vars: Option<Vec<(String, String)>>,
}

#[async_std::main]
Expand All @@ -57,15 +64,18 @@ async fn main() {

let loader = Loader::new(extensions);

let (data_flow, vars) = zenoh_flow_commons::try_load_from_file::<DataFlowDescriptor>(
cli.flow.as_os_str(),
Vars::default(),
)
.context(format!(
"Failed to load data flow descriptor from < {} >",
&cli.flow.display()
))
.unwrap();
let vars = match cli.vars {
Some(v) => Vars::from(v),
None => Vars::default(),
};

let (data_flow, vars) =
zenoh_flow_commons::try_load_from_file::<DataFlowDescriptor>(cli.flow.as_os_str(), vars)
.context(format!(
"Failed to load data flow descriptor from < {} >",
&cli.flow.display()
))
.unwrap();

let flattened_flow = FlattenedDataFlowDescriptor::try_flatten(data_flow, vars)
.context(format!(
Expand Down

0 comments on commit 276e45d

Please sign in to comment.