Merge pull request #364 from hannobraun/config

Make configuration optional
This commit is contained in:
Hanno Braun 2022-03-16 15:31:20 +01:00 committed by GitHub
commit 1aa0981a73
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -9,8 +9,8 @@ use serde::Deserialize;
#[derive(Debug, Deserialize)]
pub struct Config {
pub default_path: PathBuf,
pub default_model: PathBuf,
pub default_path: Option<PathBuf>,
pub default_model: Option<PathBuf>,
}
impl Config {

View File

@ -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,8 +55,18 @@ fn main() -> anyhow::Result<()> {
let args = Args::parse();
let config = Config::load()?;
let mut path = config.default_path;
path.push(args.model.unwrap_or(config.default_model));
let mut path = config.default_path.unwrap_or_else(|| PathBuf::from(""));
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)?;