papa 2.3.0-alpha

A cli mod manager for the Northstar launcher
use std::path::PathBuf;

use directories::ProjectDirs;
use rustyline::Editor;

use crate::api::model::Cache;

use self::config::Config;

pub mod actions;
pub mod config;
#[cfg(feature = "northstar")]
pub mod northstar;

pub(crate) mod commands;
pub(crate) mod utils;

pub struct Ctx {
    pub config: Config,
    pub dirs: ProjectDirs,
    pub rl: Editor<()>,
    pub cache: Cache,
    pub local_target: PathBuf,
    pub global_target: PathBuf,
}

impl Ctx {
    pub fn new(dirs: ProjectDirs, rl: Editor<()>) -> Self {
        utils::ensure_dirs(&dirs);
        let config = config::load_config(dirs.config_dir()).expect("Unable to load config file");
        let cache = Cache::build(dirs.cache_dir()).unwrap();
        let lt = config.mod_dir.clone();
        let gt = dirs.data_local_dir();
        Ctx {
            config,
            dirs: dirs.clone(),
            rl,
            cache,
            local_target: lt,
            global_target: gt.to_path_buf(),
        }
    }
}