feat(cli): adding online and offline nexus child cli commands
@@ -18,6 +18,8 @@ pub async fn handler(
) -> crate::Result<()> {
match matches.subcommand() {
("fault", Some(args)) => fault(ctx, args).await,
+ ("offline", Some(args)) => child_operation(ctx, args, 0).await,
+ ("online", Some(args)) => child_operation(ctx, args, 1).await,
(cmd, _) => {
Err(Status::not_found(format!("command {} does not exist", cmd)))
.context(GrpcStatus)
@@ -41,6 +43,36 @@ pub fn subcommands<'a, 'b>() -> App<'a, 'b> {
.help("uri of the child"),
);
+ let offline = SubCommand::with_name("offline")
+ .about("offline a child")
+ .arg(
+ Arg::with_name("uuid")
+ .required(true)
+ .index(1)
+ .help("uuid of the nexus"),
+ )
+ .arg(
+ Arg::with_name("uri")
+ .required(true)
+ .index(2)
+ .help("uri of the child"),
+ );
+
+ let online = SubCommand::with_name("online")
+ .about("online a child")
+ .arg(
+ Arg::with_name("uuid")
+ .required(true)
+ .index(1)
+ .help("uuid of the nexus"),
+ )
+ .arg(
+ Arg::with_name("uri")
+ .required(true)
+ .index(2)
+ .help("uri of the child"),
+ );
+
SubCommand::with_name("child")
.settings(&[
AppSettings::SubcommandRequiredElseHelp,
@@ -49,6 +81,8 @@ pub fn subcommands<'a, 'b>() -> App<'a, 'b> {
])
.about("Nexus child management")
.subcommand(fault)
+ .subcommand(offline)
+ .subcommand(online)
}
async fn fault(
@@ -94,3 +128,49 @@ async fn fault(
Ok(())
}
+
+async fn child_operation(
+ mut ctx: Context,
+ matches: &ArgMatches<'_>,
+ action: i32,
+) -> crate::Result<()> {
+ let uuid = matches
+ .value_of("uuid")
+ .ok_or_else(|| ClientError::MissingValue {
+ field: "uuid".to_string(),
+ })?
+ .to_string();
+ let uri = matches
+ .value_of("uri")
+ .ok_or_else(|| ClientError::MissingValue {
+ field: "uri".to_string(),
+ })?
+ .to_string();
+
+ let response = ctx
+ .client
+ .child_operation(rpc::ChildNexusRequest {
+ uuid: uuid.clone(),
+ uri: uri.clone(),
+ action,
+ })
+ .await
+ .context(GrpcStatus)?;
+
+ match ctx.output {
+ OutputFormat::Json => {
+ println!(
+ "{}",
+ serde_json::to_string_pretty(&response.get_ref())
+ .unwrap()
+ .to_colored_json_auto()
+ .unwrap()
+ );
+ }
+ OutputFormat::Default => {
+ println!("{}", uri);
+ }
+ };
+
+ Ok(())
+}
