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 ¶
ShellEditor describes the command and parameters to open a text editor.
Click to show internal directories.
Click to hide internal directories.