Skip to content

Commit 38d4de8

Browse files
vmagrometa-codesync[bot]
authored andcommitted
[antlir][json_arg] allow '-' as alias for stdin
Summary: Title Test Plan: It's not really possible to replace `stdin` in a `rust_unittest`, so the rest of this stack working has to be proof enough Reviewed By: elibus Differential Revision: D90352731 fbshipit-source-id: e72c2f47882c1350ec2405250a35742b28d98291
1 parent db5f0f3 commit 38d4de8

File tree

1 file changed

+7
-1
lines changed
  • antlir/util/cli/json_arg/src

1 file changed

+7
-1
lines changed

antlir/util/cli/json_arg/src/lib.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::fmt::Debug;
1717
use std::fmt::Display;
1818
use std::hash::Hash;
1919
use std::hash::Hasher;
20+
use std::io::BufReader;
2021
use std::io::Cursor;
2122
use std::io::Read;
2223
use std::marker::PhantomData;
@@ -168,7 +169,12 @@ where
168169
type Err = std::io::Error;
169170

170171
fn from_str(path: &str) -> std::io::Result<Self> {
171-
let f = std::io::BufReader::new(std::fs::File::open(path)?);
172+
let f: Box<dyn std::io::Read> = if path == "-" {
173+
Box::new(std::io::stdin())
174+
} else {
175+
Box::new(std::fs::File::open(path)?)
176+
};
177+
let f = BufReader::new(f);
172178
D::deserialize(f)
173179
.map(|value| Self {
174180
path: path.into(),

0 commit comments

Comments
 (0)