• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

dariusbakunas / cogrs / 13486377277

23 Feb 2025 07:54PM UTC coverage: 36.597% (-0.4%) from 36.957%
13486377277

push

github

dariusbakunas
refactor: extract init code from adhoc cli to cli trait

0 of 29 new or added lines in 2 files covered. (0.0%)

95 existing lines in 4 files now uncovered.

714 of 1951 relevant lines covered (36.6%)

1.21 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/cogrs-core/src/cli.rs
1
use crate::config::manager::ConfigManager;
2
use anyhow::{anyhow, Result};
3
use cogrs_plugins::plugin_loader;
4
use cogrs_plugins::plugin_type::PluginType;
5
use std::collections::HashMap;
6
use std::fs;
7
use std::path::PathBuf;
8
use tokio::sync::Mutex;
9

10
pub trait Cli {
NEW
11
    async fn init() -> Result<()> {
×
NEW
12
        let config_manager = ConfigManager::instance();
×
NEW
13
        config_manager.lock().await.init()?;
×
NEW
14
        let (cogrs_home, _) = config_manager
×
15
            .lock()
NEW
16
            .await
×
17
            .get_config_value::<PathBuf>("COGRS_HOME")?
NEW
18
            .ok_or_else(|| anyhow!("`COGRS_HOME` is not defined in the configuration"))?;
×
19

NEW
20
        set_plugin_paths(config_manager).await?;
×
21

NEW
22
        if !cogrs_home.exists() {
×
NEW
23
            fs::create_dir_all(&cogrs_home)?;
×
24
        }
25

NEW
26
        Ok(())
×
27
    }
28
}
29

NEW
30
async fn set_plugin_paths(config_manager: &Mutex<ConfigManager>) -> Result<()> {
×
NEW
31
    let plugin_loader = plugin_loader::PluginLoader::instance();
×
NEW
32
    let mut loader = plugin_loader.lock().await;
×
33

NEW
34
    let mut plugin_paths: HashMap<PluginType, Vec<PathBuf>> = HashMap::new();
×
35

NEW
36
    let callback_plugin_paths: Vec<PathBuf> =
×
37
        get_plugin_paths(config_manager, "DEFAULT_CALLBACK_PLUGIN_PATH").await?;
NEW
38
    let connection_plugin_paths: Vec<PathBuf> =
×
39
        get_plugin_paths(config_manager, "DEFAULT_CONNECTION_PLUGIN_PATH").await?;
40

NEW
41
    plugin_paths.insert(PluginType::Callback, callback_plugin_paths);
×
NEW
42
    plugin_paths.insert(PluginType::Connection, connection_plugin_paths);
×
NEW
43
    loader.set_plugin_paths(plugin_paths);
×
44

NEW
45
    Ok(())
×
46
}
47

NEW
48
async fn get_plugin_paths(
×
49
    config_manager: &Mutex<ConfigManager>,
50
    config_key: &str,
51
) -> Result<Vec<PathBuf>> {
52
    // Retrieve the configuration value for the provided key
NEW
53
    let (config_value, _) = config_manager
×
54
        .lock()
NEW
55
        .await
×
NEW
56
        .get_config_value::<PathBuf>(config_key)?
×
NEW
57
        .ok_or_else(|| anyhow!("`{}` is not defined in the configuration", config_key))?;
×
58

59
    // Split the paths and map them into a vector of PathBuf
NEW
60
    let paths: Vec<PathBuf> = config_value
×
61
        .to_string_lossy()
62
        .split(':')
NEW
63
        .map(|path| PathBuf::from(path))
×
64
        .collect();
65

NEW
66
    Ok(paths)
×
67
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc