1package main
2
3import (
4	"encoding/json"
5	"errors"
6)
7
8// jsonShell is not a real shell
9type jsonShell struct{}
10
11// JSON is not really a shell but it fits. Useful to add support to editor and
12// other external tools that understand JSON as a format.
13var JSON Shell = jsonShell{}
14
15func (sh jsonShell) Hook() (string, error) {
16	return "", errors.New("this feature is not supported")
17}
18
19func (sh jsonShell) Export(e ShellExport) string {
20	out, err := json.MarshalIndent(e, "", "  ")
21	if err != nil {
22		// Should never happen
23		panic(err)
24	}
25	return string(out)
26}
27
28func (sh jsonShell) Dump(env Env) string {
29	out, err := json.MarshalIndent(env, "", "  ")
30	if err != nil {
31		// Should never happen
32		panic(err)
33	}
34	return string(out)
35}
36