Skip to content

Commit c37f27e

Browse files
committed
feat: set routes
1 parent b42c174 commit c37f27e

1 file changed

Lines changed: 15 additions & 8 deletions

File tree

src/main.rs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,7 @@ impl Apply for Command {
127127
}
128128
}
129129
Self::Join(args) => {
130-
eprintln!(
131-
"{}",
132-
client.update_network(&args.network_id.clone(), &args.into())
133-
);
130+
eprintln!("{}", client.update_network(&args.network_id.clone(), &args.into()));
134131
}
135132
Self::Leave(args) => {
136133
client.delete_network(&args.network_id);
@@ -346,7 +343,10 @@ struct CtrlNetParams {
346343
#[clap(long)]
347344
/// Routes for the network
348345
/// Format: "target", e.g., "192.168.1.0/24"
349-
/// Currently, 'via' is not supported
346+
/// or "target,via", e.g., "172.16.0.0/16,192.168.1.2"
347+
///
348+
/// This field can be specified multiple times to add multiple routes
349+
/// When routes are specified, the existing routes will be replaced with the new ones, not appended.
350350
routes: Vec<String>,
351351

352352
#[clap(long)]
@@ -400,9 +400,16 @@ impl From<CtrlNetParams> for crate::ztapi::types::ControllerNetwork {
400400
.routes
401401
.into_iter()
402402
.map(|v| {
403-
crate::ztapi::types::ControllerNetworkRoutesItem {
404-
target: Some(v),
405-
via: None, // FIXME:
403+
if let Some((target, via)) = v.split_once(",") {
404+
crate::ztapi::types::ControllerNetworkRoutesItem {
405+
target: Some(target.to_string()),
406+
via: Some(via.to_string()),
407+
}
408+
} else {
409+
crate::ztapi::types::ControllerNetworkRoutesItem {
410+
target: Some(v),
411+
via: None,
412+
}
406413
}
407414
})
408415
.collect(),

0 commit comments

Comments
 (0)