outfile

package
v2.0.4 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefineFlags

func DefineFlags(fs *flag.FlagSet, fileFlag, forceFlag, appendFlag, fileHelpName string)

DefineFlags is a wrapper around CreateOpener for updating a default instance of Opener.

Types

type FilenameTransform

type FilenameTransform func(string) string

A FilenameTransform applies a transform to the filename before it used to open a file.

type NameWriteCloser

type NameWriteCloser interface {
	// Name returns a name for the Writer.
	Name() string
	io.WriteCloser
}

NameWriteCloser implements the io.WriteCloser interface, but also allows a a name to be returned so that the object can be identified.

func Open

func Open(ctx context.Context) (NameWriteCloser, error)

Open is a wrapper around Opener.Open for the default instance of Opener.

Must only be called after DefineFlags.

type Opener

type Opener struct {
	FilenameTransform FilenameTransform

	Perm os.FileMode
	// contains filtered or unexported fields
}
var DefaultOpener *Opener

func CreateOpener

func CreateOpener(fs *flag.FlagSet, fileFlag, forceFlag, appendFlag, fileHelpName string) *Opener

CreateOpener creates an Opener and defines the sepecified flags fileFlag, forceFlag and appendFlag.

func (*Opener) Open

func (o *Opener) Open(ctx context.Context) (NameWriteCloser, error)

Open opens and returns a file for output with the filename set by the fileFlag, applying any transform set in FilenameTransform.

If filename is empty/unset, os.Stdout will be used. If filename does not exist, it will be created with the mode set in o.Perm. If filename does exist, the behavior of this function will depend on the flags:

  • if appendFlag is set on the command line the existing file will be appended to.
  • if forceFlag is set on the command line the existing file will be truncated.
  • if neither forceFlag nor appendFlag are set an error will be returned.

Jump to

Keyboard shortcuts

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