@@ -159,6 +159,7 @@ impl Args {
159
159
} ;
160
160
Ok ( ser)
161
161
}
162
+
162
163
fn read_toml ( & mut self ) -> Result < Vec < u8 > > {
163
164
use toml:: Table ;
164
165
let mut buf = String :: new ( ) ;
@@ -180,15 +181,14 @@ impl Args {
180
181
let doc_as: serde_json:: Value = doc. try_into ( ) ?;
181
182
Ok ( serde_json:: to_vec ( & doc_as) ?)
182
183
}
184
+
183
185
fn read_json ( & mut self ) -> Result < Vec < u8 > > {
184
186
let json_value: serde_json:: Value = if let Some ( f) = & self . file {
185
187
if !std:: path:: Path :: new ( & f) . exists ( ) {
186
188
Self :: try_parse_from ( [ "cmd" , "-h" ] ) ?;
187
189
std:: process:: exit ( 2 ) ;
188
190
}
189
191
let file = std:: fs:: File :: open ( f) ?;
190
- // NB: can do everything async (via tokio + tokio_util) except this:
191
- // serde only has a sync reader interface, so may as well do all sync.
192
192
serde_json:: from_reader ( BufReader :: new ( file) ) ?
193
193
} else if !stdin ( ) . is_terminal ( ) && !cfg ! ( test) {
194
194
debug ! ( "reading from stdin" ) ;
@@ -197,11 +197,9 @@ impl Args {
197
197
Self :: try_parse_from ( [ "cmd" , "-h" ] ) ?;
198
198
std:: process:: exit ( 2 ) ;
199
199
} ;
200
-
201
- // TODO: if slurp and json value is an array...
202
-
203
200
Ok ( serde_json:: to_vec ( & json_value) ?)
204
201
}
202
+
205
203
fn read_input ( & mut self ) -> Result < Vec < u8 > > {
206
204
let ser = match self . input {
207
205
Input :: Yaml => self . read_yaml ( ) ?,
0 commit comments