1package store
2
3import (
4	"src.elv.sh/pkg/eval"
5	"src.elv.sh/pkg/store/storedefs"
6)
7
8//elvdoc:fn next-cmd-seq
9//
10// ```elvish
11// store:next-cmd-seq
12// ```
13//
14// Outputs the sequence number that will be used for the next entry of the
15// command history.
16
17//elvdoc:fn add-cmd
18//
19// ```elvish
20// store:add-cmd $text
21// ```
22//
23// Adds an entry to the command history with the given content. Outputs its
24// sequence number.
25
26//elvdoc:fn del-cmd
27//
28// ```elvish
29// store:del-cmd $seq
30// ```
31//
32// Deletes the command history entry with the given sequence number.
33//
34// **NOTE**: This command only deletes the entry from the persistent store. When
35// deleting an entry that was added in the current session, the deletion will
36// not take effect for the current session, since the entry still exists in the
37// in-memory per-session history.
38
39//elvdoc:fn cmd
40//
41// ```elvish
42// store:cmd $seq
43// ```
44//
45// Outputs the content of the command history entry with the given sequence
46// number.
47
48//elvdoc:fn cmds
49//
50// ```elvish
51// store:cmds $from $upto
52// ```
53//
54// Outputs all command history entries with sequence numbers between `$from`
55// (inclusive) and `$upto` (exclusive). Use -1 for `$upto` to not set an upper
56// bound.
57//
58// Each entry is represented by a pseudo-map with fields `text` and `seq`.
59
60//elvdoc:fn add-dir
61//
62// ```elvish
63// store:add-dir $path
64// ```
65//
66// Adds a path to the directory history. This will also cause the scores of all
67// other directories to decrease.
68
69//elvdoc:fn del-dir
70//
71// ```elvish
72// store:del-dir $path
73// ```
74//
75// Deletes a path from the directory history. This has no impact on the scores
76// of other directories.
77
78//elvdoc:fn dirs
79//
80// ```elvish
81// store:dirs
82// ```
83//
84// Outputs all directory history entries, in decreasing order of score.
85//
86// Each entry is represented by a pseudo-map with fields `path` and `score`.
87
88//elvdoc:fn shared-var
89//
90// ```elvish
91// store:shared-var $name
92// ```
93//
94// Outputs the value of the shared variable with the given name. Throws an error
95// if the shared variable doesn't exist.
96
97//elvdoc:fn set-shared-var
98//
99// ```elvish
100// store:set-shared-var $name $value
101// ```
102//
103// Sets the value of the shared variable with the given name, creating it if it
104// doesn't exist. The value must be a string.
105
106//elvdoc:fn del-shared-var
107//
108// ```elvish
109// store:del-shared-var $name
110// ```
111//
112// Deletes the shared variable with the given name.
113
114func Ns(s storedefs.Store) *eval.Ns {
115	return eval.BuildNsNamed("store").
116		AddGoFns(map[string]interface{}{
117			"next-cmd-seq": s.NextCmdSeq,
118			"add-cmd":      s.AddCmd,
119			"del-cmd":      s.DelCmd,
120			"cmd":          s.Cmd,
121			"cmds":         s.CmdsWithSeq,
122			"next-cmd":     s.NextCmd,
123			"prev-cmd":     s.PrevCmd,
124
125			"add-dir": func(dir string) error { return s.AddDir(dir, 1) },
126			"del-dir": s.DelDir,
127			"dirs":    func() ([]storedefs.Dir, error) { return s.Dirs(storedefs.NoBlacklist) },
128
129			"shared-var":     s.SharedVar,
130			"set-shared-var": s.SetSharedVar,
131			"del-shared-var": s.DelSharedVar,
132		}).Ns()
133}
134