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;
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 client = MantaClient::from_app_ctx(ctx, Some(&token))?;
let from: Vec<String> = match from_opt.or(ctx.settings_group_name_opt) {
Some(name) => vec![name.to_string()],
None => ctx
.session
.as_ref()
.map(|s| s.accessible_groups.clone())
.unwrap_or_default(),
};
let to = vec![to.to_string()];
nodes::exec(
&client,
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(())
}