exec

package
v0.18.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: BSD-3-Clause Imports: 12 Imported by: 2

Documentation

Overview

Package exec allows invoking other commands, including triggering the manual, opening a document, or opening a Web page in the default Web browser. It also provides a representation of the flag value syntax used by the -exec expression in Unix-like find designed to pass the name of a command and its arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FindEditor added in v0.16.1

func FindEditor() string

FindEditor gets the command used for the editor.

func HaveLookPath added in v0.13.0

func HaveLookPath(pathname string) cli.ContextFilter

HaveLookPath returns a ContextFilter that checks if the given pathname exists on the PATH.

func Open

func Open(file string, appopt ...string) error

Open a file or URL, optionally in the given app. Either one or two arguments is specified, the name/URL of the file to open and the name of the app to use. If the argument looks like a URL, then it triggers the use of the protocol handler associated with the protocol if no app is specified.

Types

type ArgList

type ArgList []string

ArgList provides a value that describes a command and its arguments used as a flag, arg, or expression Value. This uses the syntax that the find -exec expression uses, which is terminated by a semi-colon or plus sign. (e.g. -exec COMMAND ; or -exec COMMAND {} +).

func (*ArgList) Args

func (l *ArgList) Args() []string

Args gets the list of items added, including the command as Args()[0]

func (*ArgList) Command

func (l *ArgList) Command() (string, []string)

Command gets the command and its arguments

func (*ArgList) NewCounter

func (l *ArgList) NewCounter() cli.ArgCounter

func (*ArgList) Set

func (l *ArgList) Set(arg string) error

func (*ArgList) String

func (l *ArgList) String() string

func (*ArgList) UsePlaceholder

func (l *ArgList) UsePlaceholder() bool

UsePlaceholder gets whether the arg list ended with +, which is used to indicate that the {} placeholder is to be expanded

type Editor added in v0.16.0

type Editor struct {
	// Data provides the initial content of the temporary file.
	// Accepted types: io.Reader, string, or []byte.
	Data any

	// Mode sets the file permissions on the temporary file.
	Mode fs.FileMode

	// ModTime, when non-zero, sets the modification time of the temporary file.
	ModTime time.Time

	// Cmd, when non-nil, is called with the *exec.Cmd created via
	// exec.CommandContext before the editor is started, allowing further
	// customization (environment variables, extra arguments, etc.).
	Cmd func(*eexec.Cmd)

	// KeepTempFile when set to true, causes the temporary file not to be deleted
	// after the
	KeepTempFile bool

	// Output receives the output of the editor
	Output []byte
}

Editor is a pipeline-enabled value that opens a text editor using OS-specific conventions. The VISUAL environment variable is consulted first, then EDITOR, then an OS-specific fallback.

The fields correspond to those of testing/fstest.MapFile (excluding Sys) and are used to initialize the temporary file the editor opens. Data accepts io.Reader, string, or []byte; the zero value produces an empty file.

func (*Editor) Execute added in v0.16.0

func (e *Editor) Execute(ctx context.Context) error

Execute implements cli.Action. It creates a temporary file, writes Data into it (if set), applies Mode and ModTime, then invokes the system editor and waits for it to exit.

Jump to

Keyboard shortcuts

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