#![forbid(unsafe_code)]
mod commands;
mod dev;
mod icon;
mod publish;
mod registry_security;
mod scaffold;
mod signing;
use clap::{Parser, Subcommand};
#[derive(Parser)]
#[command(name = "gtdx", version, about = "Greentic Designer Extensions CLI")]
struct Cli {
#[arg(long, env = "GREENTIC_HOME", global = true)]
home: Option<std::path::PathBuf>,
#[command(subcommand)]
command: Command,
}
#[derive(Subcommand)]
enum Command {
Validate(commands::validate::Args),
Component(commands::component::Args),
List(commands::list::Args),
Install(commands::install::Args),
Keygen(commands::keygen::Args),
Uninstall(commands::uninstall::Args),
Search(commands::search::Args),
Info(commands::info::Args),
New(commands::new::Args),
Openapi(commands::openapi::Args),
Dev(commands::dev::Args),
Publish(commands::publish::Args),
Login(commands::login::Args),
Logout(commands::login::LogoutArgs),
Registries(commands::registries::Args),
Doctor(commands::doctor::Args),
Enable(commands::enable::EnableArgs),
Disable(commands::disable::DisableArgs),
Sign(commands::sign::Args),
Verify(commands::verify::Args),
Lint(commands::lint::Args),
Outdated(commands::outdated::Args),
Update(commands::update::Args),
Yank(commands::yank::Args),
Unyank(commands::yank::UnyankArgs),
Version,
}
#[tokio::main]
async fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let cli = Cli::parse();
let home = resolve_home(cli.home)?;
match cli.command {
Command::Validate(args) => commands::validate::run(&args, &home),
Command::Component(args) => commands::component::run(args, &home).await,
Command::List(args) => commands::list::run(args, &home),
Command::Install(args) => commands::install::run(args, &home).await,
Command::Keygen(args) => commands::keygen::run(&args, &home),
Command::Uninstall(args) => commands::uninstall::run(&args, &home),
Command::Search(args) => commands::search::run(args, &home).await,
Command::Info(args) => commands::info::run(&args, &home),
Command::New(args) => commands::new::run(&args, &home),
Command::Openapi(args) => commands::openapi::run(&args),
Command::Dev(args) => commands::dev::run(args, &home).await,
Command::Publish(args) => commands::publish::run(args, &home).await,
Command::Login(args) => commands::login::run_login(&args, &home).await,
Command::Logout(args) => commands::login::run_logout(&args, &home),
Command::Registries(args) => commands::registries::run(args, &home),
Command::Doctor(args) => commands::doctor::run(args, &home).await,
Command::Enable(args) => commands::enable::run(&args, &home),
Command::Disable(args) => commands::disable::run(&args, &home),
Command::Sign(args) => commands::sign::run(&args, &home),
Command::Verify(args) => commands::verify::run(&args, &home),
Command::Lint(args) => commands::lint::run(&args, &home),
Command::Outdated(args) => commands::outdated::run(args, &home).await,
Command::Update(args) => commands::update::run(args, &home).await,
Command::Yank(args) => commands::yank::run_yank(args, &home).await,
Command::Unyank(args) => commands::yank::run_unyank(args, &home).await,
Command::Version => {
println!("gtdx {}", env!("CARGO_PKG_VERSION"));
Ok(())
}
}
}
fn resolve_home(override_path: Option<std::path::PathBuf>) -> anyhow::Result<std::path::PathBuf> {
if let Some(p) = override_path {
return Ok(p);
}
directories::BaseDirs::new()
.map(|d| d.home_dir().join(".greentic"))
.ok_or_else(|| anyhow::anyhow!("no home directory"))
}