editor

package
v0.14.2 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package editor spawns the user's external editor over a temporary Markdown file and reads the edited result back.

Its defining constraint is that a non-blocking editor is a data-loss hazard: launchers like `code` or `subl` fork and return to the shell immediately by default, racing the caller's temp-file cleanup against the editor's save. Run refuses a known non-blocking editor unless its command line carries a wait flag, and EditMarkdown additionally treats a sub-second exit with unchanged content as that same failure. Editor resolution follows JIRA_EDITOR → configured → $EDITOR → $VISUAL → "vi".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EditMarkdown

func EditMarkdown(ctx context.Context, issueKey, fieldName, markdown, editorCommand string) (string, error)

EditMarkdown writes a temp file, spawns the configured editor, and reads the edited content back. The temp file is preserved on every error path (per kubectl's pattern) so the user can recover in-flight edits — the path is named in the error message.

A sub-second editor exit combined with byte-identical content trips the non-blocking-spawn safety check: that's the signature of `EDITOR=code` (without --wait) returning before VS Code has finished opening the buffer. Treating it as success would race the parent's cleanup against the editor's save, causing the strikethrough-on- filename + silent-data-loss bug.

func ReadMarkdown

func ReadMarkdown(path string) (string, error)

ReadMarkdown reads path and returns its body with any leading frontmatter block (the one WriteTemp adds) stripped and surrounding whitespace trimmed.

func Resolve

func Resolve(configured string) string

Resolve returns the editor command to launch, given a configured editor (typically pulled from profile.editor or global config.editor).

Precedence:

JIRA_EDITOR → configured → $EDITOR → $VISUAL → "vi"

JIRA_EDITOR is the per-invocation override; configured is the user's pinned preference in jira-cli config; $EDITOR/$VISUAL are the platform defaults; "vi" is the last-resort fallback. An empty value at any level falls through to the next.

func ResolveEditor

func ResolveEditor() string

ResolveEditor is the no-arg variant for callers that don't have access to the config layer. Equivalent to Resolve("").

func RoundTripADF

func RoundTripADF(ctx context.Context, opts RoundTripADFOptions) (adf.Document, []adf.Warning, error)

RoundTripADF takes an ADF document, renders it to GFM Markdown for the editor buffer, preserves any non-Markdown-representable subtrees as fenced opaque blocks, launches the editor, parses the edited Markdown back, reconstitutes the opaques, and returns the resulting Document plus any structured warnings emitted along the way.

func Run

func Run(ctx context.Context, editorCommand, path string) error

Run resolves editorCommand (see Resolve), then spawns it on path with the user's terminal wired through so an interactive editor can read keystrokes. It refuses a known non-blocking editor invoked without a wait flag, since that would race the caller's cleanup. exec.Command is used directly — no shell — so path and args are never re-interpreted.

func WriteTemp

func WriteTemp(issueKey, fieldName, markdown string) (string, error)

WriteTemp writes markdown to a new jira-edit-*.md temp file, prefixed with an issue_key/field_name frontmatter block for context, and returns its path. The caller owns cleanup — EditMarkdown deletes it, but preserves it on error.

Types

type RoundTripADFOptions

type RoundTripADFOptions struct {
	IssueKey  string
	FieldName string
	Document  adf.Document
	// EditCmd is the user's editor invocation (env-driven). Mutually
	// exclusive with EditFn — EditFn wins for tests.
	EditCmd string
	EditFn  func(ctx context.Context, path string) error
}

RoundTripADFOptions configures one external --edit cycle.

Jump to

Keyboard shortcuts

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