Skip to content

Commit 7680b16

Browse files
committed
jsondoclint: Parse args with clap.
1 parent b435960 commit 7680b16

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

Cargo.lock

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ checksum = "23b71c3ce99b7611011217b366d923f1d0a7e07a92bb2dbf1e84508c673ca3bd"
597597
dependencies = [
598598
"atty",
599599
"bitflags",
600-
"clap_derive",
600+
"clap_derive 3.2.18",
601601
"clap_lex 0.2.2",
602602
"indexmap",
603603
"once_cell",
@@ -614,7 +614,9 @@ checksum = "6bf8832993da70a4c6d13c581f4463c2bdda27b9bf1c5498dc4365543abe6d6f"
614614
dependencies = [
615615
"atty",
616616
"bitflags",
617+
"clap_derive 4.0.13",
617618
"clap_lex 0.3.0",
619+
"once_cell",
618620
"strsim",
619621
"termcolor",
620622
]
@@ -641,6 +643,19 @@ dependencies = [
641643
"syn",
642644
]
643645

646+
[[package]]
647+
name = "clap_derive"
648+
version = "4.0.13"
649+
source = "registry+https://github.com/rust-lang/crates.io-index"
650+
checksum = "c42f169caba89a7d512b5418b09864543eeb4d497416c917d7137863bd2076ad"
651+
dependencies = [
652+
"heck",
653+
"proc-macro-error",
654+
"proc-macro2",
655+
"quote",
656+
"syn",
657+
]
658+
644659
[[package]]
645660
name = "clap_lex"
646661
version = "0.2.2"
@@ -2097,6 +2112,7 @@ name = "jsondoclint"
20972112
version = "0.1.0"
20982113
dependencies = [
20992114
"anyhow",
2115+
"clap 4.0.15",
21002116
"fs-err",
21012117
"rustdoc-json-types",
21022118
"serde_json",

src/tools/jsondoclint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ edition = "2021"
77

88
[dependencies]
99
anyhow = "1.0.62"
10+
clap = { version = "4.0.15", features = ["derive"] }
1011
fs-err = "2.8.1"
1112
rustdoc-json-types = { version = "0.1.0", path = "../../rustdoc-json-types" }
1213
serde_json = "1.0.85"

src/tools/jsondoclint/src/main.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use std::env;
2-
3-
use anyhow::{anyhow, bail, Result};
1+
use anyhow::{bail, Result};
2+
use clap::Parser;
43
use fs_err as fs;
54
use rustdoc_json_types::{Crate, Id, FORMAT_VERSION};
65
use serde_json::Value;
@@ -21,8 +20,15 @@ enum ErrorKind {
2120
Custom(String),
2221
}
2322

23+
#[derive(Parser)]
24+
struct Cli {
25+
/// The path to the json file to be linted
26+
path: String,
27+
}
28+
2429
fn main() -> Result<()> {
25-
let path = env::args().nth(1).ok_or_else(|| anyhow!("no path given"))?;
30+
let Cli { path } = Cli::parse();
31+
2632
let contents = fs::read_to_string(&path)?;
2733
let krate: Crate = serde_json::from_str(&contents)?;
2834
assert_eq!(krate.format_version, FORMAT_VERSION);

0 commit comments

Comments
 (0)