mirror of
https://github.com/go-sylixos/elvish.git
synced 2024-12-13 09:57:51 +08:00
33 lines
676 B
Go
33 lines
676 B
Go
package eval
|
|
|
|
import (
|
|
"errors"
|
|
"strconv"
|
|
|
|
"github.com/elves/elvish/daemon/api"
|
|
)
|
|
|
|
var ErrDaemonOffline = errors.New("daemon is offline")
|
|
|
|
func makeDaemonNamespace(daemon *api.Client) Namespace {
|
|
// Obtain process ID
|
|
daemonPid := func() Value {
|
|
pid, err := daemon.Pid()
|
|
maybeThrow(err)
|
|
return String(strconv.Itoa(pid))
|
|
}
|
|
|
|
return Namespace{
|
|
"pid": MakeRoVariableFromCallback(daemonPid),
|
|
"sock": NewRoVariable(String(daemon.SockPath())),
|
|
|
|
FnPrefix + "spawn": NewRoVariable(&BuiltinFn{"daemon:spawn", daemonSpawn}),
|
|
}
|
|
}
|
|
|
|
func daemonSpawn(ec *EvalCtx, args []Value, opts map[string]Value) {
|
|
TakeNoArg(args)
|
|
TakeNoOpt(opts)
|
|
maybeThrow(ec.ToSpawn.Spawn())
|
|
}
|