devalang_wasm/tools/cli/
mod.rs1mod commands;
3pub mod config;
4pub mod io;
5pub mod state;
6
7use anyhow::Result;
8use clap::{Parser, Subcommand};
9use commands::devices::DevicesListCommand;
10use commands::play::PlayCommand;
11use state::CliContext;
12
13#[derive(Parser, Debug)]
14#[command(name = "devalang")]
15#[command(
16 version,
17 about = "🦊 Devalang – A programming language for music and sound."
18)]
19pub struct Cli {
20 #[command(subcommand)]
21 command: Commands,
22}
23
24#[derive(Subcommand, Debug)]
25pub enum Commands {
26 Play(PlayCommand),
28 Init(commands::init::InitCommand),
30 Build(commands::build::BuildCommand),
32 Check(commands::check::CheckCommand),
34 Addon(commands::addon::AddonCommand),
36 Login {
38 token: Option<String>,
40 },
41 Logout,
43 Me,
45 Telemetry {
47 #[command(subcommand)]
48 action: TelemetryAction,
49 },
50 Devices {
52 #[command(subcommand)]
53 action: DevicesCommands,
54 },
55}
56
57#[derive(Subcommand, Debug)]
58pub enum DevicesCommands {
59 List(DevicesListCommand),
61 Preview(commands::devices::DevicesLiveCommand),
63 Write(commands::devices::DevicesWriteCommand),
65}
66
67#[derive(Subcommand, Debug)]
68pub enum TelemetryAction {
69 Enable,
71 Disable,
73 Status,
75}
76
77pub fn run() -> Result<()> {
78 let cli = Cli::parse();
79 let ctx = CliContext::new();
80 let runtime = tokio::runtime::Runtime::new()?;
81
82 runtime.block_on(async move {
83 match cli.command {
84 Commands::Play(command) => commands::play::execute(command, &ctx).await?,
85 Commands::Init(command) => command.execute(&ctx).await?,
86 Commands::Build(command) => command.execute(&ctx).await?,
87 Commands::Check(command) => command.execute(&ctx).await?,
88 Commands::Addon(command) => command.execute(&ctx).await?,
89 Commands::Login { token } => commands::auth::login(token).await?,
90 Commands::Logout => commands::auth::logout().await?,
91 Commands::Me => commands::auth::check_auth_status().await?,
92 Commands::Telemetry { action } => {
93 let logger = ctx.logger();
94 match action {
95 TelemetryAction::Enable => {
96 config::telemetry::enable_telemetry()?;
97 logger.success("Telemetry enabled");
98 logger.info("Thank you for helping us improve Devalang!");
99 }
100 TelemetryAction::Disable => {
101 config::telemetry::disable_telemetry()?;
102 logger.success("Telemetry disabled");
103 }
104 TelemetryAction::Status => {
105 let status = config::telemetry::get_telemetry_status();
106 logger.info(format!("Telemetry is currently: {}", status));
107 }
108 }
109 }
110 Commands::Devices { action } => match action {
111 DevicesCommands::List(cmd) => {
112 commands::devices::execute_list(cmd, &ctx)?;
113 }
114 DevicesCommands::Preview(cmd) => {
115 commands::devices::execute_preview(cmd, &ctx).await?;
116 }
117 DevicesCommands::Write(cmd) => {
118 commands::devices::execute_write(cmd, &ctx).await?;
119 }
120 },
121 }
122 Ok(())
123 })
124}