Repository navigation
Expand file tree
/
Copy pathport.go
More file actions
48 lines (41 loc) · 1.46 KB
/
Copy pathport.go
File metadata and controls
48 lines (41 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//go:generate mockgen -source=port.go -destination=mock.port_test.go -package=internal_test -exclude_interfaces=World
// Package internal implements task toc.
package internal
import "errors"
// Texts of HTML comments around a table of contents.
const (
MarkerStart = "toc"
MarkerEnd = "tocstop"
)
// Errors.
var (
ErrInvalidLevels = errors.New("invalid range of heading levels")
ErrNoMarker = errors.New("no <!-- " + MarkerStart + " --> marker")
ErrNoEndMarker = errors.New("no <!-- " + MarkerEnd + " --> marker after <!-- " + MarkerStart + " -->")
ErrOutdated = errors.New("outdated table of contents")
)
// App is the application.
type App interface {
// Update updates tables of contents in markdown files.
Update(opts Options) error
}
// World abstracts commands and files for testability.
type World interface {
// TOCFiles returns paths of tracked and untracked (but not ignored) markdown files
// which have a line with the start marker,
// relative to the current directory and separated by '/'.
TOCFiles() ([]string, error)
ReadFile(name string) ([]byte, error)
WriteFile(name string, data []byte) error
}
// Options of [App.Update].
type Options struct {
// Files to update.
// Default is all markdown files with a table of contents.
Files []string
// MinLevel and MaxLevel set the range of heading levels to include.
MinLevel int
MaxLevel int
// Check makes Update fail on an outdated table of contents instead of updating it.
Check bool
}