File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,7 +91,7 @@ struct Cli {
9191 #[ command( flatten) ]
9292 auth_type : AuthType ,
9393
94- /// Add body contents.
94+ /// Add body contents (prefix with @ to read from file) .
9595 #[ arg( short = 'b' , long = "body" ) ]
9696 bodies : Vec < String > ,
9797
@@ -228,9 +228,18 @@ async fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
228228 request = request. header ( CONTENT_TYPE , "application/json" ) ;
229229 }
230230
231+ let mut bodies = vec ! [ ] ;
232+ for body in args. bodies {
233+ bodies. push ( if let Some ( file_path) = body. strip_prefix ( '@' ) {
234+ std:: fs:: read_to_string ( file_path) ?
235+ } else {
236+ body
237+ } ) ;
238+ }
239+
231240 if args. body_type . form {
232241 let mut form = reqwest:: multipart:: Form :: new ( ) ;
233- for field in & args . bodies {
242+ for field in bodies {
234243 let ( key, value) = field
235244 . split_once ( '=' )
236245 . ok_or_else ( || Error :: InvalidFormField ( field. clone ( ) ) ) ?;
@@ -239,7 +248,7 @@ async fn run() -> std::result::Result<(), Box<dyn std::error::Error>> {
239248 request = request. multipart ( form) ;
240249 } else {
241250 let mut concatenated_body = String :: new ( ) ;
242- for body in args . bodies {
251+ for body in bodies {
243252 if args. body_type . json {
244253 if let Err ( err) = serde_json5:: from_str :: < serde_json:: Value > ( & body) {
245254 return Err ( Box :: new ( Error :: InvalidJson ( err) ) ) ;
You can’t perform that action at this time.
0 commit comments