mod api_key;
mod commands;
use anyhow::{Context, Result};
use clap::{Parser, Subcommand};
use oxyde_cloud_common::config::CloudConfig;
use std::path::PathBuf;
#[derive(Parser)]
#[command(version, about, long_about = None)]
struct Args {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand)]
enum Commands {
Login,
Logout,
Init {
#[arg(short, long)]
name: Option<String>,
#[arg(short, long)]
team_slug: Option<String>,
#[arg(short, long, value_name = "FILE", default_value = "oxyde-cloud.toml")]
config: PathBuf,
},
#[cfg(feature = "with-deploy-test")]
Deploy {
#[arg(short, long, value_name = "FILE", default_value = "oxyde-cloud.toml")]
config: PathBuf,
},
DeployConfig,
Log {
#[arg(short, long)]
name: Option<String>,
#[arg(short, long, value_name = "FILE", default_value = "oxyde-cloud.toml")]
config: PathBuf,
},
}
#[tokio::main]
async fn main() -> Result<()> {
let args = Args::parse();
simple_logger::init_with_level(log::Level::Info).unwrap();
match args.command {
Commands::Login => {
commands::login::login().await.context("Login failed")?;
}
Commands::Logout => {
commands::logout::logout().context("Logout failed")?;
}
Commands::Init {
name,
team_slug,
config,
} => {
commands::init::init(name, team_slug, config)
.await
.context("Init failed")?;
}
#[cfg(feature = "with-deploy-test")]
Commands::Deploy { config } => {
commands::deploy::deploy(config)
.await
.context("Deploy failed")?;
}
Commands::DeployConfig => {
commands::deploy_config::init_deploy_config().context("Deploy config failed")?;
}
Commands::Log { name, config } => {
let config = CloudConfig::load(&config).await.ok();
let name = if let Some(name) = name {
name
} else if let Some(config) = config {
config.app.slug
} else {
anyhow::bail!(
"If you don't execute this command in a folder with a config you have to provide an app name!"
);
};
commands::log::log(&name)
.await
.context("Log command failed")?;
}
}
Ok(())
}