diff --git a/src/main.rs b/src/main.rs index 5cbacb10..12c1629e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -327,9 +327,9 @@ struct Server { #[derive(Debug, Subcommand, Clone)] enum ServerCommands { /// "run" sub command. - Run(server::run::Args), + Run(Box), /// Dump the schema. - Schema(crate::server::schema::Args), + Schema(Box), } pub fn main() -> Result<(), anyhow::Error> { diff --git a/src/server/run/mod.rs b/src/server/run/mod.rs index fb197e99..959dff50 100644 --- a/src/server/run/mod.rs +++ b/src/server/run/mod.rs @@ -264,7 +264,7 @@ pub struct WithVersionSpec { /// The actual data. pub data: T, /// Version specification. - pub version_spec: pbs::common::versions::VersionSpec, + pub version_spec: Option, } impl WithVersionSpec @@ -272,12 +272,15 @@ where T: std::fmt::Debug, { /// Construct with the given data and path to specification YAML file. - pub fn from_data_and_path

(data: T, path: P) -> Result + pub fn from_data_and_path

(data: T, path: &Option

) -> Result where P: AsRef, { - let version_spec: pbs::common::versions::VersionSpec = - versions::schema::VersionSpec::from_path(path)?.into(); + let version_spec: Option = path + .as_ref() + .map(versions::schema::VersionSpec::from_path) + .transpose()? + .map(|version_spec| version_spec.into()); Ok(Self { data, version_spec }) } } @@ -483,11 +486,16 @@ pub fn run(args_common: &common::cli::Args, args: &Args) -> Result<(), anyhow::E .parent() .ok_or_else(|| anyhow::anyhow!("cannot get parent directory of path {}", path_genes))? .join("spec.yaml"); + let path_buf = path_buf.exists().then_some(path_buf); data.genes = Some( WithVersionSpec::from_data_and_path(gene_info_db, &path_buf).map_err(|e| { anyhow::anyhow!( "problem loading gene info spec from {}: {}", - path_buf.display(), + if let Some(path_buf) = path_buf.as_ref() { + format!("{}", path_buf.display()) + } else { + "None".to_string() + }, e ) })?, @@ -564,13 +572,18 @@ pub fn run(args_common: &common::cli::Args, args: &Args) -> Result<(), anyhow::E anyhow::anyhow!("cannot get parent directory of path {}", path_rocksdb) })? .join("spec.yaml"); + let spec_path = spec_path.exists().then_some(spec_path); let name = db_info.name; data.db_infos[genome_release][name] = Some(db_info); data.annos[genome_release][name] = Some( WithVersionSpec::from_data_and_path(db, &spec_path).map_err(|e| { anyhow::anyhow!( "problem loading gene info spec from {}: {}", - spec_path.display(), + if let Some(spec_path) = spec_path.as_ref() { + format!("{}", spec_path.display()) + } else { + "None".to_string() + }, e ) })?, diff --git a/src/server/run/versions.rs b/src/server/run/versions.rs index 683c02bf..751f336b 100644 --- a/src/server/run/versions.rs +++ b/src/server/run/versions.rs @@ -25,9 +25,9 @@ pub mod schema { pub version: String, } - impl Into for CreatedFrom { - fn into(self) -> pbs::common::versions::CreatedFrom { - let Self { name, version } = self; + impl From for pbs::common::versions::CreatedFrom { + fn from(val: CreatedFrom) -> Self { + let CreatedFrom { name, version } = val; pbs::common::versions::CreatedFrom { name, version } } } @@ -81,16 +81,16 @@ pub mod schema { let full_path = p.as_ref().to_str().ok_or_else(|| { anyhow::anyhow!("problem converting path to string: {:?}", p.as_ref()) })?; - let yaml_str = std::fs::read_to_string(&full_path) + let yaml_str = std::fs::read_to_string(full_path) .map_err(|e| anyhow::anyhow!("problem reading file {}: {}", &full_path, e))?; serde_yaml::from_str(&yaml_str) .map_err(|e| anyhow::anyhow!("problem deserializing {}: {}", full_path, e)) } } - impl Into for VersionSpec { - fn into(self) -> pbs::common::versions::VersionSpec { - let Self { + impl From for pbs::common::versions::VersionSpec { + fn from(val: VersionSpec) -> Self { + let VersionSpec { identifier, title, creator, @@ -102,7 +102,7 @@ pub mod schema { description, source, created_from, - } = self; + } = val; pbs::common::versions::VersionSpec { identifier, title, @@ -131,7 +131,7 @@ pub struct AnnoVersionInfo { /// Database name. pub database: AnnoDb, /// Version information of the database. - pub version_spec: VersionSpec, + pub version_spec: Option, } /// Version information for databases in a given release. @@ -177,8 +177,8 @@ async fn handle( for (anno_db, with_version) in anno_dbs { if let Some(with_version) = with_version.as_ref() { version_infos.push(AnnoVersionInfo { - database: anno_db.clone(), - version_spec: with_version.version_spec.clone().into(), + database: anno_db, + version_spec: with_version.version_spec.clone(), }); } } @@ -193,7 +193,7 @@ async fn handle( .as_ref() .genes .as_ref() - .map(|genes| genes.version_spec.clone()), + .and_then(|genes| genes.version_spec.clone()), annos, }; @@ -216,7 +216,7 @@ pub mod test { crate::common::set_snapshot_suffix!("{}", &name); let full_path = format!("tests/server/annonars/{}/spec.yaml", &name); - let spec = super::schema::VersionSpec::from_path(&full_path)?; + let spec = super::schema::VersionSpec::from_path(full_path)?; insta::assert_yaml_snapshot!(&spec); let proto_spec: crate::pbs::common::versions::VersionSpec = spec.into();