-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathinspect.rs
56 lines (51 loc) · 1.54 KB
/
inspect.rs
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 crate::xdr;
use clap::{command, Parser};
use soroban_spec_tools::contract;
use std::{fmt::Debug, path::PathBuf};
use tracing::debug;
use super::SpecOutput;
use crate::commands::global::Args;
use crate::print::Print;
use crate::{config::locator, wasm};
#[derive(Parser, Debug, Clone)]
#[group(skip)]
pub struct Cmd {
#[command(flatten)]
wasm: wasm::Args,
/// Output just XDR in base64
#[arg(long, default_value = "docs")]
output: SpecOutput,
#[clap(flatten)]
locator: locator::Args,
}
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[error(transparent)]
Wasm(#[from] wasm::Error),
#[error("missing spec for {0:?}")]
MissingSpec(PathBuf),
#[error(transparent)]
Xdr(#[from] xdr::Error),
#[error(transparent)]
Spec(#[from] contract::Error),
}
impl Cmd {
pub fn run(&self, global_args: &Args) -> Result<(), Error> {
Print::new(global_args.quiet).warnln(
"`contract inspect` has been deprecated in favor of `contract info`. \
Please use `contract info` instead.",
);
let wasm = self.wasm.parse()?;
debug!("File: {}", self.wasm.wasm.to_string_lossy());
let output = match self.output {
SpecOutput::XdrBase64 => wasm
.spec_base64
.clone()
.ok_or_else(|| Error::MissingSpec(self.wasm.wasm.clone()))?,
SpecOutput::XdrBase64Array => wasm.spec_as_json_array()?,
SpecOutput::Docs => wasm.to_string(),
};
println!("{output}");
Ok(())
}
}