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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
use std::path::PathBuf;
use anyhow::*;
use clitool::CliTool;
use move_idl::IDLBuilder;
#[derive(clap::Parser)]
#[clap(name = "move-idl-parse", author, version)]
pub struct IDLParseTool {
#[clap(default_value = ".")]
pub root: PathBuf,
#[clap(short, long, default_value = "./build/idls/")]
pub out_dir: PathBuf,
#[clap(short, long)]
pub with_dependencies: bool,
}
#[async_trait::async_trait]
impl CliTool<()> for IDLParseTool {
async fn execute(self) -> Result<()> {
let idl = IDLBuilder::load(&self.root)?.gen()?;
std::fs::create_dir_all(&self.out_dir)?;
let relevant_modules = if self.with_dependencies {
let mut idl_mut = idl.clone();
let mut modules = idl_mut.modules;
modules.append(&mut idl_mut.dependencies);
modules
} else {
idl.clone().modules
};
let modules_dir = &self.out_dir.join("modules");
std::fs::create_dir_all(modules_dir)?;
for (name, module_idl) in relevant_modules.iter() {
let module_idl_path = &modules_dir
.join(name.name().as_str())
.with_extension("json");
std::fs::write(module_idl_path, serde_json::to_string_pretty(&module_idl)?)?;
}
std::fs::write(
&self.out_dir.join("combined.json"),
serde_json::to_string_pretty(&idl)?,
)?;
Ok(())
}
}