mirror of
https://github.com/mii443/wasmer.git
synced 2025-12-10 22:58:18 +00:00
Move the cli into it’s own library
This commit is contained in:
31
lib/cli/src/commands/validate.rs
Normal file
31
lib/cli/src/commands/validate.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use crate::store::StoreOptions;
|
||||
use anyhow::{Context, Result};
|
||||
use std::path::PathBuf;
|
||||
use structopt::StructOpt;
|
||||
use wasmer::*;
|
||||
|
||||
#[derive(Debug, StructOpt)]
|
||||
/// The options for the `wasmer validate` subcommand
|
||||
pub struct Validate {
|
||||
/// File to validate as WebAssembly
|
||||
#[structopt(name = "FILE", parse(from_os_str))]
|
||||
path: PathBuf,
|
||||
|
||||
#[structopt(flatten)]
|
||||
store: StoreOptions,
|
||||
}
|
||||
|
||||
impl Validate {
|
||||
/// Runs logic for the `validate` subcommand
|
||||
pub fn execute(&self) -> Result<()> {
|
||||
self.inner_execute()
|
||||
.context(format!("failed to validate `{}`", self.path.display()))
|
||||
}
|
||||
fn inner_execute(&self) -> Result<()> {
|
||||
let (store, _engine_type, _compiler_type) = self.store.get_store()?;
|
||||
let module_contents = std::fs::read(&self.path)?;
|
||||
Module::validate(&store, &module_contents)?;
|
||||
eprintln!("Validation passed for `{}`.", self.path.display());
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user