diff --git a/cli.go b/cli.go index 3b1f4c5..2a9248d 100644 --- a/cli.go +++ b/cli.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "log" "os" @@ -128,6 +129,13 @@ func main() { }, }, } + cli.AppHelpTemplate = fmt.Sprintf(`%sS + + WE REALLY NEED YOUR FEEDBACK, + + CREATE A NEW ISSUE FOR BUGS AND FEATURE REQUESTS : + `, cli.AppHelpTemplate) + err := app.Run(os.Args) if err != nil { log.Fatal(err) diff --git a/methods/delete.go b/methods/delete.go index 142c368..db4e39f 100644 --- a/methods/delete.go +++ b/methods/delete.go @@ -29,7 +29,7 @@ func Deletebasic(c *cli.Context) { if err != nil { panic(err) } - defer resp.Body.Close() + //defer resp.Body.Close() s := formatresp(resp) fmt.Println(s) } diff --git a/methods/get.go b/methods/get.go index 7194e29..c1ab8df 100644 --- a/methods/get.go +++ b/methods/get.go @@ -29,7 +29,7 @@ func Getbasic(c *cli.Context) error { if err != nil { log.Println("Error on response.\n[ERRO] -", err) } - defer resp.Body.Close() + s := formatresp(resp) fmt.Println(s) return nil diff --git a/methods/patch.go b/methods/patch.go index d6c5af6..ba27002 100644 --- a/methods/patch.go +++ b/methods/patch.go @@ -29,7 +29,7 @@ func Patchbasic(c *cli.Context) { if err != nil { panic(err) } - defer resp.Body.Close() + //defer resp.Body.Close() s := formatresp(resp) fmt.Println(s) } diff --git a/methods/post.go b/methods/post.go index e580e24..f67c384 100644 --- a/methods/post.go +++ b/methods/post.go @@ -29,7 +29,7 @@ func Postbasic(c *cli.Context) { if err != nil { panic(err) } - defer resp.Body.Close() + //defer resp.Body.Close() s := formatresp(resp) fmt.Println(s) } diff --git a/methods/put.go b/methods/put.go index 040b72b..6783d54 100644 --- a/methods/put.go +++ b/methods/put.go @@ -29,8 +29,7 @@ func Putbasic(c *cli.Context) { if err != nil { panic(err) } - defer resp.Body.Close() - + //defer resp.Body.Close() s := formatresp(resp) fmt.Println(s) } diff --git a/methods/json.go b/methods/send.go similarity index 86% rename from methods/json.go rename to methods/send.go index 0fb855f..3f5b3b2 100644 --- a/methods/json.go +++ b/methods/send.go @@ -12,7 +12,7 @@ import ( "github.com/urfave/cli" ) -//Colls hold the format of the basic `postwoman-collection.json` +//Colls hold the structure of the basic `postwoman-collection.json` type Colls struct { Name string `json:"name"` Folders []string `json:"folders"` @@ -29,6 +29,7 @@ type Reqdata struct { Pass string `json:"httpPassword"` Token string `json:"bearerToken"` Ctype string `json:"contentType"` + Name string `json:"name"` Heads []string `json:"headers"` Params []string `json:"params"` Bparams []Bpardata `json:"bodyParams"` @@ -46,21 +47,13 @@ func ReadCollection(c *cli.Context) { if err != nil { fmt.Print(err) } - //fmt.Print(string(data)) - jsondat := []Colls{} - + var jsondat []Colls err = json.Unmarshal([]byte(data), &jsondat) if err != nil { fmt.Println(err) } + fmt.Println("Name:\t" + color.HiMagentaString(jsondat[0].Name)) for i := 0; i < len(jsondat[0].Request); i++ { - /* fmt.Printf(` - URL: %s - Method: %s - Auth: %s - Token:%s - Headers: %s - -------`, jsondat[0].Request[i].URL+jsondat[0].Request[i].Path, jsondat[0].Request[i].Method, jsondat[0].Request[i].Auth, jsondat[0].Request[i].Token, jsondat[0].Request[i].Heads) */ request(jsondat, i) } @@ -82,7 +75,7 @@ func request(c []Colls, i int) { } methods := color.HiYellowString(c[0].Request[i].Method) fURL := colors.Sprintf(c[0].Request[i].URL + c[0].Request[i].Path) - fmt.Printf("%s \t%s\t%s", fURL, methods, out) + fmt.Printf("%s |\t%s |\t%s |\t%s", color.HiGreenString(c[0].Request[i].Name), fURL, methods, out) } } @@ -107,7 +100,7 @@ func getsend(c []Colls, ind int, method string) (string, error) { if err != nil { log.Println("Error on response.\n[ERRO] -", err) } - defer resp.Body.Close() + //defer resp.Body.Close() //fmt.Print(resp.Header) s := color.Sprintf("Status: %s\tStatusCode:\t%d\n", resp.Status, resp.StatusCode) return s, nil @@ -115,9 +108,13 @@ func getsend(c []Colls, ind int, method string) (string, error) { func sendpopa(c []Colls, ind int, method string) (string, error) { color := color.New(color.FgCyan, color.Bold) - + var jsonStr []byte var url = c[0].Request[ind].URL + c[0].Request[ind].Path - var jsonStr = []byte(string(c[0].Request[ind].Bparams[0].Key[0] + c[0].Request[ind].Bparams[0].Value[0])) + if len(c[0].Request[ind].Bparams) > 0 { + jsonStr = []byte(string(c[0].Request[ind].Bparams[0].Key[0] + c[0].Request[ind].Bparams[0].Value[0])) + } else { + jsonStr = nil + } req, err := http.NewRequest(method, url, bytes.NewBuffer(jsonStr)) req.Header.Set("Content-Type", c[0].Request[ind].Ctype) @@ -138,7 +135,7 @@ func sendpopa(c []Colls, ind int, method string) (string, error) { if err != nil { log.Println("Error on response.\n[ERRO] -", err) } - defer resp.Body.Close() + //defer resp.Body.Close() //fmt.Print(resp.Header) s := color.Sprintf("Status: %s\tStatusCode:\t%d\n", resp.Status, resp.StatusCode) return s, nil