jsondoclint: Parse args with clap.

This commit is contained in:
Nixon Enraght-Moony 2023-01-02 19:30:39 +00:00
parent b435960c4c
commit 7680b164b0
3 changed files with 28 additions and 5 deletions

View file

@ -597,7 +597,7 @@ checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd"
dependencies = [
"atty",
"bitflags",
"clap_derive",
"clap_derive 3.2.18",
"clap_lex 0.2.2",
"indexmap",
"once_cell",
@ -614,7 +614,9 @@ checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
dependencies = [
"atty",
"bitflags",
"clap_derive 4.0.13",
"clap_lex 0.3.0",
"once_cell",
"strsim",
"termcolor",
]
@ -641,6 +643,19 @@ dependencies = [
"syn",
]
[[package]]
name = "clap_derive"
version = "4.0.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.2.2"
@ -2097,6 +2112,7 @@ name = "jsondoclint"
version = "0.1.0"
dependencies = [
"anyhow",
"clap 4.0.15",
"fs-err",
"rustdoc-json-types",
"serde_json",

View file

@ -7,6 +7,7 @@ edition = "2021"
[dependencies]
anyhow = "1.0.62"
clap = { version = "4.0.15", features = ["derive"] }
fs-err = "2.8.1"
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
serde_json = "1.0.85"

View file

@ -1,6 +1,5 @@
use std::env;
use anyhow::{anyhow, bail, Result};
use anyhow::{bail, Result};
use clap::Parser;
use fs_err as fs;
use rustdoc_json_types::{Crate, Id, FORMAT_VERSION};
use serde_json::Value;
@ -21,8 +20,15 @@ enum ErrorKind {
Custom(String),
}
#[derive(Parser)]
struct Cli {
/// The path to the json file to be linted
path: String,
}
fn main() -> Result<()> {
let path = env::args().nth(1).ok_or_else(|| anyhow!("no path given"))?;
let Cli { path } = Cli::parse();
let contents = fs::read_to_string(&path)?;
let krate: Crate = serde_json::from_str(&contents)?;
assert_eq!(krate.format_version, FORMAT_VERSION);