diff --git a/src/commands/app.rs b/src/commands/app.rs index 47924ff..533528d 100644 --- a/src/commands/app.rs +++ b/src/commands/app.rs @@ -2,7 +2,35 @@ use anyhow::{ensure, Result}; use charms::app; use std::fs; +pub fn new(name: &str) -> Result<()> { + if !std::process::Command::new("which") + .args(&["cargo-generate"]) + .status()? + .success() + { + std::process::Command::new("cargo") + .args(&["install", "cargo-generate"]) + .status()?; + } + let status = std::process::Command::new("cargo") + .args(&["generate", "sigma0-dev/charms-app", "--name", name]) + .status()?; + ensure!(status.success()); + Ok(()) +} + pub fn build() -> Result<()> { + if !std::process::Command::new("which") + .args(&["cargo-prove"]) + .status()? + .success() + { + std::process::Command::new("bash") + .args(&["-c", "curl -L https://sp1.succinct.xyz | bash"]) + .status()?; + std::process::Command::new(format!("{}/.sp1/bin/sp1up", std::env::var("HOME")?)) + .status()?; + } let mut child = std::process::Command::new("cargo") .args(&["prove", "build"]) .stdout(std::process::Stdio::piped()) diff --git a/src/commands/mod.rs b/src/commands/mod.rs index 41c4424..143ec04 100644 --- a/src/commands/mod.rs +++ b/src/commands/mod.rs @@ -82,6 +82,13 @@ pub enum TxCommands { #[derive(Subcommand)] pub enum AppCommands { + /// Create a new app + New { + /// Name of the app. Directory will be created. + name: String, + }, + + /// Build the app Build, /// Show verification key for an app @@ -90,5 +97,6 @@ pub enum AppCommands { path: Option, }, + /// Generate the app proof for a spell. Prove, } diff --git a/src/main.rs b/src/main.rs index a3eae7e..3a3138e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,10 +20,9 @@ fn main() -> Result<()> { TxCommands::ShowSpell { tx } => tx::tx_show_spell(tx), }, Commands::App { command } => match command { + AppCommands::New { name } => app::new(&name), AppCommands::Vk { path } => app::vk(path), - AppCommands::Build => { - todo!() - } + AppCommands::Build => app::build(), AppCommands::Prove => { todo!() }