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
|
package cmd
import (
"encoding/json"
"errors"
)
// jsonShell is not a real shell
type jsonShell struct{}
// JSON is not really a shell but it fits. Useful to add support to editor and
// other external tools that understand JSON as a format.
var JSON Shell = jsonShell{}
func (sh jsonShell) Hook() (string, error) {
return "", errors.New("this feature is not supported")
}
func (sh jsonShell) Export(e ShellExport) (string, error) {
out, err := json.MarshalIndent(e, "", " ")
if err != nil {
return "", err
}
return string(out), nil
}
func (sh jsonShell) Dump(env Env) (string, error) {
out, err := json.MarshalIndent(env, "", " ")
if err != nil {
return "", err
}
return string(out), nil
}
|