From a9ce688a2cac09da1f26df36ee267b9c683c7033 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:09:47 +0100 Subject: [PATCH 1/2] Make `model_path` optional --- src/config.rs | 2 +- src/main.rs | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8fecef0b0..a7d9ba4a8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,7 +9,7 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Config { - pub default_path: PathBuf, + pub default_path: Option, pub default_model: PathBuf, } diff --git a/src/main.rs b/src/main.rs index a2c8b65c8..6fb4bc701 100644 --- a/src/main.rs +++ b/src/main.rs @@ -12,6 +12,7 @@ mod window; use std::collections::HashSet; use std::ffi::OsStr; +use std::path::PathBuf; use std::{collections::HashMap, sync::mpsc, time::Instant}; use futures::executor::block_on; @@ -54,7 +55,7 @@ fn main() -> anyhow::Result<()> { let args = Args::parse(); let config = Config::load()?; - let mut path = config.default_path; + let mut path = config.default_path.unwrap_or_else(|| PathBuf::from("")); path.push(args.model.unwrap_or(config.default_model)); let model = Model::from_path(path)?; From 7a6d8e2e68526a8c84e6c8c22e4c509491225932 Mon Sep 17 00:00:00 2001 From: Hanno Braun Date: Wed, 16 Mar 2022 15:16:24 +0100 Subject: [PATCH 2/2] Make `default_model` optional --- src/config.rs | 2 +- src/main.rs | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index a7d9ba4a8..94d6e8967 100644 --- a/src/config.rs +++ b/src/config.rs @@ -10,7 +10,7 @@ use serde::Deserialize; #[derive(Debug, Deserialize)] pub struct Config { pub default_path: Option, - pub default_model: PathBuf, + pub default_model: Option, } impl Config { diff --git a/src/main.rs b/src/main.rs index 6fb4bc701..384404ae3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,17 @@ fn main() -> anyhow::Result<()> { let config = Config::load()?; let mut path = config.default_path.unwrap_or_else(|| PathBuf::from("")); - path.push(args.model.unwrap_or(config.default_model)); + match args.model.or(config.default_model) { + Some(model) => { + path.push(model); + } + None => { + anyhow::bail!( + "No model specified, and no default model configured.\n\ + Specify a model by passing `--model path/to/model`." + ); + } + } let model = Model::from_path(path)?;