codegen: Opt out of documentation (#843)

* codegen: Opt-out for API documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* cli: Add `--no-docs` flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Check no documentation was generated

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* Update cargo.lock

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* tests: Adjust testing for the new codegen API

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* macro: Ensure `subxt` macro does not contain documentation

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* macro: Expose documentation flag

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>

* expose_documentation => generate_docs

---------

Signed-off-by: Alexandru Vasile <alexandru.vasile@parity.io>
Co-authored-by: James Wilson <james@jsdw.me>
This commit is contained in:
Alexandru Vasile
2023-03-02 21:35:02 +02:00
committed by GitHub
parent 1c5faf3f8f
commit 5320ca9d55
13 changed files with 244 additions and 93 deletions
+15 -1
View File
@@ -40,6 +40,11 @@ pub struct Opts {
/// Defaults to `::subxt`.
#[clap(long = "crate")]
crate_path: Option<String>,
/// Do not generate documentation for the runtime API code.
///
/// Defaults to `false` (documentation is generated).
#[clap(long, action)]
no_docs: bool,
}
fn derive_for_type_parser(src: &str) -> Result<(String, String), String> {
@@ -69,7 +74,13 @@ pub async fn run(opts: Opts) -> color_eyre::Result<()> {
subxt_codegen::utils::fetch_metadata_bytes(&url).await?
};
codegen(&bytes, opts.derives, opts.derives_for_type, opts.crate_path)?;
codegen(
&bytes,
opts.derives,
opts.derives_for_type,
opts.crate_path,
opts.no_docs,
)?;
Ok(())
}
@@ -78,6 +89,7 @@ fn codegen(
raw_derives: Vec<String>,
derives_for_type: Vec<(String, String)>,
crate_path: Option<String>,
no_docs: bool,
) -> color_eyre::Result<()> {
let item_mod = syn::parse_quote!(
pub mod api {}
@@ -100,12 +112,14 @@ fn codegen(
let type_substitutes = TypeSubstitutes::new(&crate_path);
let should_gen_docs = !no_docs;
let runtime_api = subxt_codegen::generate_runtime_api_from_bytes(
item_mod,
metadata_bytes,
derives,
type_substitutes,
crate_path,
should_gen_docs,
);
println!("{runtime_api}");
Ok(())