input

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: May 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package input builds HTTP request bodies from CLI arguments and/or stdin.

Index

Constants

View Source
const MaxStdinBodyBytes = 16 << 20

Variables

This section is empty.

Functions

func Body

func Body(stdinReader io.Reader, stdinIsTTY bool, args []string, contentType string, bodyOpts BodyOptions) (any, error)

Body parses positional CLI args (shorthand syntax) and/or stdin into a request body. The rules are:

  1. No args, stdin is a TTY → nil body (no Content-Type sent).
  2. No args, data on stdin → parsed as shorthand/JSON/YAML and returned as a Go value so the content registry can marshal it correctly.
  3. Args only → joined with spaces (matches how the shell splits tokens) and parsed as shorthand.
  4. Stdin + args → stdin document is the base; args are applied as a shorthand patch on top.

The returned body is a Go value (map/slice/scalar) ready to be marshalled by the content registry, or nil if there is no body. stdinReader is cli.Stdin; pass strings.NewReader("") with stdinIsTTY=true in tests to simulate an empty terminal.

Types

type BodyInfo

type BodyInfo struct {
	UsedStdin bool
	UsedArgs  bool
}

BodyInfo describes which CLI input sources contributed to the returned body.

func BodyWithInfo

func BodyWithInfo(stdinReader io.Reader, stdinIsTTY bool, args []string, contentType string, bodyOpts BodyOptions) (any, BodyInfo, error)

BodyWithInfo is like Body, but also reports which input sources contributed to the returned body.

type BodyOptions

type BodyOptions struct {
	Warnf func(string, ...any)
}

BodyOptions controls request-body parsing.

Jump to

Keyboard shortcuts

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