use anyhow::Result;
use clap::{Parser, Subcommand};
use nvy::config::run_config;
use nvy::nvy_config::TARGET_SHELL;
use nvy::init::run_init;
use nvy::profiles::{run_profiles, run_profiles_remove, run_profiles_set};
use nvy::target::{run_target, run_target_set};
use nvy::r#use::run_use;
#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
#[clap(alias = "i")]
Init,
#[clap(alias = "u")]
Use {
#[arg(num_args = 1..)]
#[arg(default_values_t = vec!["default".to_string()])]
profiles: Vec<String>,
},
#[clap(alias = "c")]
Config,
#[clap(alias = "t")]
Target {
#[command(subcommand)]
command: Option<TargetCommands>,
},
#[clap(alias = "p")]
Profiles {
#[command(subcommand)]
command: Option<ProfileCommands>,
},
}
#[derive(Subcommand)]
enum TargetCommands {
Set {
#[arg(default_value = TARGET_SHELL)]
file: String,
},
}
#[derive(Subcommand)]
enum ProfileCommands {
Set {
profile: String,
file: String,
},
Remove {
profile: String,
},
}
fn main() -> Result<()> {
let cli = Cli::parse();
match &cli.command {
Commands::Init => {
run_init()?;
},
Commands::Use { profiles } => {
run_use(profiles)?;
},
Commands::Config => {
run_config()?;
},
Commands::Target { command } => {
match command {
Some(TargetCommands::Set { file }) => {
run_target_set(file)?;
},
None => {
run_target()?;
}
}
},
Commands::Profiles { command } => {
match command {
None => {
run_profiles()?;
}
Some(ProfileCommands::Set { profile, file }) => {
run_profiles_set(profile, file)?;
},
Some(ProfileCommands::Remove { profile }) => {
run_profiles_remove(profile)?;
},
}
}
}
Ok(())
}