1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
use crate::cli::{current_directory, binary_dir};
use serde::Deserialize;
use std::fs::read_to_string;
use strum_macros::EnumString;
use toml;
#[derive(Debug, PartialEq, EnumString)]
#[strum(ascii_case_insensitive)]
#[derive(Deserialize, Clone)]
pub enum AppType {
App,
Server,
}
#[derive(Deserialize, Clone)]
pub struct AppConfig {
}
#[derive(Deserialize, Clone)]
pub struct ServerConfig {
pub port: Option<u16>,
pub is_logging: Option<bool>,
pub show_error_pages: Option<bool>,
pub serve_static_files: Option<bool>,
pub routes_directory: Option<String>,
}
#[derive(Deserialize, Clone)]
pub struct Features {
}
#[derive(Deserialize, Clone)]
pub struct RapidConfig {
pub app_type: String,
pub app_config: Option<AppConfig>,
pub features: Option<Features>,
pub server: Option<ServerConfig>,
}
pub fn find_rapid_config() -> RapidConfig {
let dir = current_directory();
let config_file_contents = read_to_string(dir.join("rapid.toml"));
if let Err(_) = config_file_contents {
eprintln!("Could not find a valid config file in the current working directory. Please make sure you are in a project scaffolded with the Rapid CLI.");
std::process::exit(200);
}
let rapid_config: RapidConfig = toml::from_str(&config_file_contents.unwrap()).unwrap();
rapid_config
}
pub fn is_rapid() -> bool {
let dir = current_directory();
let config_file_contents = read_to_string(dir.join("rapid.toml"));
if let Err(_) = config_file_contents {
return false;
}
return true;
}