1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
//! command `meta`
use crate::{metadata::Metadata, result::Result};
use std::{fs, path::PathBuf};
use structopt::StructOpt;

/// Show metadata structure, read types from registry, etc.
#[derive(Debug, StructOpt)]
pub enum Action {
    /// Display the structure of the metadata.
    Display,
}

/// Show metadata structure, read types from registry, etc.
#[derive(Debug, StructOpt)]
pub struct Meta {
    /// Path of "*.meta.wasm".
    pub metadata: PathBuf,
    #[structopt(subcommand)]
    pub action: Action,
}

impl Meta {
    /// Run command meta.
    pub fn exec(&self) -> Result<()> {
        let wasm = fs::read(&self.metadata)?;
        let meta = Metadata::of(&wasm)?;

        match self.action {
            Action::Display => println!("{}", format!("{:#}", meta).replace('"', "")),
        }

        Ok(())
    }
}