@@ -12,40 +12,27 @@ import (
12
12
13
13
"github.com/HexmosTech/gabs/v2"
14
14
"github.com/HexmosTech/lama2/lama2cmd"
15
- "github.com/rs/zerolog/log"
16
15
)
17
16
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.
18
21
func assembleCmdString (httpv string , url string , jsonObj * gabs.Container , headers * gabs.Container , multipart bool , form bool , o * lama2cmd.Opts ) ([]string , string ) {
19
22
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
-
32
23
var files * gabs.Container
33
24
if multipart {
34
25
if jsonObj .ExistsP ("@files" ) {
35
26
files = jsonObj .S ("@files" )
36
- log .Debug ().Str ("Files" , files .String ()).Msg ("" )
37
27
jsonObj .Delete ("@files" )
38
- log .Trace ().Str ("Shortened JsonObj" , jsonObj .String ()).Msg ("" )
39
28
}
40
29
}
41
30
42
31
jsonStr := ""
43
32
if jsonObj != nil && ! multipart && ! form {
44
33
dst := & bytes.Buffer {}
45
34
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 )
49
36
}
50
37
jsonStr = dst .String ()
51
38
}
@@ -58,7 +45,7 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
58
45
}*/
59
46
60
47
command = append (command , "ht " )
61
- if o .Nocolor {
48
+ if o != nil && o .Nocolor {
62
49
command = append (command , "--pretty=none " )
63
50
}
64
51
if multipart || form {
@@ -105,20 +92,20 @@ func assembleCmdString(httpv string, url string, jsonObj *gabs.Container, header
105
92
// API file inputs, figures out the type of target command
106
93
// and finally generates a string representing the generated
107
94
// 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 ( "" , " " ) )
110
97
httpv := parsedInput .S ("verb" , "value" )
111
98
url := parsedInput .S ("url" , "value" )
112
99
jsonObj := parsedInput .S ("details" , "ip_data" )
113
100
headers := parsedInput .S ("details" , "headers" )
114
101
multipart := parsedInput .S ("multipart" , "value" )
102
+ form := parsedInput .S ("form" , "value" )
115
103
multipartBool := false
116
104
if multipart != nil {
117
105
multipartBool = true
118
106
}
119
- form := parsedInput .S ("form" , "value" )
120
107
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
124
111
}
0 commit comments