buf: github.com/bufbuild/buf/internal/pkg/app Index | Files | Directories

package app

import "github.com/bufbuild/buf/internal/pkg/app"

Package app provides application primitives.

Index

Package Files

app.go app_error.go app_unix.go arg_container.go container.go env_container.go stderr_container.go stdin_container.go stdout_container.go

Constants

const (
    // DevStdinFilePath is the equivalent of /dev/stdin.
    //
    // This will be /dev/stdin for darwin and linux.
    // This does not exist for windows.
    DevStdinFilePath = "/dev/stdin"
    // DevStdoutFilePath is the equivalent of /dev/stdout.
    //
    // This will be /dev/stdout for darwin and linux.
    // This does not exist for windows.
    DevStdoutFilePath = "/dev/stdout"
    // DevStderrFilePath is the equivalent of /dev/stderr.
    //
    // This will be /dev/stderr for darwin and linux.
    // This does not exist for windows.
    DevStderrFilePath = "/dev/stderr"
    // DevNullFilePath is the equivalent of /dev/null.
    //
    // This will be /dev/null for darwin and linux.
    // This will be nul for windows.
    DevNullFilePath = "/dev/null"
)

func Args Uses

func Args(argList ArgContainer) []string

Args returns all arguments.

Equivalent to os.Args.

func CacheDirPath Uses

func CacheDirPath(envContainer EnvContainer) (string, error)

CacheDirPath returns the cache directory path.

This will be $XDG_CACHE_HOME for darwin and linux, falling back to $HOME/.cache. This will be %LocalAppData% for windows.

Users cannot assume that CacheDirPath, ConfigDirPath, and DataDirPath are unique.

func ConfigDirPath Uses

func ConfigDirPath(envContainer EnvContainer) (string, error)

ConfigDirPath returns the config directory path.

This will be $XDG_CONFIG_HOME for darwin and linux, falling back to $HOME/.config. This will be %AppData% for windows.

Users cannot assume that CacheDirPath, ConfigDirPath, and DataDirPath are unique.

func DataDirPath Uses

func DataDirPath(envContainer EnvContainer) (string, error)

DataDirPath returns the data directory path.

This will be $XDG_DATA_HOME for darwin and linux, falling back to $HOME/.local/share. This will be %LocalAppData% for windows.

Users cannot assume that CacheDirPath, ConfigDirPath, and DataDirPath are unique.

func Environ Uses

func Environ(envContainer EnvContainer) []string

Environ returns all environment variables in the form "KEY=VALUE".

Equivalent to os.Enviorn.

Sorted.

func EnvironMap Uses

func EnvironMap(envContainer EnvContainer) map[string]string

EnvironMap returns all environment variables in a map.

No key will have an empty value.

func GetExitCode Uses

func GetExitCode(err error) int

GetExitCode gets the exit code.

If err == nil, this returns 0. If err was created by this package, this returns the exit code from the error. Otherwise, this returns 1.

func HomeDirPath Uses

func HomeDirPath(envContainer EnvContainer) (string, error)

HomeDirPath returns the home directory path.

This will be $HOME for darwin and linux. This will be %USERPROFILE% for windows.

func IsDevNull Uses

func IsDevNull(path string) bool

IsDevNull returns true if the path is the equivalent of /dev/null.

func IsDevStderr Uses

func IsDevStderr(path string) bool

IsDevStderr returns true if the path is the equivalent of /dev/stderr.

func IsDevStdin Uses

func IsDevStdin(path string) bool

IsDevStdin returns true if the path is the equivalent of /dev/stdin.

func IsDevStdout Uses

func IsDevStdout(path string) bool

IsDevStdout returns true if the path is the equivalent of /dev/stdout.

func Main Uses

func Main(ctx context.Context, f func(context.Context, Container) error)

Main runs the application using the OS Container and calling os.Exit on the return value of Run.

func NewError Uses

func NewError(exitCode int, message string) error

NewError returns a new Error that contains an exit code.

The exit code cannot be 0.

func NewErrorf Uses

func NewErrorf(exitCode int, format string, args ...interface{}) error

NewErrorf returns a new error that contains an exit code.

The exit code cannot be 0.

func Run Uses

func Run(ctx context.Context, container Container, f func(context.Context, Container) error) error

Run runs the application using the container.

The run will be stopped on interrupt signal.

type ArgContainer Uses

type ArgContainer interface {
    // NumArgs gets the number of arguments.
    NumArgs() int
    // Arg gets the ith argument.
    //
    // Panics if i < 0 || i >= Len().
    Arg(i int) string
}

ArgContainer provides the arguments.

func NewArgContainer Uses

func NewArgContainer(args ...string) ArgContainer

NewArgContainer returns a new ArgContainer.

func NewArgContainerForOS Uses

func NewArgContainerForOS() ArgContainer

NewArgContainerForOS returns a new ArgContainer for the operating system.

type Container Uses

type Container interface {
    EnvContainer
    StdinContainer
    StdoutContainer
    StderrContainer
    ArgContainer
}

Container contains environment variables, args, and stdio.

func NewContainer Uses

func NewContainer(
    env map[string]string,
    stdin io.Reader,
    stdout io.Writer,
    stderr io.Writer,
    args ...string,
) Container

NewContainer returns a new Container.

func NewContainerForArgs Uses

func NewContainerForArgs(container Container, newArgs ...string) Container

NewContainerForArgs returns a new Container with the replacement args.

func NewContainerForOS Uses

func NewContainerForOS() (Container, error)

NewContainerForOS returns a new Container for the operating system.

type EnvContainer Uses

type EnvContainer interface {
    // Env gets the environment variable value for the key.
    //
    // Returns empty string if the key is not set or the value is empty.
    Env(key string) string

    // ForEachEnv iterates over all non-empty environment variables and calls the function.
    //
    // The value will never be empty.
    ForEachEnv(func(string, string))
}

EnvContainer provides envionment variables.

func NewEnvContainer Uses

func NewEnvContainer(m map[string]string) EnvContainer

NewEnvContainer returns a new EnvContainer.

Empty values are effectively ignored.

func NewEnvContainerForOS Uses

func NewEnvContainerForOS() (EnvContainer, error)

NewEnvContainerForOS returns a new EnvContainer for the operating system.

func NewEnvContainerWithOverrides Uses

func NewEnvContainerWithOverrides(envContainer EnvContainer, overrides map[string]string) EnvContainer

NewEnvContainerWithOverrides returns a new EnvContainer with the values of the input EnvContainer, overridden by the values in overrides.

Empty values are effectively ignored. To unset a key, set the value to "" in overrides.

type EnvStderrContainer Uses

type EnvStderrContainer interface {
    EnvContainer
    StderrContainer
}

EnvStderrContainer is an environment and stderr container.

type EnvStdinContainer Uses

type EnvStdinContainer interface {
    EnvContainer
    StdinContainer
}

EnvStdinContainer is an environment and stdin container.

type EnvStdioContainer Uses

type EnvStdioContainer interface {
    EnvContainer
    StdioContainer
}

EnvStdioContainer is an environment and stdio container.

type EnvStdoutContainer Uses

type EnvStdoutContainer interface {
    EnvContainer
    StdoutContainer
}

EnvStdoutContainer is an environment and stdout container.

type StderrContainer Uses

type StderrContainer interface {
    // Stderr provides stderr.
    //
    // If no value was passed when Stdio was created, this will return io.EOF on any call.
    Stderr() io.Writer
}

StderrContainer provides stderr.

func NewStderrContainer Uses

func NewStderrContainer(writer io.Writer) StderrContainer

NewStderrContainer returns a new StderrContainer.

func NewStderrContainerForOS Uses

func NewStderrContainerForOS() StderrContainer

NewStderrContainerForOS returns a new StderrContainer for the operaterrg system.

type StdinContainer Uses

type StdinContainer interface {
    // Stdin provides stdin.
    //
    // If no value was passed when Stdio was created, this will return io.EOF on any call.
    Stdin() io.Reader
}

StdinContainer provides stdin.

func NewStdinContainer Uses

func NewStdinContainer(reader io.Reader) StdinContainer

NewStdinContainer returns a new StdinContainer.

func NewStdinContainerForOS Uses

func NewStdinContainerForOS() StdinContainer

NewStdinContainerForOS returns a new StdinContainer for the operating system.

type StdioContainer Uses

type StdioContainer interface {
    StdinContainer
    StdoutContainer
    StderrContainer
}

StdioContainer is a stdio container.

type StdoutContainer Uses

type StdoutContainer interface {
    // Stdout provides stdout.
    //
    // If no value was passed when Stdio was created, this will return io.EOF on any call.
    Stdout() io.Writer
}

StdoutContainer provides stdout.

func NewStdoutContainer Uses

func NewStdoutContainer(writer io.Writer) StdoutContainer

NewStdoutContainer returns a new StdoutContainer.

func NewStdoutContainerForOS Uses

func NewStdoutContainerForOS() StdoutContainer

NewStdoutContainerForOS returns a new StdoutContainer for the operatoutg system.

Directories

PathSynopsis
appcmdPackage appcmd contains helper functionality for applications using commands.
appcmd/appcmdtesting
appflagPackage appflag contains functionality to work with flags.
applogPackage applog contains utilities to work with logging.
appprotoPackage appproto contains helper functionality for protoc plugins.
appproto/appprotoexecPackage appprotoexec provides protoc plugin handling and execution.
appproto/appprotogen
appproto/appprotoosPackage appprotoos does OS-specific generation.

Package app imports 12 packages (graph) and is imported by 14 packages. Updated 2020-10-20. Refresh now. Tools for package owners.