feat(rust): node launch_config optional `JSON` string
Adds the ability for `ockam node create --launch_config <path>` to
optionally take a JSON string instead of a filepath.
@@ -6,7 +6,7 @@ use rand::prelude::random;
use anyhow::{anyhow, Context as _};
use std::{
net::{IpAddr, SocketAddr},
- path::{Path, PathBuf},
+ path::PathBuf,
str::FromStr,
};
use tracing::error;
@@ -81,8 +81,8 @@ pub struct CreateCommand {
/// This argument is currently ignored on background nodes. Node
/// configuration is run asynchronously and may take several
/// seconds to complete.
- #[arg(long, hide = true)]
- pub launch_config: Option<PathBuf>,
+ #[arg(long, hide = true, value_parser=parse_launch_config)]
+ pub launch_config: Option<Config>,
#[arg(long, hide = true)]
pub project: Option<PathBuf>,
@@ -140,6 +140,16 @@ impl CreateCommand {
}
}
+fn parse_launch_config(config_or_path: &str) -> anyhow::Result<Config> {
+ match serde_json::from_str::<Config>(config_or_path) {
+ Ok(c) => Ok(c),
+ Err(_) => {
+ let path = PathBuf::from_str(config_or_path).context(anyhow!("Not a valid path"))?;
+ Config::read(path)
+ }
+ }
+}
+
async fn run_impl(
ctx: Context,
(opts, cmd): (CommandGlobalOpts, CreateCommand),
@@ -281,15 +291,14 @@ async fn run_foreground_node(
async fn start_services(
ctx: &Context,
tcp: &TcpTransport,
- cfg: &Path,
+ cfg: &Config,
addr: SocketAddr,
node_opts: super::NodeOpts,
opts: &CommandGlobalOpts,
) -> anyhow::Result<()> {
let config = {
- let c = Config::read(cfg)?;
- if let Some(sc) = c.startup_services {
- sc
+ if let Some(sc) = &cfg.startup_services {
+ sc.clone()
} else {
return Ok(());
}
