editz

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2022 License: MIT Imports: 7 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Edit

func Edit(filePath string, validateFunc func([]byte) error) (contents []byte, isChanged bool, err error)

Edit implements a visudo-like text editing prompt.

Sequence of actions:

1. Copy the file to a temporary location. 2. Open it using the default text editor (or a fallback editor, depending on the system). 3. Wait for the editor to exit. 4. If no changes were made, return immediately, otherwise validate the changes using the given callback. 5. If validation succeeds, overwrite the original file with the changed one, otherwise abort.

The function returns the contents of the file after editing and a flag indicating whether there were changes.

Types

type Editor

type Editor interface {
	Edit(filePath string)
}

Editor opens a text editor.

var (
	// DefaultEditor is the default Editor.
	DefaultEditor Editor = getDefaultEditor()
)

type ShellEditor

type ShellEditor struct {
	Command string
	Params  []string
}

ShellEditor describes the command and parameters to open a text editor.

func (*ShellEditor) Edit

func (e *ShellEditor) Edit(filePath string)

Edit runs the editor.

Jump to

Keyboard shortcuts

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