@@ -12,40 +12,27 @@ import (
1212
1313 "github.com/HexmosTech/gabs/v2"
1414 "github.com/HexmosTech/lama2/lama2cmd"
15- "github.com/rs/zerolog/log"
1615)
1716
17+ // The assembleCmdString function constructs a httpie
18+ // command string for an HTTP request based on the provided
19+ // HTTP method, URL, JSON object, headers, and options. It also
20+ // handle multipart and form data.
1821func assembleCmdString (httpv string , url string , jsonObj * gabs.Container , headers * gabs.Container , multipart bool , form bool , o * lama2cmd.Opts ) ([]string , string ) {
1922 command := make ([]string , 0 )
20- log .Info ().
21- Str ("Type" , "Construct Command" ).
22- Str ("httpv" , httpv ).
23- Str ("url" , url ).
24- Bool ("multipart" , multipart ).
25- Bool ("form" , form ).
26- Msg (fmt .Sprint ("Construct parameters" ))
27-
28- log .Debug ().
29- Str ("JSONObj" , jsonObj .String ()).
30- Str ("Headers" , headers .String ()).Msg ("" )
31-
3223 var files * gabs.Container
3324 if multipart {
3425 if jsonObj .ExistsP ("@files" ) {
3526 files = jsonObj .S ("@files" )
36- log .Debug ().Str ("Files" , files .String ()).Msg ("" )
3727 jsonObj .Delete ("@files" )
38- log .Trace ().Str ("Shortened JsonObj" , jsonObj .String ()).Msg ("" )
3928 }
4029 }
4130
4231 jsonStr := ""
4332 if jsonObj != nil && ! multipart && ! form {
4433 dst := & bytes.Buffer {}
4534 if err := json .Compact (dst , []byte (jsonObj .String ())); err != nil {
46- log .Fatal ().
47- Str ("Error" , err .Error ()).
48- Msg ("Couldn't minify JSON" )
35+ fmt .Println (err )
4936 }
5037 jsonStr = dst .String ()
5138 }
@@ -58,7 +45,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
5845 }*/
5946
6047 command = append (command , "ht " )
61- if o .Nocolor {
48+ if o != nil && o .Nocolor {
6249 command = append (command , "--pretty=none " )
6350 }
6451 if multipart || form {
@@ -105,20 +92,20 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
10592// API file inputs, figures out the type of target command
10693// and finally generates a string representing the generated
10794// command
108- func ConstructCommand (parsedInput * gabs.Container , o * lama2cmd. Opts ) ([] string , string ) {
109- log . Info (). Str ( "ParsedInput " , parsedInput .String ()). Msg ( "" )
95+ func ConstructCommandHelper (parsedInput * gabs.Container ) ( string , string , * gabs. Container , * gabs. Container , bool , bool ) {
96+ fmt . Println ( "WW parsedInput: " , parsedInput .StringIndent ( "" , " " ) )
11097 httpv := parsedInput .S ("verb" , "value" )
11198 url := parsedInput .S ("url" , "value" )
11299 jsonObj := parsedInput .S ("details" , "ip_data" )
113100 headers := parsedInput .S ("details" , "headers" )
114101 multipart := parsedInput .S ("multipart" , "value" )
102+ form := parsedInput .S ("form" , "value" )
115103 multipartBool := false
116104 if multipart != nil {
117105 multipartBool = true
118106 }
119- form := parsedInput .S ("form" , "value" )
120107 formBool := form != nil
121-
122- res , stdinBody := assembleCmdString ( httpv . Data ().( string ) , url .Data ().(string ), jsonObj , headers , multipartBool , formBool , o )
123- return res , stdinBody
108+ fmt . Println ( "WW httpv:" , httpv . Data ().( string ))
109+ fmt . Println ( "WW url:" , url .Data ().(string ))
110+ return httpv . Data ().( string ), url . Data ().( string ), jsonObj , headers , multipartBool , formBool
124111}
0 commit comments