core: go.gazette.dev/core/cmd/gazctl/editor Index | Files

package editor

import "go.gazette.dev/core/cmd/gazctl/editor"

Package editor provides utilities for editing and re-editing text files in an editor until the changes are accepted or the user aborts the attempt.

Index

Package Files

editor.go

func EditRetryLoop Uses

func EditRetryLoop(args RetryLoopArgs) error

EditRetryLoop seeds a temp file, prefixed with FilePrefix, with content from SelectFn and passes it to ApplyFn. If ApplyFn errors, the editor will be re-opened with recent error message included in the header comments. The current implementation prefixes comment lines with "#".

type RetryLoopArgs Uses

type RetryLoopArgs struct {
    // FilePrefix
    FilePrefix string
    // SelectFn returns content to be displayed within the editor.
    // It is invoked on each retry of the editing loop.
    SelectFn func() io.Reader
    // ApplyFn attempts to apply the edited contents. If it returns
    // an error, the editor will be re-opened with the error message.
    ApplyFn func(b []byte) error
    // AbortIfUnchanged indicates the editing loop should abort if the
    // editor exits without making any file changes. In this case,
    // ApplyFn is not called with edited content.
    AbortIfUnchanged bool
}

RetryLoopArgs is arguments of EditRetryLoop.

Package editor imports 10 packages (graph) and is imported by 1 packages. Updated 2019-12-23. Refresh now. Tools for package owners.