Documentation
¶
Overview ¶
Package ctl is the control socket that lets a block talk back to the run that started it: mdsh ctl on one side, the run on the other.
Each call opens a connection, sends one line of JSON, reads one line of JSON back, and closes. The server handles calls one at a time, in the order they arrive.
Index ¶
Constants ¶
const ( // SockVar holds the socket's path. SockVar = "MDSH_SOCK" // TokenVar holds the token for this run of this block. TokenVar = "MDSH_TOKEN" )
The variables mdsh exports in every block's prelude.
const ( // OK is done, or confirm was answered yes. OK = 0 // No is confirm answered no. No = 1 // Refused is bad arguments, an unknown task, a token that has // stopped working, or a name that an input binds. Refused = 2 // NotRunning is $MDSH_SOCK unset, or nothing listening on it. NotRunning = 3 // NoAnswer is ask or confirm with nobody to answer and no default. NoAnswer = 4 )
Exit codes, the same for every command.
const ( Yes = "yes" // NoValue is confirm answered no; mdsh ctl exits with No. NoValue = "no" )
The values a confirm call answers with.
const MaxRequest = 1 << 20
MaxRequest is the longest request line the server reads.
const Version = 1
Version is the protocol version this package speaks.
Variables ¶
var ErrNotRunning = errors.New("not running under mdsh")
ErrNotRunning is Call's error when there is no run to call: the socket path is empty or nothing is listening on it.
Functions ¶
func NoAnswerError ¶ added in v1.6.0
NoAnswerError is the error for a NoAnswer response: what mdsh ctl prints, and what the run shows under the block.
Types ¶
type AskArgs ¶ added in v1.6.0
type AskArgs struct {
Question string `json:"question"`
Choices []string `json:"choices,omitempty"`
Default *string `json:"default,omitempty"`
Secret bool `json:"secret,omitempty"`
}
AskArgs are the arguments to ask and confirm. Default is nil when the call gave no --default; for confirm it is "yes" or "no". Choices and Secret are for ask only.
type NameArgs ¶
type NameArgs struct {
Name string `json:"name"`
}
NameArgs are the arguments to unset and get.
type Request ¶
type Request struct {
V int `json:"v"`
Token string `json:"token"`
Cmd string `json:"cmd"`
Args json.RawMessage `json:"args,omitempty"`
}
Request is one call.
type Response ¶
type Response struct {
V int `json:"v"`
OK bool `json:"ok"`
Value string `json:"value,omitempty"`
Error string `json:"error,omitempty"`
Code int `json:"code,omitempty"`
}
Response is the answer to one call. Value is what the command prints, such as the value get read.
func Call ¶
Call sends cmd with args to the socket at path, as the block that has token, and returns the answer. It waits as long as the run takes to answer, which for a question can be a while.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server listens on the control socket.
func Listen ¶
Listen creates the socket in a new temp directory that only the current user can open, and starts serving calls with h.
type SetArgs ¶
type SetArgs struct {
Name string `json:"name"`
Value string `json:"value"`
Secret bool `json:"secret,omitempty"`
}
SetArgs are the arguments to set.
type StatusArgs ¶
type StatusArgs struct {
Text string `json:"text"`
Step int `json:"step,omitempty"`
Of int `json:"of,omitempty"`
}
StatusArgs are the arguments to status. Step and Of are 0 when the call gave no count.