input

package
v0.32.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2025 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadBytesFromArgsOrStdin

func ReadBytesFromArgsOrStdin(cmd *cobra.Command, args []string) ([]byte, error)

ReadBytesFromArgsOrStdin reads input from either args or stdin, returning bytes. This is identical to ReadFromArgsOrStdin but returns []byte instead of string.

Use this when you need to preserve binary data or pass data to APIs that expect []byte. Commands should use Args: cobra.MaximumNArgs(1) to enforce 0 or 1 arguments.

Example usage:

var myCmd = &cobra.Command{
    Args: cobra.MaximumNArgs(1),
    RunE: func(cmd *cobra.Command, args []string) error {
        data, err := input.ReadBytesFromArgsOrStdin(cmd, args)
        if err != nil {
            return err
        }
        // Process data...
        return nil
    },
}

func ReadFromArgsOrStdin

func ReadFromArgsOrStdin(cmd *cobra.Command, args []string) (string, error)

ReadFromArgsOrStdin reads input from either: 1. The first argument (if provided), or 2. Stdin (if no arguments)

This is the standard pattern for all DevTUI formatter/converter commands. Commands should use Args: cobra.MaximumNArgs(1) to enforce 0 or 1 arguments.

Returns string, which is suitable for text-based commands.

Example usage:

var myCmd = &cobra.Command{
    Args: cobra.MaximumNArgs(1),
    RunE: func(cmd *cobra.Command, args []string) error {
        content, err := input.ReadFromArgsOrStdin(cmd, args)
        if err != nil {
            return err
        }
        // Process content...
        return nil
    },
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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