@@ -83,7 +83,10 @@ impl<T: CliConfig> Cli<T> {
8383 . value_name ( "JSON-FILE" )
8484 . required ( false )
8585 . value_parser ( :: clap:: value_parser!( std:: path:: PathBuf ) )
86- . help ( "Path to a file that contains the full json body." ) ,
86+ . help (
87+ "Path to a file that contains the full json body, or '-' to read from \
88+ stdin.",
89+ ) ,
8790 )
8891 . arg (
8992 :: clap:: Arg :: new ( "json-body-template" )
@@ -148,7 +151,10 @@ impl<T: CliConfig> Cli<T> {
148151 . value_name ( "JSON-FILE" )
149152 . required ( false )
150153 . value_parser ( :: clap:: value_parser!( std:: path:: PathBuf ) )
151- . help ( "Path to a file that contains the full json body." ) ,
154+ . help (
155+ "Path to a file that contains the full json body, or '-' to read from \
156+ stdin.",
157+ ) ,
152158 )
153159 . arg (
154160 :: clap:: Arg :: new ( "json-body-template" )
@@ -186,7 +192,10 @@ impl<T: CliConfig> Cli<T> {
186192 . value_name ( "JSON-FILE" )
187193 . required ( false )
188194 . value_parser ( :: clap:: value_parser!( std:: path:: PathBuf ) )
189- . help ( "Path to a file that contains the full json body." ) ,
195+ . help (
196+ "Path to a file that contains the full json body, or '-' to read from \
197+ stdin.",
198+ ) ,
190199 )
191200 . arg (
192201 :: clap:: Arg :: new ( "json-body-template" )
@@ -234,7 +243,10 @@ impl<T: CliConfig> Cli<T> {
234243 . value_name ( "JSON-FILE" )
235244 . required ( false )
236245 . value_parser ( :: clap:: value_parser!( std:: path:: PathBuf ) )
237- . help ( "Path to a file that contains the full json body." ) ,
246+ . help (
247+ "Path to a file that contains the full json body, or '-' to read from \
248+ stdin.",
249+ ) ,
238250 )
239251 . arg (
240252 :: clap:: Arg :: new ( "json-body-template" )
@@ -273,7 +285,10 @@ impl<T: CliConfig> Cli<T> {
273285 . value_name ( "JSON-FILE" )
274286 . required ( false )
275287 . value_parser ( :: clap:: value_parser!( std:: path:: PathBuf ) )
276- . help ( "Path to a file that contains the full json body." ) ,
288+ . help (
289+ "Path to a file that contains the full json body, or '-' to read from \
290+ stdin.",
291+ ) ,
277292 )
278293 . arg (
279294 :: clap:: Arg :: new ( "json-body-template" )
@@ -309,7 +324,10 @@ impl<T: CliConfig> Cli<T> {
309324 . value_name ( "JSON-FILE" )
310325 . required ( true )
311326 . value_parser ( :: clap:: value_parser!( std:: path:: PathBuf ) )
312- . help ( "Path to a file that contains the full json body." ) ,
327+ . help (
328+ "Path to a file that contains the full json body, or '-' to read from \
329+ stdin.",
330+ ) ,
313331 )
314332 . arg (
315333 :: clap:: Arg :: new ( "json-body-template" )
@@ -466,8 +484,15 @@ impl<T: CliConfig> Cli<T> {
466484 }
467485
468486 if let Some ( value) = matches. get_one :: < std:: path:: PathBuf > ( "json-body" ) {
469- let body_txt = std:: fs:: read_to_string ( value)
470- . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?;
487+ let body_txt = if value. as_os_str ( ) == "-" {
488+ let mut buf = String :: new ( ) ;
489+ std:: io:: Read :: read_to_string ( & mut std:: io:: stdin ( ) , & mut buf)
490+ . context ( "failed to read from stdin" ) ?;
491+ buf
492+ } else {
493+ std:: fs:: read_to_string ( value)
494+ . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?
495+ } ;
471496 let body_value = serde_json:: from_str :: < types:: TaskSubmit > ( & body_txt)
472497 . with_context ( || format ! ( "failed to parse {}" , value. display( ) ) ) ?;
473498 request = request. body ( body_value) ;
@@ -572,8 +597,15 @@ impl<T: CliConfig> Cli<T> {
572597 }
573598
574599 if let Some ( value) = matches. get_one :: < std:: path:: PathBuf > ( "json-body" ) {
575- let body_txt = std:: fs:: read_to_string ( value)
576- . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?;
600+ let body_txt = if value. as_os_str ( ) == "-" {
601+ let mut buf = String :: new ( ) ;
602+ std:: io:: Read :: read_to_string ( & mut std:: io:: stdin ( ) , & mut buf)
603+ . context ( "failed to read from stdin" ) ?;
604+ buf
605+ } else {
606+ std:: fs:: read_to_string ( value)
607+ . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?
608+ } ;
577609 let body_value = serde_json:: from_str :: < types:: UserCreate > ( & body_txt)
578610 . with_context ( || format ! ( "failed to parse {}" , value. display( ) ) ) ?;
579611 request = request. body ( body_value) ;
@@ -642,8 +674,15 @@ impl<T: CliConfig> Cli<T> {
642674 }
643675
644676 if let Some ( value) = matches. get_one :: < std:: path:: PathBuf > ( "json-body" ) {
645- let body_txt = std:: fs:: read_to_string ( value)
646- . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?;
677+ let body_txt = if value. as_os_str ( ) == "-" {
678+ let mut buf = String :: new ( ) ;
679+ std:: io:: Read :: read_to_string ( & mut std:: io:: stdin ( ) , & mut buf)
680+ . context ( "failed to read from stdin" ) ?;
681+ buf
682+ } else {
683+ std:: fs:: read_to_string ( value)
684+ . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?
685+ } ;
647686 let body_value = serde_json:: from_str :: < types:: WorkerBootstrap > ( & body_txt)
648687 . with_context ( || format ! ( "failed to parse {}" , value. display( ) ) ) ?;
649688 request = request. body ( body_value) ;
@@ -702,8 +741,15 @@ impl<T: CliConfig> Cli<T> {
702741 }
703742
704743 if let Some ( value) = matches. get_one :: < std:: path:: PathBuf > ( "json-body" ) {
705- let body_txt = std:: fs:: read_to_string ( value)
706- . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?;
744+ let body_txt = if value. as_os_str ( ) == "-" {
745+ let mut buf = String :: new ( ) ;
746+ std:: io:: Read :: read_to_string ( & mut std:: io:: stdin ( ) , & mut buf)
747+ . context ( "failed to read from stdin" ) ?;
748+ buf
749+ } else {
750+ std:: fs:: read_to_string ( value)
751+ . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?
752+ } ;
707753 let body_value = serde_json:: from_str :: < types:: WorkerAppendTask > ( & body_txt)
708754 . with_context ( || format ! ( "failed to parse {}" , value. display( ) ) ) ?;
709755 request = request. body ( body_value) ;
@@ -762,8 +808,15 @@ impl<T: CliConfig> Cli<T> {
762808 }
763809
764810 if let Some ( value) = matches. get_one :: < std:: path:: PathBuf > ( "json-body" ) {
765- let body_txt = std:: fs:: read_to_string ( value)
766- . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?;
811+ let body_txt = if value. as_os_str ( ) == "-" {
812+ let mut buf = String :: new ( ) ;
813+ std:: io:: Read :: read_to_string ( & mut std:: io:: stdin ( ) , & mut buf)
814+ . context ( "failed to read from stdin" ) ?;
815+ buf
816+ } else {
817+ std:: fs:: read_to_string ( value)
818+ . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?
819+ } ;
767820 let body_value = serde_json:: from_str :: < types:: WorkerCompleteTask > ( & body_txt)
768821 . with_context ( || format ! ( "failed to parse {}" , value. display( ) ) ) ?;
769822 request = request. body ( body_value) ;
@@ -802,8 +855,15 @@ impl<T: CliConfig> Cli<T> {
802855 }
803856
804857 if let Some ( value) = matches. get_one :: < std:: path:: PathBuf > ( "json-body" ) {
805- let body_txt = std:: fs:: read_to_string ( value)
806- . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?;
858+ let body_txt = if value. as_os_str ( ) == "-" {
859+ let mut buf = String :: new ( ) ;
860+ std:: io:: Read :: read_to_string ( & mut std:: io:: stdin ( ) , & mut buf)
861+ . context ( "failed to read from stdin" ) ?;
862+ buf
863+ } else {
864+ std:: fs:: read_to_string ( value)
865+ . with_context ( || format ! ( "failed to read {}" , value. display( ) ) ) ?
866+ } ;
807867 let body_value = serde_json:: from_str :: < types:: WorkerAddOutput > ( & body_txt)
808868 . with_context ( || format ! ( "failed to parse {}" , value. display( ) ) ) ?;
809869 request = request. body ( body_value) ;
0 commit comments