93 lines
2.4 KiB
Rust
93 lines
2.4 KiB
Rust
|
|
use std::process::Command;
|
||
|
|
|
||
|
|
use clap::{Parser, Subcommand};
|
||
|
|
|
||
|
|
#[derive(Parser, Debug)]
|
||
|
|
#[command(author, version, about, long_about = None)]
|
||
|
|
struct Cli {
|
||
|
|
#[command(subcommand)]
|
||
|
|
command: Commands,
|
||
|
|
}
|
||
|
|
|
||
|
|
#[derive(Subcommand, Debug)]
|
||
|
|
enum Commands {
|
||
|
|
/// Builds the website and server, including wasm files
|
||
|
|
Build,
|
||
|
|
|
||
|
|
/// Starts the server
|
||
|
|
Run,
|
||
|
|
|
||
|
|
/// Generates new encryption keys
|
||
|
|
GenKeys {
|
||
|
|
/// How many keypairs to generate
|
||
|
|
#[arg(short, long, default_value = "100")]
|
||
|
|
number: Option<usize>,
|
||
|
|
},
|
||
|
|
|
||
|
|
/// Reads fetched messages
|
||
|
|
ReadMessages {
|
||
|
|
/// Optional source file path
|
||
|
|
#[arg(short, long)]
|
||
|
|
source: Option<String>,
|
||
|
|
|
||
|
|
/// Optional output file path
|
||
|
|
#[arg(short, long)]
|
||
|
|
out_dir: Option<String>,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
|
fn main() {
|
||
|
|
let cli = Cli::parse();
|
||
|
|
|
||
|
|
match &cli.command {
|
||
|
|
Commands::Build => {
|
||
|
|
println!("Executing build command...");
|
||
|
|
|
||
|
|
build();
|
||
|
|
}
|
||
|
|
Commands::Run => {
|
||
|
|
println!("Executing run command...");
|
||
|
|
// Add your run logic here
|
||
|
|
}
|
||
|
|
Commands::GenKeys { .. } => {
|
||
|
|
println!("Executing gen-keys command...");
|
||
|
|
// Add your key generation logic here
|
||
|
|
}
|
||
|
|
Commands::ReadMessages { source, .. } => {
|
||
|
|
println!("Executing read-messages command...");
|
||
|
|
match source {
|
||
|
|
Some(s) => println!("Reading from source: {}", s),
|
||
|
|
None => println!("Reading from default source."),
|
||
|
|
}
|
||
|
|
// Add your message reading logic here
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
fn build() {
|
||
|
|
let status = Command::new("wasm-pack")
|
||
|
|
.arg("build")
|
||
|
|
.arg("--out-dir")
|
||
|
|
.arg("../../routes/contact/pkg")
|
||
|
|
.arg("crates/message-tools")
|
||
|
|
.arg("--target")
|
||
|
|
.arg("no-modules")
|
||
|
|
.status();
|
||
|
|
|
||
|
|
match status {
|
||
|
|
Ok(exit_status) => {
|
||
|
|
if exit_status.success() {
|
||
|
|
println!("\nBuild successful!");
|
||
|
|
} else {
|
||
|
|
// Print the exit code if the build failed
|
||
|
|
eprintln!("\nBuild failed with exit code: {:?}", exit_status.code());
|
||
|
|
std::process::exit(exit_status.code().unwrap_or(1));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
Err(e) => {
|
||
|
|
eprintln!("\nFailed to execute cargo build command: {}", e);
|
||
|
|
std::process::exit(1); // Exit with an error code
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|