Skip to content

Commit b946608

Browse files
authored
Merge pull request #202 from tones111/stdin
Allow svd files to be read from stdin
2 parents fb54754 + ea95970 commit b946608

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

src/main.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ fn run() -> Result<()> {
5050
.arg(
5151
Arg::with_name("input")
5252
.help("Input SVD file")
53-
.required(true)
5453
.short("i")
5554
.takes_value(true)
5655
.value_name("FILE"),
@@ -74,10 +73,21 @@ fn run() -> Result<()> {
7473
.unwrap_or(Ok(Target::CortexM))?;
7574

7675
let xml = &mut String::new();
77-
File::open(matches.value_of("input").unwrap())
78-
.chain_err(|| "couldn't open the SVD file")?
79-
.read_to_string(xml)
80-
.chain_err(|| "couldn't read the SVD file")?;
76+
match matches.value_of("input") {
77+
Some(file) => {
78+
File::open(file)
79+
.chain_err(|| "couldn't open the SVD file")?
80+
.read_to_string(xml)
81+
.chain_err(|| "couldn't read the SVD file")?;
82+
}
83+
None => {
84+
let stdin = std::io::stdin();
85+
stdin
86+
.lock()
87+
.read_to_string(xml)
88+
.chain_err(|| "couldn't read from stdin")?;
89+
}
90+
}
8191

8292
let device = svd::parse(xml);
8393

0 commit comments

Comments
 (0)