/
put.go
executable file
路33 lines (28 loc) 路 1.59 KB
/
put.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cli
import (
"github.com/spf13/cobra"
)
func PutCMD() *cobra.Command {
cmd := &cobra.Command{
Use: "put <url> [flags]",
Short: "Send a PUT request",
Long: `Send a PUT request to a given URL with a given body`,
RunE: func(cmd *cobra.Command, args []string) error {
if len(args) > 0 {
withBodyOpts.URL = args[0]
}
return runWithBody(&withBodyOpts, "PUT")
},
}
cmd.Flags().StringVarP(&withBodyOpts.Method.AuthType.TokenAuth, "token", "t", "", "The bearer token to use for authentication")
cmd.Flags().StringVarP(&withBodyOpts.Method.AuthType.BasicAuthUsername, "username", "u", "", "The username to use for basic authentication")
cmd.Flags().StringVarP(&withBodyOpts.Method.AuthType.BasicAuthPassword, "password", "p", "", "The password to use for basic authentication")
cmd.Flags().BoolVarP(&withBodyOpts.Method.JustShowBody, "just-body", "j", false, "Just show the response body")
cmd.Flags().BoolVarP(&withBodyOpts.Method.JustShowHeaders, "headers", "H", false, "Just show the response headers")
cmd.Flags().StringVarP(&withBodyOpts.Method.SaveFile, "save", "s", "", "Save the response to a file")
cmd.Flags().StringVarP(&withBodyOpts.Method.ContentType, "content-type", "c", "", "The content type of the body")
cmd.Flags().StringVarP(&withBodyOpts.Method.Body, "body", "b", "", "The body of the request")
cmd.Flags().BoolVarP(&withBodyOpts.Method.OpenEditor, "editor", "e", false, "Open the editor to edit the body")
cmd.Flags().BoolVarP(&withBodyOpts.Method.IsBodyStdin, "body-stdin", "i", false, "Read the body from stdin")
return cmd
}