use clap::{Parser, Subcommand};
use crate::{config, list, remove};
#[derive(Parser, Debug)]
#[clap(
name = "Ena-Code-Manager",
about = "Utility to manage Ena-Code profiles and configurations"
)]
#[clap(version = env!("CARGO_PKG_VERSION"), author = "Takasakiii <lucasmc2709@live.com>")]
pub struct LaunchOptions {
#[clap(subcommand)]
commands: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Profiles {
#[clap(subcommand)]
commands: Profiles,
},
Config {
#[clap(subcommand)]
configs: EnaConfigs,
},
}
#[derive(Subcommand, Debug)]
pub enum Profiles {
List,
Remove {
name: String,
},
}
#[derive(Subcommand, Debug)]
pub enum EnaConfigs {
SharedProfilesConfigs {
#[clap(subcommand)]
enable: EnableDisable,
},
UseCurrentFolder {
#[clap(subcommand)]
enable: EnableDisable,
},
VsCodePath { path: String },
DefaultProfile { profile: String },
ProfilesFolder { path: String },
}
#[derive(Subcommand, Debug)]
pub enum EnableDisable {
Enable,
Disable,
}
impl Commands {
pub fn handle(options: &LaunchOptions) {
match &options.commands {
Commands::Profiles { commands } => Profiles::handle(commands),
Commands::Config { configs } => EnaConfigs::handle(configs),
}
}
}
impl EnaConfigs {
fn handle(config: &Self) {
match &config {
Self::DefaultProfile { profile } => config::default_profile(profile),
Self::ProfilesFolder { path } => config::profiles_folder(path),
Self::SharedProfilesConfigs { enable } => config::shared_profiles_config(enable),
Self::UseCurrentFolder { enable } => config::use_current_folder(enable),
Self::VsCodePath { path } => config::vs_code_path(path),
}
}
}
impl EnableDisable {
pub fn to_bool(&self) -> bool {
matches!(self, &EnableDisable::Enable)
}
}
impl Profiles {
fn handle(options: &Profiles) {
match &options {
Profiles::List => list::list_profiles(),
Profiles::Remove { name } => remove::remove(name),
}
}
}
impl LaunchOptions {
pub fn build() -> Self {
LaunchOptions::parse()
}
}