Skip to content

Commit

Permalink
feat: smdk build command
Browse files Browse the repository at this point in the history
  • Loading branch information
EstebanBorai committed Sep 29, 2022
1 parent da468b1 commit b4aab00
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
41 changes: 41 additions & 0 deletions crates/fluvio-cli/src/client/smdk/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::fmt::Debug;
use std::process::Command;
use std::sync::Arc;

use async_trait::async_trait;
use fluvio_extension_common::Terminal;
use clap::Parser;
use fluvio::Fluvio;

use crate::Result;
use crate::client::cmd::ClientCmd;

/// Builds the SmartModule in the current working directory into a WASM file
#[derive(Debug, Parser)]
pub struct BuildSmartModuleOpt;

#[async_trait]
impl ClientCmd for BuildSmartModuleOpt {
async fn process_client<O: Terminal + Debug + Send + Sync>(
self,
_out: Arc<O>,
_fluvio: &Fluvio,
) -> Result<()> {
let mut cmd = Command::new("cargo");
let cwd = std::env::current_dir()?;

cmd.current_dir(cwd)
.arg("build")
.arg("--release")
.arg("--lib");
cmd.arg("--target").arg("wasm32-unknown-unknown");

let status = cmd.status()?;

if status.success() {
return Ok(());
}

panic!("An error ocurred running \"cargo run\"!");
}
}
6 changes: 6 additions & 0 deletions crates/fluvio-cli/src/client/smdk/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod build;
mod new;

pub use cmd::SmdkCmd;
Expand All @@ -16,10 +17,12 @@ mod cmd {
use crate::client::cmd::ClientCmd;
use crate::common::output::Terminal;

use super::build::BuildSmartModuleOpt;
use super::new::NewSmartModuleOpt;

#[derive(Debug, Parser)]
pub enum SmdkCmd {
Build(BuildSmartModuleOpt),
New(NewSmartModuleOpt),
}

Expand All @@ -31,6 +34,9 @@ mod cmd {
target: ClusterTarget,
) -> Result<()> {
match self {
Self::Build(opt) => {
opt.process(out, target).await?;
}
Self::New(opt) => {
opt.process(out, target).await?;
}
Expand Down

0 comments on commit b4aab00

Please sign in to comment.