mod commands;
pub mod config;
pub mod io;
pub mod rules_reporter;
pub mod state;
use anyhow::Result;
use clap::{Parser, Subcommand};
use commands::devices::DevicesListCommand;
use commands::play::PlayCommand;
use state::CliContext;
#[derive(Parser, Debug)]
#[command(name = "devalang")]
#[command(
version,
about = "🦊 Devalang – A programming language for music and sound."
)]
pub struct Cli {
#[command(subcommand)]
command: Commands,
}
#[derive(Subcommand, Debug)]
pub enum Commands {
Play(PlayCommand),
Init(commands::init::InitCommand),
Build(commands::build::BuildCommand),
Check(commands::check::CheckCommand),
Addon(commands::addon::AddonCommand),
Login {
token: Option<String>,
},
Logout,
Me,
Telemetry {
#[command(subcommand)]
action: TelemetryAction,
},
Devices {
#[command(subcommand)]
action: DevicesCommands,
},
}
#[derive(Subcommand, Debug)]
pub enum DevicesCommands {
List(DevicesListCommand),
Preview(commands::devices::DevicesLiveCommand),
Write(commands::devices::DevicesWriteCommand),
}
#[derive(Subcommand, Debug)]
pub enum TelemetryAction {
Enable,
Disable,
Status,
}
pub fn run() -> Result<()> {
let cli = Cli::parse();
let ctx = CliContext::new();
let runtime = tokio::runtime::Runtime::new()?;
runtime.block_on(async move {
match cli.command {
Commands::Play(command) => commands::play::execute(command, &ctx).await?,
Commands::Init(command) => command.execute(&ctx).await?,
Commands::Build(command) => command.execute(&ctx).await?,
Commands::Check(command) => command.execute(&ctx).await?,
Commands::Addon(command) => command.execute(&ctx).await?,
Commands::Login { token } => commands::auth::login(token).await?,
Commands::Logout => commands::auth::logout().await?,
Commands::Me => commands::auth::check_auth_status().await?,
Commands::Telemetry { action } => {
let logger = ctx.logger();
match action {
TelemetryAction::Enable => {
config::telemetry::enable_telemetry()?;
logger.success("Telemetry enabled");
logger.info("Thank you for helping us improve Devalang!");
}
TelemetryAction::Disable => {
config::telemetry::disable_telemetry()?;
logger.success("Telemetry disabled");
}
TelemetryAction::Status => {
let status = config::telemetry::get_telemetry_status();
logger.info(format!("Telemetry is currently: {}", status));
}
}
}
Commands::Devices { action } => match action {
DevicesCommands::List(cmd) => {
commands::devices::execute_list(cmd, &ctx)?;
}
DevicesCommands::Preview(cmd) => {
commands::devices::execute_preview(cmd, &ctx).await?;
}
DevicesCommands::Write(cmd) => {
commands::devices::execute_write(cmd, &ctx).await?;
}
},
}
Ok(())
})
}