Documentation
¶
Overview ¶
Package edit is how a gist is changed, shared by the CLI and the TUI: it holds the gist's lock, knows the revision a change was based on, keeps an edit as a draft until it is sent, and checks the gist did not move underneath it.
What can be promised is limited by the API, which takes no condition on a PATCH. A change made elsewhere between the start of an edit and the check just before sending is always found. One made between that check and the PATCH is not prevented, but it is found afterwards and reported, and the revision it made stays on GitHub. Changing just the description makes no revision, so it is compared by its text, and one overwritten in that last moment is lost.
Index ¶
- Variables
- func Command(configured string, paths ...string) []string
- type API
- type ChangedError
- type Editor
- type FileEdit
- type KeptAtError
- type Request
- type Result
- type Scratch
- type Session
- func (s *Session) Changed() []*FileEdit
- func (s *Session) Close() error
- func (s *Session) DropDrafts(ctx context.Context) error
- func (s *Session) File(name string) *FileEdit
- func (s *Session) Gist() string
- func (s *Session) Keep(name, content string) (bool, error)
- func (s *Session) Push(ctx context.Context, overwrite bool) (Result, error)
- func (s *Session) Reload(ctx context.Context) (bool, error)
- func (s *Session) Workspace() (*Workspace, error)
- type Workspace
Constants ¶
This section is empty.
Variables ¶
var ErrNoFile = errors.New("no such file in the gist")
ErrNoFile says the gist has no such file.
Functions ¶
Types ¶
type API ¶
type API interface {
Get(ctx context.Context, id string) (model.Gist, error)
Raw(ctx context.Context, f model.File) (string, error)
Update(ctx context.Context, id string, ch model.Change) (model.Gist, error)
}
API is what editing asks of GitHub.
type ChangedError ¶
type ChangedError struct {
// Current is the gist as it is now.
Current model.Gist
// What names what moved: "revision" or "description".
What string
}
ChangedError says the gist on GitHub is not what the change was based on.
func (*ChangedError) Error ¶
func (e *ChangedError) Error() string
type Editor ¶
type Editor struct {
API API
State *state.Store
// Now is the time, for tests; nil uses the clock.
Now func() time.Time
}
Editor changes gists.
func (*Editor) Begin ¶
Begin starts editing files, each from its draft if it has one. The gist's lock is held until Close: ErrLocked says another process has it.
type FileEdit ¶
type FileEdit struct {
// Name is the file's name.
Name string
// Revision and Original are the base: what the edit started from. A
// refresh of the list does not change them.
Revision string
Original string
// Content is what to edit: the original, or the draft of an earlier edit.
Content string
// FromDraft says Content came from a draft.
FromDraft bool
// contains filtered or unexported fields
}
FileEdit is a file being edited.
type KeptAtError ¶
KeptAtError says an edit could not be kept as a draft and its files are left on disk, so it is not lost.
func (*KeptAtError) Error ¶
func (e *KeptAtError) Error() string
func (*KeptAtError) Unwrap ¶
func (e *KeptAtError) Unwrap() error
type Request ¶
type Request struct {
Gist string
// Base, when not "", is the revision the change must be based on.
Base string
// BaseDescription, when not nil, is the description it must be based on.
BaseDescription *string
// Build makes the change from the gist as it is. An empty one sends
// nothing.
Build func(ctx context.Context, g model.Gist) (model.Change, error)
}
Request is a change made without an editor.
type Result ¶
type Result struct {
// Gist is the gist after the change.
Gist model.Gist
// Sent says something was sent; not when there was nothing to change.
Sent bool
// Overwritten is the revision of a change made elsewhere that this one
// went over, found only after sending, or "".
Overwritten string
}
Result is what a change did.
type Scratch ¶
type Scratch struct {
// contains filtered or unexported fields
}
Scratch is a file for an editor to write what has no gist yet.
func NewScratch ¶
NewScratch writes content to a file of this name, in a directory of its own that only the user can read.
type Session ¶
type Session struct {
// Files are the files being edited.
Files []*FileEdit
// contains filtered or unexported fields
}
Session is the editing of a gist's files: from taking the lock until they are sent or given up. Close lets the lock go.
func (*Session) DropDrafts ¶
DropDrafts throws away the drafts the session started from, and starts those files again from GitHub.
func (*Session) Keep ¶
Keep records content as the draft of a file, if it differs from the base, and returns whether it does. When it does not, there is nothing to send of it and no draft is left. Comparing with the base rather than the draft means a draft opened and closed unchanged still goes on to be sent.
func (*Session) Push ¶
Push sends the content kept of the files changed, in one change, unless the gist has moved on from what one of them is based on, which ChangedError says. With overwrite it goes over what is there. Their drafts go once it is sent.
type Workspace ¶
type Workspace struct {
// contains filtered or unexported fields
}
Workspace is the files of a session on disk, for an editor: each under its real name, so the editor highlights it.
func (*Workspace) ReadBack ¶
ReadBack reads the files the editor left, whatever way it ended, and keeps each as a draft. Only then are they removed: until the edit is in a draft these files are its only copy. It returns whether anything differs from the base. An editor that removed a file leaves the edit of that file as it was.