main 98594d0

assert.go RawHistoryFolder

1// SPDX-License-Identifier: MIT
2
3package template
4
5import "fmt"
6
7// TokenError is an error about a token, positioned at it. It is what the
8// Assert functions return.
9type TokenError struct {
10	Token   Token
11	Message string
12}
13
14func (e *TokenError) Error() string { return e.Message }
15
16func assertErr(t Token, desc string, want string) error {
17	return &TokenError{Token: t, Message: fmt.Sprintf("Unexpected type '%s' encountered while reading '%s'. The type '%s' was expected.", t.Kind(), desc, want)}
18}
19
20// AssertString returns t as a string token or a [*TokenError] worded like the
21// reference's "Unexpected type 'X' encountered while reading 'desc'".
22func AssertString(t Token, desc string) (*String, error) {
23	if s, ok := t.(*String); ok {
24		return s, nil
25	}
26	return nil, assertErr(t, desc, KindString.String())
27}
28
29// AssertBoolean returns t as a boolean token or a [*TokenError].
30func AssertBoolean(t Token, desc string) (*Boolean, error) {
31	if s, ok := t.(*Boolean); ok {
32		return s, nil
33	}
34	return nil, assertErr(t, desc, KindBoolean.String())
35}
36
37// AssertNumber returns t as a number token or a [*TokenError].
38func AssertNumber(t Token, desc string) (*Number, error) {
39	if s, ok := t.(*Number); ok {
40		return s, nil
41	}
42	return nil, assertErr(t, desc, KindNumber.String())
43}
44
45// AssertSequence returns t as a sequence token or a [*TokenError].
46func AssertSequence(t Token, desc string) (*Sequence, error) {
47	if s, ok := t.(*Sequence); ok {
48		return s, nil
49	}
50	return nil, assertErr(t, desc, KindSequence.String())
51}
52
53// AssertMapping returns t as a mapping token or a [*TokenError].
54func AssertMapping(t Token, desc string) (*Mapping, error) {
55	if s, ok := t.(*Mapping); ok {
56		return s, nil
57	}
58	return nil, assertErr(t, desc, KindMapping.String())
59}
60
61// AssertScalar returns t when it is neither a sequence nor a mapping, or a
62// [*TokenError].
63func AssertScalar(t Token, desc string) (Token, error) {
64	if IsScalar(t) {
65		return t, nil
66	}
67	return nil, assertErr(t, desc, "ScalarToken")
68}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 3

↑↓ moveenter openesc close