wrapspec.go

 1package cmd
 2
 3import "git.secluded.site/keld/internal/ui/screens"
 4
 5// wrappedCommand describes a restic command that keld exposes in its
 6// interactive menu and shell completions.
 7type wrappedCommand struct {
 8	Name   string
 9	Hotkey rune
10}
11
12// wrappedCommands lists the restic commands keld actively wraps. Adding
13// an entry here automatically surfaces it in the TUI menu and shell
14// completions. The order determines menu display order.
15var wrappedCommands = []wrappedCommand{
16	{Name: "backup", Hotkey: 'b'},
17	{Name: "restore", Hotkey: 'r'},
18	{Name: "snapshots", Hotkey: 's'},
19	{Name: "forget", Hotkey: 'f'},
20	{Name: "check", Hotkey: 'c'},
21	{Name: "init", Hotkey: 'i'},
22}
23
24// menuItems is derived from wrappedCommands for the interactive menu.
25var menuItems = func() []screens.MenuItem {
26	items := make([]screens.MenuItem, len(wrappedCommands))
27	for i, wc := range wrappedCommands {
28		items[i] = screens.MenuItem{Label: wc.Name, Hotkey: wc.Hotkey}
29	}
30	return items
31}()
32
33// knownCommands is derived from wrappedCommands for shell completion.
34var knownCommands = func() []string {
35	names := make([]string, len(wrappedCommands))
36	for i, wc := range wrappedCommands {
37		names[i] = wc.Name
38	}
39	return names
40}()
41
42// flagContract describes a restic flag that keld semantically depends on
43// (e.g. used in HasFlag checks or keyAliases).
44type flagContract struct {
45	Command    string
46	Name       string
47	IsBool     bool
48	Repeatable bool
49}
50
51// flagContracts lists flags keld's wrapper logic hardcodes assumptions
52// about. Contract tests verify these still match the generated data.
53var flagContracts = []flagContract{
54	{Command: "restore", Name: "target", IsBool: false, Repeatable: false},
55	{Command: "global", Name: "repo", IsBool: false, Repeatable: false},
56}
57
58// passthroughCommands lists restic commands that keld does not actively wrap
59// but should still allow through without error. Contract tests verify that
60// every command in restic.Commands is either wrapped or listed here.
61var passthroughCommands = map[string]struct{}{
62	"cache":            {},
63	"cat":              {},
64	"copy":             {},
65	"diff":             {},
66	"dump":             {},
67	"features":         {},
68	"find":             {},
69	"generate":         {},
70	"key":              {},
71	"key-add":          {},
72	"key-list":         {},
73	"key-passwd":       {},
74	"key-remove":       {},
75	"list":             {},
76	"ls":               {},
77	"migrate":          {},
78	"mount":            {},
79	"options":          {},
80	"prune":            {},
81	"recover":          {},
82	"repair":           {},
83	"repair-index":     {},
84	"repair-packs":     {},
85	"repair-snapshots": {},
86	"rewrite":          {},
87	"stats":            {},
88	"tag":              {},
89	"unlock":           {},
90	"version":          {},
91}