Compare commits

..

No commits in common. "d28da80b00defb23ac16d9a66194da349f2aa5a6" and "2e3c46f5cd9881178a8c835eb2e9cebfb4f2879f" have entirely different histories.

4 changed files with 2 additions and 64 deletions

View File

@ -7,8 +7,4 @@ edition = "2021"
[dependencies] [dependencies]
clap = { version = "3.1.6", features = ["derive"] } clap = { version = "3.1.6", features = ["derive"] }
config = { version = "0.13.1" } regex = { version = "*" }
serde_derive = { version = "1.0.8" }
serde = { version = "*" }
[dev-dependencies]

View File

@ -1,17 +1,12 @@
use carman::Arguments;
use clap::Parser; use clap::Parser;
/// Carman code deployment Daemon /// Carman code deployment Daemon
mod arguments;
use arguments::Arguments;
mod settings;
use settings::Settings;
fn main() { fn main() {
let args = Arguments::parse(); let args = Arguments::parse();
let config = Settings::new();
println!("Hello, world!"); println!("Hello, world!");
println!("{:?}", args); println!("{:?}", args);
println!("{:?}", config);
} }

View File

@ -1,53 +0,0 @@
use config::{Config, ConfigError, Environment, File};
use serde_derive::Deserialize;
use std::env;
#[derive(Debug, Deserialize)]
#[allow(unused)]
struct Repository {
key: String,
token: String,
url: String,
version: u8,
}
#[derive(Debug, Deserialize)]
#[allow(unused)]
pub struct Settings {
debug: bool,
log: u8,
repository: Repository,
}
impl Settings {
pub fn new() -> Result<Self, ConfigError> {
let run_mode = env::var("RUN_MODE").unwrap_or_else(|_| "development".into());
let s = Config::builder()
// Start off by merging in the "default" configuration file
.add_source(File::with_name("examples/hierarchical-env/config/default"))
// Add in the current environment file
// Default to 'development' env
// Note that this file is _optional_
.add_source(
File::with_name(&format!("examples/hierarchical-env/config/{}", run_mode))
.required(false),
)
// Add in a local configuration file
// This file shouldn't be checked in to git
.add_source(File::with_name("examples/hierarchical-env/config/local").required(false))
// Add in settings from the environment (with a prefix of APP)
// Eg.. `APP_DEBUG=1 ./target/app` would set the `debug` key
.add_source(Environment::with_prefix("carman"))
// You may also programmatically change settings
.set_override("database.url", "postgres://")?
.build()?;
// Now that we're done, let's access our configuration
println!("debug: {:?}", s.get_bool("debug"));
println!("database: {:?}", s.get::<String>("database.url"));
// You can deserialize (and thus freeze) the entire configuration as
s.try_deserialize()
}
}