dev-workspaces 0.2.0

A dev tool to simplify working with workspace directories
Documentation
use std::path::PathBuf;

use anyhow::{Context, Result};
use clap::{Parser, Subcommand};

use dev_workspaces::*;

#[derive(Parser)]
#[command(name = "workspaces")]
#[command(bin_name = "workspaces")]
#[command(version, about, long_about = None)]
#[command(propagate_version = true)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    /// List out managed paths
    #[command(subcommand)]
    List(ListCommand),

    /// Show doctor diagnosis on managed workspaces and projects
    Doctor,

    /// Show config path
    Config {
        /// Quiet extraneous output
        #[arg(short, long)]
        quiet: bool,
    },
}

#[derive(Subcommand)]
enum ListCommand {
    /// List workspace paths
    Workspaces,

    /// List project paths
    Projects,
}

fn main() -> Result<()> {
    let config = Config::from_config_file()?;

    let workspace_paths = config.collect_workspace_paths();

    let project_paths = config.collect_project_paths();

    let cli = Cli::parse();

    match &cli.command {
        Commands::List(cmd) => {
            match &cmd {
                ListCommand::Workspaces => {
                    for p in workspace_paths.iter() {
                        let p = <PathBuf as Clone>::clone(p)
                            .into_os_string()
                            .into_string()
                            .unwrap();
                        println!("{p}");
                    }
                }
                ListCommand::Projects => {
                    for p in project_paths.iter() {
                        let p = <PathBuf as Clone>::clone(p)
                            .into_os_string()
                            .into_string()
                            .unwrap();
                        println!("{p}");
                    }
                }
            };
        }
        Commands::Doctor { .. } => {
            let diagnosis = doctor(&config).context("Tried to generate doctor diagnosis")?;
            diagnosis.print();
        }
        Commands::Config { quiet } => {
            let config_path = Config::file_path()?;
            let config_path = config_path.into_os_string().into_string().unwrap();
            if *quiet {
                println!("{config_path}");
            } else {
                println!("Workspaces config path: {config_path}");
            }
        }
    };

    Ok(())
}