Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions src/init.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
use anyhow::Result;
use dialoguer::{Confirm, Select};
use std::path::Path;

use crate::config::EngineKind;

pub fn handle_init(game_id: String, branch: String, engine: Option<EngineKind>) -> Result<()> {
let path = Path::new("./wavedash.toml");

if path.exists() {
let overwrite = Confirm::new()
.with_prompt("wavedash.toml already exists. Overwrite?")
.default(false)
.interact()?;

if !overwrite {
println!("Aborted.");
return Ok(());
}
}

let engine = match engine {
Some(e) => e,
None => {
let items = &["Godot", "Unity", "Custom"];
let selection = Select::new()
.with_prompt("Select engine")
.items(items)
.default(0)
.interact()?;

match selection {
0 => EngineKind::Godot,
1 => EngineKind::Unity,
2 => EngineKind::Custom,
_ => unreachable!(),
}
}
};

let engine_section = match engine {
EngineKind::Godot => "[godot]\nversion = \"4.3\"\n".to_string(),
EngineKind::Unity => "[unity]\nversion = \"6000.0\"\n".to_string(),
EngineKind::Custom => {
"[custom]\nversion = \"1.0\"\nentrypoint = \"index.html\"\n".to_string()
}
};

let content = format!(
"game_id = \"{game_id}\"\n\
branch = \"{branch}\"\n\
upload_dir = \"./build\"\n\
version = \"0.0.1\"\n\
\n\
{engine_section}"
);

std::fs::write(path, &content)?;
println!("✓ Created wavedash.toml");

Ok(())
}
34 changes: 34 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod builds;
mod config;
mod dev;
mod file_staging;
mod init;
mod updater;

use anyhow::Result;
Expand All @@ -12,6 +13,23 @@ use clap::{Parser, Subcommand};
use dev::handle_dev;
use std::path::PathBuf;

#[derive(Clone, clap::ValueEnum)]
enum EngineArg {
Godot,
Unity,
Custom,
}

impl From<EngineArg> for config::EngineKind {
fn from(arg: EngineArg) -> Self {
match arg {
EngineArg::Godot => config::EngineKind::Godot,
EngineArg::Unity => config::EngineKind::Unity,
EngineArg::Custom => config::EngineKind::Custom,
}
}
}

fn mask_token(token: &str) -> String {
if token.len() > 10 {
format!("{}...{}", &token[..6], &token[token.len() - 3..])
Expand Down Expand Up @@ -51,6 +69,15 @@ enum Commands {
#[arg(long = "no-open", help = "Don't open the sandbox URL in the browser")]
no_open: bool,
},
#[command(about = "Initialize a new wavedash.toml config file")]
Init {
#[arg(long)]
game_id: String,
#[arg(long)]
branch: String,
#[arg(long, value_enum)]
engine: Option<EngineArg>,
},
#[command(about = "Check for and install updates")]
Update,
}
Expand Down Expand Up @@ -153,6 +180,13 @@ async fn main() -> Result<()> {
Commands::Dev { config, no_open } => {
handle_dev(config, cli.verbose, no_open).await?;
}
Commands::Init {
game_id,
branch,
engine,
} => {
init::handle_init(game_id, branch, engine.map(|e| e.into()))?;
}
Commands::Update => {
updater::run_update().await?;
}
Expand Down