Skip to content

Commit

Permalink
feat: Add: 1.move and rename domain mod;2.update StandardEnvironment …
Browse files Browse the repository at this point in the history
…functions;3...

Signed-off-by: photowey <[email protected]>
  • Loading branch information
photowey committed Jul 14, 2024
1 parent b2568a7 commit 73c0dc5
Show file tree
Hide file tree
Showing 19 changed files with 401 additions and 135 deletions.
62 changes: 34 additions & 28 deletions crates/app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

// ----------------------------------------------------------------

use std::collections::HashSet;

use omigacore::collection::hashset::hashset_join;
use omigacore::constants::{COMMA, SIGMA_CORE_PROFILE_ACTIVES_DEFAULT};
use omigacore::model::kv::Kv;

Expand All @@ -36,15 +39,15 @@ pub struct OmigaApplication {
/// * application
/// * omiga
/// * ...
configs: Vec<String>,
configs: HashSet<String>,
/// Config file profiles active.
///
/// * dev
/// * test
/// * stage
/// * prod
/// * ...
profiles: Vec<String>,
profiles: HashSet<String>,
/// Config file format.
///
/// * toml
Expand All @@ -53,21 +56,21 @@ pub struct OmigaApplication {
/// * properties (Unsupported now)
/// * ini (Unsupported now)
/// * ...
formats: Vec<String>,
formats: HashSet<String>,
/// Application cmd args for specific configs.
///
/// * /opt/configs/omiga.yml
/// * /opt/configs/omiga-dev.yml
/// * /opt/configs/application.yml
/// * /opt/configs/application-dev.yml
/// * ...
paths: Vec<String>,
paths: HashSet<String>,
/// Search paths.
/// * .
/// * ./configs
/// * ./resources
/// * ...
search_paths: Vec<String>,
search_paths: HashSet<String>,
/// Application cmd args.
///
/// * --omiga.server.port=9320
Expand All @@ -90,11 +93,11 @@ impl OmigaApplication {
// ----------------------------------------------------------------

pub fn new(
configs: Vec<String>,
profiles: Vec<String>,
formats: Vec<String>,
paths: Vec<String>,
search_paths: Vec<String>,
configs: HashSet<String>,
profiles: HashSet<String>,
formats: HashSet<String>,
paths: HashSet<String>,
search_paths: HashSet<String>,
kv: Option<Kv>,
) -> Self {
Self {
Expand All @@ -110,20 +113,20 @@ impl OmigaApplication {
// ----------------------------------------------------------------

pub fn profiles_active(&self) -> String {
self.profiles.join(COMMA)
hashset_join(&self.profiles, COMMA)
}

pub fn profiles_active_array(&self) -> Vec<String> {
pub fn profiles_active_array(&self) -> HashSet<String> {
self.profiles.clone()
}

// ----------------------------------------------------------------

pub fn configs(&self) -> String {
self.configs.join(COMMA)
hashset_join(&self.configs, COMMA)
}

pub fn configs_array(&self) -> Vec<String> {
pub fn configs_array(&self) -> HashSet<String> {
self.configs.clone()
}

Expand All @@ -149,15 +152,15 @@ pub struct OmigaApplicationBuilder {
/// * application
/// * omiga
/// * ...
configs: Vec<String>,
configs: HashSet<String>,
/// Config file profiles active.
///
/// * dev
/// * test
/// * stage
/// * prod
/// * ...
profiles: Vec<String>,
profiles: HashSet<String>,
/// Config file format.
///
/// * toml
Expand All @@ -166,21 +169,21 @@ pub struct OmigaApplicationBuilder {
/// * properties (Unsupported now)
/// * ini (Unsupported now)
/// * ...
formats: Vec<String>,
formats: HashSet<String>,
/// Application cmd args for specific configs.
///
/// * /opt/configs/omiga.yml
/// * /opt/configs/omiga-dev.yml
/// * /opt/configs/application.yml
/// * /opt/configs/application-dev.yml
/// * ...
paths: Vec<String>,
paths: HashSet<String>,
/// Search paths.
/// * .
/// * ./configs
/// * ./resources
/// * ...
search_paths: Vec<String>,
search_paths: HashSet<String>,
/// Application cmd args.
///
/// * --omiga.server.port=9320
Expand All @@ -191,20 +194,23 @@ pub struct OmigaApplicationBuilder {

impl OmigaApplicationBuilder {
pub fn new() -> Self {
let mut default_profiles = HashSet::new();
default_profiles.insert(SIGMA_CORE_PROFILE_ACTIVES_DEFAULT.to_string());

Self {
configs: Vec::new(),
profiles: vec![SIGMA_CORE_PROFILE_ACTIVES_DEFAULT.to_string()],
formats: Vec::new(),
paths: Vec::new(),
search_paths: Vec::new(),
configs: HashSet::new(),
profiles: default_profiles,
formats: HashSet::new(),
paths: HashSet::new(),
search_paths: HashSet::new(),
kv: Some(Kv::new()),
}
}

// ----------------------------------------------------------------

pub fn config(mut self, config: String) -> Self {
self.configs.push(config);
self.configs.insert(config);

self
}
Expand All @@ -219,7 +225,7 @@ impl OmigaApplicationBuilder {

pub fn profile(mut self, profile: String) -> Self {
self.profiles.retain(|p| Self::is_not_default_profile(p));
self.profiles.push(profile);
self.profiles.insert(profile);

self
}
Expand All @@ -233,7 +239,7 @@ impl OmigaApplicationBuilder {
// ----------------------------------------------------------------

pub fn format(mut self, format: String) -> Self {
self.formats.push(format);
self.formats.insert(format);

self
}
Expand All @@ -247,7 +253,7 @@ impl OmigaApplicationBuilder {
// ----------------------------------------------------------------

pub fn search_path(mut self, search_path: String) -> Self {
self.search_paths.push(search_path);
self.search_paths.insert(search_path);

self
}
Expand Down
1 change: 1 addition & 0 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ edition = "2021"
license = "Apache-2.0"

[dependencies]
chrono = { workspace = true }
22 changes: 22 additions & 0 deletions crates/core/src/collection.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright © 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// collection

// ----------------------------------------------------------------

pub mod hashset;
pub mod table;
29 changes: 29 additions & 0 deletions crates/core/src/collection/hashset.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright © 2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

// hashset

// ----------------------------------------------------------------

use std::collections::HashSet;

// ----------------------------------------------------------------

pub fn hashset_join(set: &HashSet<String>, delimiter: &str) -> String {
let mut vec: Vec<String> = set.iter().cloned().collect();
vec.sort();
vec.join(delimiter)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

// core/domain
// collection/table

// ----------------------------------------------------------------

Expand Down
2 changes: 2 additions & 0 deletions crates/core/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use std::error::Error;
use std::fmt;

// ----------------------------------------------------------------

#[allow(dead_code)] // tmp
#[derive(Debug, PartialEq)]
pub enum OmigaError {
Expand Down
5 changes: 1 addition & 4 deletions crates/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@

// ----------------------------------------------------------------

pub mod collection;
pub mod constants;
pub mod error;

// ----------------------------------------------------------------

pub mod model;
3 changes: 1 addition & 2 deletions crates/env/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
// ------------------------------------------------------------

pub mod converter;
pub mod domain;
pub mod error;
pub mod table;
pub mod merger;
3 changes: 2 additions & 1 deletion crates/env/src/core/converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

use chrono::NaiveDateTime;

use crate::core::domain::{Array, Table, Value};
use omigacore::collection::table::{Array, Table, Value};

use crate::core::error::ConfigError;

// ----------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions crates/env/src/core/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ impl Error for ConfigError {}

#[derive(Debug, PartialEq)]
pub enum FileError {
FileNotFound(String),
InvalidPath(String),
InvalidFile(String),
ReaderNotFound(String),
Expand All @@ -62,6 +63,7 @@ pub enum FileError {
impl fmt::Display for FileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
FileError::FileNotFound(path) => write!(f, "Omiga: file not found, :[{}]", path),
FileError::InvalidPath(path) => write!(f, "Omiga: invalid path:[{}]", path),
FileError::InvalidFile(file) => write!(f, "Omiga: invalid config file type:[{}]", file),
FileError::ReaderNotFound(suffix) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use std::mem;

use crate::core::domain::{Table, Value};
use omigacore::collection::table::{Table, Value};

// ----------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion crates/env/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

use std::env;

use omigacore::collection::table::{Table, Value};
use omigacore::constants::SIGMA_CORE_PROFILE_ACTIVES_DEFAULT;

use crate::core::domain::{Table, Value};
use crate::core::error::ConfigError;
use crate::reader::ConfigReader;

Expand Down
Loading

0 comments on commit 73c0dc5

Please sign in to comment.