From 276e45d83968ab80b3d11028518fba77c2d6f99f Mon Sep 17 00:00:00 2001 From: J-Loudet Date: Wed, 7 Feb 2024 17:54:46 +0100 Subject: [PATCH] feat(standalone-runtime): allow passing `Vars` (#176) 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 --- zenoh-flow-standalone-runtime/src/main.rs | 30 +++++++++++++++-------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/zenoh-flow-standalone-runtime/src/main.rs b/zenoh-flow-standalone-runtime/src/main.rs index 88d4abe1..b73c6da1 100644 --- a/zenoh-flow-standalone-runtime/src/main.rs +++ b/zenoh-flow-standalone-runtime/src/main.rs @@ -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::{ @@ -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, + /// 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::, verbatim_doc_comment)] + vars: Option>, } #[async_std::main] @@ -57,15 +64,18 @@ async fn main() { let loader = Loader::new(extensions); - let (data_flow, vars) = zenoh_flow_commons::try_load_from_file::( - 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::(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!(