Documentation
¶
Overview ¶
Package files maps course content to local paths, downloads it, and opens it.
Index ¶
- Constants
- func CourseDir(root string, c d2l.Course) string
- func DirNames(m *d2l.Module) map[int]string
- func Download(ctx context.Context, c *d2l.Client, orgUnit int, t d2l.Topic, dest string) (skipped bool, err error)
- func DownloadAttachment(ctx context.Context, c *d2l.Client, orgUnit, newsID int, a d2l.Attachment, ...) (string, error)
- func FileName(t d2l.Topic) string
- func Fresh(dest string, t d2l.Topic) bool
- func ModuleDir(root string, c d2l.Course, levels []*d2l.Module) string
- func Names(m *d2l.Module) map[int]string
- func Sanitize(s string) string
- func ShellCommand(command, arg string) *exec.Cmd
- func StartDetached(cmd *exec.Cmd) error
- type Entry
- type Opener
Constants ¶
const DefaultEditor = "vi"
DefaultEditor is used when $EDITOR is unset.
Variables ¶
This section is empty.
Functions ¶
func DirNames ¶
DirNames picks the local folder name of each submodule of m, keyed by ModuleID, with the same rule as Names.
func Download ¶
func Download(ctx context.Context, c *d2l.Client, orgUnit int, t d2l.Topic, dest string) (skipped bool, err error)
Download fetches a File topic to dest unless it is already Fresh.
func DownloadAttachment ¶
func DownloadAttachment(ctx context.Context, c *d2l.Client, orgUnit, newsID int, a d2l.Attachment, dir string) (string, error)
DownloadAttachment saves an announcement attachment into dir and returns its path.
func FileName ¶
FileName picks the local name for a File topic: the name from its URL, falling back to the title.
func Fresh ¶
Fresh reports whether dest exists and is not older than the topic. Download stamps files with the topic's LastModifiedDate, so an equal mtime means unchanged.
func ModuleDir ¶
ModuleDir is the folder of the last module in levels. levels[0] is the TOC root and each later module is a child of the one before it.
func Names ¶
Names picks the local name of each File topic directly in m, keyed by TopicID. When names clash, ignoring case, the topic with the lowest ID keeps the name and the others get " (TopicID)" before the extension. IDs only grow, so adding or reordering topics never renames an existing file.
func ShellCommand ¶
ShellCommand runs a user-configured command with arg appended as "$1", so commands with their own arguments (`zathura --fork`, `code --wait`) work and arg is never parsed by the shell.
func StartDetached ¶
StartDetached runs a non-terminal opener in its own session so it outlives the TUI and doesn't scribble on the screen. It waits up to openerGrace and reports a non-zero exit in that time with the first line of stderr.
Types ¶
type Entry ¶
type Entry struct {
Path []string // module titles, outermost first
Topic d2l.Topic
Dest string // empty unless Topic.IsFile()
}
Entry is a topic with the module titles leading to it and, for a File topic, where it is stored.