File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1- use std:: str:: FromStr ;
1+ use std:: { io :: Read , str:: FromStr } ;
22
3- use anyhow:: { Error , Result } ;
3+ use anyhow:: { Context , Error , Result } ;
44use colored_json:: { Color , ColorMode , ToColoredJson } ;
55use serde:: { de:: DeserializeOwned , Serialize } ;
66
@@ -11,7 +11,16 @@ impl<T: DeserializeOwned> FromStr for JsonOf<T> {
1111 type Err = Error ;
1212
1313 fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
14- Ok ( JsonOf ( serde_json:: from_str ( s) ?) )
14+ if s == "-" {
15+ let mut stdin = std:: io:: stdin ( ) . lock ( ) ;
16+ let mut input = String :: new ( ) ;
17+ stdin
18+ . read_to_string ( & mut input)
19+ . context ( "Error reading stdin for '-' argument" ) ?;
20+ Ok ( JsonOf ( serde_json:: from_str ( & input) ?) )
21+ } else {
22+ Ok ( JsonOf ( serde_json:: from_str ( s) ?) )
23+ }
1524 }
1625}
1726
You can’t perform that action at this time.
0 commit comments