#![cfg(feature = "native")]
use crate::experiment;
#[derive(Debug, Clone, clap::Subcommand)]
pub enum ExperimentCommand {
Tree {
#[arg(long)]
framework: Option<String>,
#[arg(long)]
integration: bool,
#[arg(long, default_value = "ascii")]
format: String,
},
}
pub fn cmd_experiment(command: ExperimentCommand) -> anyhow::Result<()> {
match command {
ExperimentCommand::Tree { framework, integration, format } => {
cmd_experiment_tree(framework.as_deref(), integration, &format)?;
}
}
Ok(())
}
fn cmd_experiment_tree(
framework: Option<&str>,
integration: bool,
format: &str,
) -> anyhow::Result<()> {
use experiment::tree::{
build_dvc_tree, build_integration_mappings, build_mlflow_tree, build_neptune_tree,
build_wandb_tree, format_all_frameworks, format_framework_tree,
format_integration_mappings,
};
if integration {
let output = match format {
"json" => {
let mappings = build_integration_mappings();
serde_json::to_string_pretty(&mappings)?
}
_ => format_integration_mappings(),
};
println!("{}", output);
} else if let Some(framework_name) = framework {
let fw = framework_name.to_lowercase();
let tree = match fw.as_str() {
"mlflow" => build_mlflow_tree(),
"wandb" => build_wandb_tree(),
"neptune" => build_neptune_tree(),
"dvc" => build_dvc_tree(),
_ => {
anyhow::bail!(
"Unknown framework: {}. Valid options: mlflow, wandb, neptune, dvc",
framework_name
);
}
};
let output = match format {
"json" => serde_json::to_string_pretty(&tree)?,
_ => format_framework_tree(&tree),
};
println!("{}", output);
} else {
let output = match format {
"json" => {
let trees = vec![
build_mlflow_tree(),
build_wandb_tree(),
build_neptune_tree(),
build_dvc_tree(),
];
serde_json::to_string_pretty(&trees)?
}
_ => format_all_frameworks(),
};
println!("{}", output);
}
Ok(())
}