Metadata difference command (#1015)

* diffing pallets and runtime apis

* print diff

* clippy fix and format

* change formatting

* fmt

* diff working with storage details

* fix diff

* cargo fmt

* remove printing of node

* change strings

* handle parsing differently

* clippy fix

* cargo fmt

* more abstraction

* clippy fix and fmt

* add unit test and ordering

* fix small issue
This commit is contained in:
Tadeo Hepperle
2023-06-21 14:33:21 +02:00
committed by GitHub
parent b4eb406ee5
commit 2a990edaca
9 changed files with 541 additions and 23 deletions
+26 -1
View File
@@ -5,14 +5,16 @@
use clap::Args;
use color_eyre::eyre;
use std::str::FromStr;
use std::{fs, io::Read, path::PathBuf};
use subxt_codegen::utils::{MetadataVersion, Uri};
pub mod type_description;
pub mod type_example;
/// The source of the metadata.
#[derive(Debug, Args)]
#[derive(Debug, Args, Clone)]
pub struct FileOrUrl {
/// The url of the substrate node to query for metadata for codegen.
#[clap(long, value_parser)]
@@ -94,3 +96,26 @@ pub fn with_indent(s: String, indent: usize) -> String {
.collect::<Vec<_>>()
.join("\n")
}
impl FromStr for FileOrUrl {
type Err = &'static str;
fn from_str(s: &str) -> Result<Self, Self::Err> {
let path = std::path::Path::new(s);
if path.exists() {
Ok(FileOrUrl {
url: None,
file: Some(PathBuf::from(s)),
version: None,
})
} else {
Uri::from_str(s)
.map_err(|_| "no path or uri could be crated")
.map(|uri| FileOrUrl {
url: Some(uri),
file: None,
version: None,
})
}
}
}