pub mod nodes;
use crate::common::app_context::AppContext;
use crate::common::authentication::get_api_token;
use crate::common::clap_ext::ArgMatchesExt;
use crate::http_client::{MantaClient, OpenApiResultExt};
use anyhow::{Error, bail};
use clap::ArgMatches;
pub async fn handle_migrate(
cli_migrate: &ArgMatches,
ctx: &AppContext<'_>,
) -> Result<(), Error> {
let token = get_api_token(ctx).await?;
match cli_migrate.subcommand() {
Some(("nodes", m)) => {
let dry_run: bool = m.get_flag("dry-run");
let from_opt = m.opt_str("from");
let to = m.req_str("to")?;
let xnames_string = m.req_str("XNAMES")?;
let output_opt = m.opt_str("output");
let from: Vec<String> = match from_opt.or(ctx.settings_group_name_opt) {
Some(name) => vec![name.to_string()],
None => {
let client = MantaClient::from_app_ctx(ctx, Some(&token))?;
client
.openapi
.get_available_groups(client.site_name())
.await
.into_anyhow()?
}
};
let to = vec![to.to_string()];
nodes::exec(
ctx,
&token,
nodes::ExecParams {
target_groups: &to,
parent_groups: &from,
hosts_expression: xnames_string,
dry_run,
create_group: false,
output: output_opt,
},
)
.await?;
}
Some((other, _)) => bail!("Unknown 'migrate' subcommand: {other}"),
None => bail!("No 'migrate' subcommand provided"),
}
Ok(())
}