changepacks_cli/
context.rs1use crate::finders::get_finders;
2use anyhow::{Context, Result};
3use changepacks_core::Config;
4use changepacks_core::ProjectFinder;
5use changepacks_utils::{find_current_git_repo, find_project_dirs, get_changepacks_config};
6use std::path::PathBuf;
7
8pub struct CommandContext {
13 pub repo_root_path: PathBuf,
15 pub config: Config,
17 pub project_finders: Vec<Box<dyn ProjectFinder>>,
19}
20
21impl CommandContext {
22 pub async fn new(remote: bool) -> Result<Self> {
25 let current_dir = std::env::current_dir()?;
26 let repo = find_current_git_repo(¤t_dir)?;
27 let repo_root_path = repo
28 .work_dir()
29 .context("Not a git working directory. Ensure you are inside a git repository.")?
30 .to_path_buf();
31 let config = get_changepacks_config(¤t_dir).await?;
32 let mut project_finders = get_finders();
33 find_project_dirs(&repo, &mut project_finders, &config, remote).await?;
34
35 Ok(Self {
36 repo_root_path,
37 config,
38 project_finders,
39 })
40 }
41
42 pub fn current_dir() -> Result<PathBuf> {
45 Ok(std::env::current_dir()?)
46 }
47}