cmd

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 25, 2023 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var RequestCmd = &cli.Command{
	Name:    "requests",
	Aliases: []string{"req"},
	Usage:   "A set of commands to work with requests",
	Subcommands: []*cli.Command{
		requestListCmd,
	},
}
View Source
var RunCmd = &cli.Command{
	Name:      "run",
	Aliases:   []string{"r"},
	Usage:     "Execute HTTP requests",
	ArgsUsage: "GROUP REQUEST",
	Flags: []cli.Flag{
		&cli.BoolFlag{Name: "silent", Aliases: []string{"s"}},
		&cli.StringSliceFlag{
			Name:    "path-param",
			Usage:   "params for path interpolation - key=value",
			Aliases: []string{"p"},
		},
	},
	Action: func(cCtx *cli.Context) error {
		group := cCtx.Args().Get(0)
		name := cCtx.Args().Get(1)
		if group == "" || name == "" {

			fmt.Fprintf(cCtx.App.Writer, "No group or request specified\n\n")
			cli.ShowSubcommandHelp(cCtx)
			return nil
		}
		err := setPathParams(cCtx)
		if err != nil {
			return err
		}

		request, err := core.FetchRequestConfigByName(group, name)
		if err != nil {
			return err
		}

		client := core.BuildClient(request.HTTPConfig)
		req, err := core.BuildHTTPRequest(request.HTTPConfig)
		if err != nil {
			log.Println("Failed to make request", err)
			return err
		}

		printRequest(cCtx, req)

		execution, err := core.PerformRequest(req, client)
		if err != nil {
			log.Println("client: could not create request:", err)
			return err
		}

		printResponse(cCtx, execution)
		if execution.Response.StatusCode >= 400 {
			return cli.Exit("", 1)
		}
		return nil
	},
}

Functions

func MockApp added in v0.0.4

func MockApp(mockData string) *cli.App

func MockData added in v0.0.4

func MockData() string

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL