sonalake / snmp-sim-rust

SNMP Simulator (Rust)
Apache License 2.0
23 stars 3 forks source link

Feature/cli integration #55

Open conor-sonalake opened 2 years ago

conor-sonalake commented 2 years ago

Altered main.rs to add derive api macro and clap macro, in order to prep for integrating clap.

frankhorv commented 2 years ago

Add Default derive to Settings, ApplicationSettings and DatabaseSettings

Then you will be able to create a default instance like

use snmp_sim::configuration::Settings;
let settings = Settings::default();

But to have some meaningful configuration values, you need to set serde::default for each struct fields. For example, the DatabaseSettings struct and connection_uri field could look like:

#[derive(serde::Deserialize, Clone, Default)]
/// Structure representing the database settings
pub struct DatabaseSettings {
    /// database connection URI
    #[serde(default = "default_connection_uri")]
    connection_uri: String,
    #[serde(default = "default_tests_skip_drop")]
    pub tests_skip_drop: bool,
}

fn default_connection_uri() -> String {
    "sqlite://~/.snmp-sim/snmp-sim.db".to_string()
}

You can consider the base.yaml as default values. How to serialize a structure into a yaml file https://docs.rs/serde_yaml/latest/serde_yaml/