waveterm/wavesrv/pkg/ephemeral/ephemeral.go
Evan Simkowitz ccc63937b6
Support running ephemeral commands (#543)
* initial

* save work, starting to add backend types

* save work

* save work

* Add EphemeralWriteCloser

* Command pipes thru, triggers infinite loop

* save debugging

* fix bad merge

* save debug statements

* fixing spaghetti

* clean up code

* got cwd override working

* Add separate paths for stdout and stderr writers

* fix stdout/stderr

* env vars are now working

* revert waveshell changes

* Making EphemeralWriteCloser into a more generic BufferedPipe

* formatting

* comment

* delete unused package

* more naming changes

* add package comment

* add UsePty to EphemeralRunOpts

* document UsePty

* ensure only one downstream writer can read from the buffer

* store pointer to syncs

* remove inshellisense stuff for now

* remove debugs

* revert yarn

* remove unnecessary debugs in main-server

* more debugging removed

* revert tsconfig
2024-04-02 15:46:32 -07:00

29 lines
2.0 KiB
Go

// Copyright 2024, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0
// Manage additional options for ephemeral commands (commands that are not saved to the history).
package ephemeral
import (
"io"
"sync/atomic"
"time"
)
const (
DefaultEphemeralTimeoutMs = 5000 // The default timeout for ephemeral commands in milliseconds.
DefaultEphemeralTimeoutDuration = DefaultEphemeralTimeoutMs * time.Millisecond // The default timeout for ephemeral commands as a time.Duration.
)
// Options specific to ephemeral commands (commands that are not saved to the history)
type EphemeralRunOpts struct {
Env map[string]string `json:"env,omitempty"` // Environment variables to set for the command.
OverrideCwd string `json:"overridecwd,omitempty"` // A directory to use as the current working directory. Defaults to the last set shell state.
UsePty bool `json:"usepty"` // If set, the command is run in a pseudo-terminal and all output will be written to the StdoutWriter. If not set, the command is run in a normal shell and the output is written to the StdoutWriter and StderrWriter.
TimeoutMs int64 `json:"timeoutms"` // The maximum time to wait for the command to complete. If the command does not complete within this time, it is killed.
ExpectsResponse bool `json:"expectsresponse"` // If set, the command is expected to return a response. If this is false, ResposeWriter is not set.
StdoutWriter io.WriteCloser `json:"-"` // A writer to receive the command's stdout. If not set, the command's output is discarded. (set by remote.go)
StderrWriter io.WriteCloser `json:"-"` // A writer to receive the command's stderr. If not set, the command's output is discarded. (set by remote.go)
Canceled atomic.Bool `json:"canceled,omitempty"` // If set, the command was canceled before it completed.
}