jsondoclint: Parse args with clap.
This commit is contained in:
parent
b435960c4c
commit
7680b164b0
18
Cargo.lock
18
Cargo.lock
@ -597,7 +597,7 @@ checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
"clap_derive",
|
"clap_derive 3.2.18",
|
||||||
"clap_lex 0.2.2",
|
"clap_lex 0.2.2",
|
||||||
"indexmap",
|
"indexmap",
|
||||||
"once_cell",
|
"once_cell",
|
||||||
@ -614,7 +614,9 @@ checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"atty",
|
"atty",
|
||||||
"bitflags",
|
"bitflags",
|
||||||
|
"clap_derive 4.0.13",
|
||||||
"clap_lex 0.3.0",
|
"clap_lex 0.3.0",
|
||||||
|
"once_cell",
|
||||||
"strsim",
|
"strsim",
|
||||||
"termcolor",
|
"termcolor",
|
||||||
]
|
]
|
||||||
@ -641,6 +643,19 @@ dependencies = [
|
|||||||
"syn",
|
"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]]
|
[[package]]
|
||||||
name = "clap_lex"
|
name = "clap_lex"
|
||||||
version = "0.2.2"
|
version = "0.2.2"
|
||||||
@ -2097,6 +2112,7 @@ name = "jsondoclint"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
|
"clap 4.0.15",
|
||||||
"fs-err",
|
"fs-err",
|
||||||
"rustdoc-json-types",
|
"rustdoc-json-types",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
@ -7,6 +7,7 @@ edition = "2021"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0.62"
|
anyhow = "1.0.62"
|
||||||
|
clap = { version = "4.0.15", features = ["derive"] }
|
||||||
fs-err = "2.8.1"
|
fs-err = "2.8.1"
|
||||||
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
|
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
|
||||||
serde_json = "1.0.85"
|
serde_json = "1.0.85"
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
use std::env;
|
use anyhow::{bail, Result};
|
||||||
|
use clap::Parser;
|
||||||
use anyhow::{anyhow, bail, Result};
|
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
use rustdoc_json_types::{Crate, Id, FORMAT_VERSION};
|
use rustdoc_json_types::{Crate, Id, FORMAT_VERSION};
|
||||||
use serde_json::Value;
|
use serde_json::Value;
|
||||||
@ -21,8 +20,15 @@ enum ErrorKind {
|
|||||||
Custom(String),
|
Custom(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
struct Cli {
|
||||||
|
/// The path to the json file to be linted
|
||||||
|
path: String,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() -> Result<()> {
|
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 contents = fs::read_to_string(&path)?;
|
||||||
let krate: Crate = serde_json::from_str(&contents)?;
|
let krate: Crate = serde_json::from_str(&contents)?;
|
||||||
assert_eq!(krate.format_version, FORMAT_VERSION);
|
assert_eq!(krate.format_version, FORMAT_VERSION);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user