Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make configuration optional #364

Merged
merged 2 commits into from Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/config.rs
Expand Up @@ -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 {
Expand Down
15 changes: 13 additions & 2 deletions src/main.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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)?;

Expand Down