1pub mod oauth_config;
3
4pub mod app_config;
6
7pub use oauth_config::AuthConfig;
9
10use std::path::PathBuf;
11
12const CONFIG_DIR: &str = ".config";
13const APP_CONFIG_DIR: &str = "mal-cli";
14const CACHE_DIR: &str = ".cache";
15const APP_CACHE_DIR: &str = "mal-cli";
16const PICTURE_CACHE_DIR: &str = "images";
17const DATA_FILE: &str = "mal_data.json";
18
19const DEFAULT_PORT: u16 = 2006;
20const DEFAULT_USER_AGENT: &str = "mal-cli";
21const OAUTH_FILE: &str = "oauth2.yml";
22const TOKEN_CACHE_FILE: &str = ".mal_token_cache.json";
23
24const _CONFIG_FILE: &str = "config.yml";
25
26#[derive(Debug)]
27pub enum ConfigError {
28 EmptyConfig,
30 ReadError,
32 PathError,
34 ParseError(serde_yaml::Error),
36 IOError(std::io::Error),
38
39 InvalidClientIdError,
40}
41
42impl std::error::Error for ConfigError {
43 fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
44 match *self {
45 ConfigError::EmptyConfig => None,
46 ConfigError::ReadError => None,
47 ConfigError::PathError => None,
48 ConfigError::ParseError(_) => None,
49 ConfigError::IOError(_) => None,
50 ConfigError::InvalidClientIdError => None,
51 }
52 }
53}
54
55impl std::fmt::Display for ConfigError {
56 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
57 match *self {
58 ConfigError::EmptyConfig => write!(f, "Source contains no data"),
59 ConfigError::ReadError => write!(f, "Could not read file"),
60 ConfigError::PathError => write!(f, "Path not found"),
61 ConfigError::ParseError(ref err) => err.fmt(f),
62 ConfigError::IOError(ref err) => err.fmt(f),
63 ConfigError::InvalidClientIdError => write!(f, "Invalid client ID provided"),
64 }
65 }
66}
67
68impl From<std::io::Error> for ConfigError {
69 fn from(err: std::io::Error) -> Self {
70 ConfigError::IOError(err)
71 }
72}
73
74impl From<serde_yaml::Error> for ConfigError {
75 fn from(err: serde_yaml::Error) -> Self {
76 ConfigError::ParseError(err)
77 }
78}
79
80pub struct ConfigPaths {
81 pub config_file_path: PathBuf,
82 pub auth_cache_path: PathBuf,
83}