forked from katzen-cafe/iowo
chore: rename executor -> evaluator and integrate into app
This commit is contained in:
parent
de9ca81b65
commit
3c529c3a1a
16 changed files with 229 additions and 115 deletions
|
@ -4,6 +4,14 @@ use clap::{builder::BoolishValueParser, ArgAction, Parser};
|
|||
|
||||
#[derive(Parser)]
|
||||
pub(crate) struct Args {
|
||||
/// What file contains the pipeline to evaluate.
|
||||
pub source: PathBuf,
|
||||
|
||||
/// How to actually run the pipeline.
|
||||
/// Overrides the config file. Defaults to the debug evaluator.
|
||||
#[arg(short, long)]
|
||||
pub evaluator: Option<eval::Available>,
|
||||
|
||||
/// Read this config file.
|
||||
#[arg(short, long)]
|
||||
pub config_path: Option<PathBuf>,
|
||||
|
|
|
@ -5,7 +5,7 @@ use std::{
|
|||
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use super::error::ConfigError;
|
||||
use super::error::Config;
|
||||
|
||||
#[derive(Debug, Serialize, Deserialize)]
|
||||
pub struct Configs {
|
||||
|
@ -13,6 +13,7 @@ pub struct Configs {
|
|||
pub example_value: i32,
|
||||
#[serde(default)]
|
||||
pub no_startup_message: bool,
|
||||
pub evaluator: Option<eval::Available>,
|
||||
}
|
||||
|
||||
/// what the fuck serde why do i need this
|
||||
|
@ -21,9 +22,9 @@ fn default_example_value() -> i32 {
|
|||
}
|
||||
|
||||
/// Find the location of a config file and check if there is, in fact, a file
|
||||
pub(super) fn find_config_file() -> Result<PathBuf, ConfigError> {
|
||||
pub(super) fn find_config_file() -> Result<PathBuf, Config> {
|
||||
let Some(config_path) = dirs::config_dir() else {
|
||||
return Err(ConfigError::NoConfigDir);
|
||||
return Err(Config::NoConfigDir);
|
||||
};
|
||||
|
||||
let ron_path = config_path.with_file_name("config.ron");
|
||||
|
@ -34,19 +35,19 @@ pub(super) fn find_config_file() -> Result<PathBuf, ConfigError> {
|
|||
} else if Path::new(&json_path).exists() {
|
||||
Ok(json_path)
|
||||
} else {
|
||||
Err(ConfigError::NoConfigFileFound)
|
||||
Err(Config::NoConfigFileFound)
|
||||
}
|
||||
}
|
||||
|
||||
impl Configs {
|
||||
pub fn read(p: PathBuf) -> Result<Self, ConfigError> {
|
||||
pub fn read(p: PathBuf) -> Result<Self, Config> {
|
||||
match p
|
||||
.extension()
|
||||
.map(|v| v.to_str().expect("config path to be UTF-8"))
|
||||
{
|
||||
Some("ron") => Ok(serde_json::from_str(&fs::read_to_string(p)?)?),
|
||||
Some("json") => Ok(ron::from_str(&fs::read_to_string(p)?)?),
|
||||
e => Err(ConfigError::UnknownExtension(e.map(str::to_string))),
|
||||
e => Err(Config::UnknownExtension(e.map(str::to_string))),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue