tokenize_cli/
config.rs

1use std::path::PathBuf;
2
3use crate::cli::Cli;
4
5const DEFAULT_TARGET: &str = ".";
6const DEFAULT_OUT: &str = "llm_context.md";
7const DEFAULT_PROMPT_FILE: &str = "assets/initial_prompt.md";
8
9#[derive(Debug)]
10pub struct Config {
11    pub target_dir: PathBuf,
12    pub out_file: PathBuf,
13    pub prompt_file: PathBuf,
14}
15
16impl Default for Config {
17    fn default() -> Self {
18        Self {
19            target_dir: PathBuf::from(DEFAULT_TARGET),
20            out_file: PathBuf::from(DEFAULT_OUT),
21            prompt_file: PathBuf::from(DEFAULT_PROMPT_FILE),
22        }
23    }
24}
25
26impl Config {
27    pub fn from_cli(cli: Cli) -> Result<Self, Error> {
28        let out_file = cli.out_file.unwrap_or_else(|| PathBuf::from(DEFAULT_OUT));
29        let prompt_file = cli
30            .prompt_file
31            .unwrap_or_else(|| PathBuf::from(DEFAULT_PROMPT_FILE));
32
33        Ok(Self {
34            target_dir: cli.target_dir,
35            out_file,
36            prompt_file,
37        })
38    }
39}
40
41#[derive(Debug, thiserror::Error)]
42pub enum Error {
43    #[error("invalid path to ignore provided: {0}")]
44    IgnoreError(String),
45}