Documentation
¶
Index ¶
- Variables
- func ExpandPath(path string, getUser func() (*user.User, error), cwdFn func() (string, error)) (string, error)
- func ExpandPathWithURI(path string, uri URI) (string, error)
- func HasPrefix(uri, prefix URI) bool
- func RelPath(base, target URI) string
- type Cmd
- type Executor
- type File
- type FileSystem
- type Pid
- type ProcessWatcher
- type Pty
- type Terminal
- type URI
Constants ¶
This section is empty.
Variables ¶
var ( // ErrFileIsNotRegular is returned when file type was not expected to be a directory. ErrFileIsNotRegular = errors.New("file type is not regular") // ErrFileIsNotWritable is returned when file is opened in read-only. ErrFileIsNotWritable = errors.New("file is not writable") // ErrFileAlreadyOpen is returned when a file is not expected to be opened already. ErrFileAlreadyOpen = errors.New("file open by another process or previous process was closed abruptly") // ErrStaleData is returned when a file was modified by some other application. ErrStaleData = errors.New("file was modified by another process since reading it") )
Functions ¶
func ExpandPath ¶
func ExpandPath( path string, getUser func() (*user.User, error), cwdFn func() (string, error), ) (string, error)
ExpandPath finds the absolute path of a relative path and expands the home shortcut (~) if any. If path is already absolute then this function returns the path unchanged.
func ExpandPathWithURI ¶
ExpandPathWithURI finds the absolute path of a relative path. It uses the given URI to resolve user and cwd so ~ is an alias for a path relative to the base of the URI. See ExpandPath for more details.
Types ¶
type Cmd ¶
type Cmd struct {
Path string
Dir string
Args []string
Env []string
Stdin io.Reader
Stdout io.Writer
Stderr io.Writer
Watcher ProcessWatcher
// SysProcAttr is ignored if passed from a extension.
SysProcAttr *syscall.SysProcAttr
}
Cmd represents an external command being prepared to run. See exec.Cmd for more details. Stdin, Stderr and Stdout, if set, will have their corresponding
type Executor ¶
type Executor interface {
// Start starts the given cmd and returns the Pid of the underlying
// process.
Start(context.Context, Cmd) (Pid, error)
// Signal sends a signal to the running process.
Signal(Pid, syscall.Signal) error
io.Closer
}
Executor is the public facing API of a workspace's command execution.
type File ¶
type File interface {
Name() string
Stat() (os.FileInfo, error)
Sync() error
Truncate(size int64) error
Fd() uintptr
io.Seeker
io.Reader
io.Closer
io.Writer
io.ReaderAt
}
File abstracts a subset of os.File.
type FileSystem ¶
type FileSystem interface {
URI(path string) (URI, error)
// OpenFile opens a file at path with the given flag and mode.
OpenFile(path string, flag int, mode os.FileMode) (File, error)
// Remove removes the file at path.
Remove(path string) error
// Stat returns a FileInfo describing the named file.
Stat(path string) (os.FileInfo, error)
// ReadDir reads the named directory, returning all its directory entries.
ReadDir(name string) ([]os.DirEntry, error)
// MkdirAll creates a directory named path, along with any necessary parents,
// and returns nil, or else returns an error. The permission bits perm (before
// umask) are used for all directories that MkdirAll creates. If path is
// already a directory, MkdirAll does nothing and returns nil.
MkdirAll(path string, perm os.FileMode) error
}
FileSystem abstracts the public facing API of a workspace file system.
type Pid ¶
type Pid int
Pid is an Executor's command identifier. It doesn't necessarily translate to an os.Process.Pid.
type ProcessWatcher ¶
type ProcessWatcher interface {
// The returned error is nil if the command runs, has no problems copying
// stdin, stdout, and stderr, and exits with a zero exit status.
WatchProcess() chan error
}
ProcessWatcher adds the ability for wait a processes started by Cmd and collect any I/O errors or non-zero exit code.
func ChanProcessWatcher ¶
func ChanProcessWatcher(ch chan error) ProcessWatcher
ChanProcessWatcher returns a ProcessWatcher that simply returns ch when Watch is called.
func MultiProcessWatcher ¶
func MultiProcessWatcher(watchers ...ProcessWatcher) ProcessWatcher
MultiProcessWatcher returns a ProcessWatcher that ensures that all the given watchers get notified when the process is done.
type Pty ¶
type Pty struct {
// Master is the pty master device file.
Master File
// Slave is the pseudoterminal slave device path.
Slave File
}
Pty is a pseudoterminal on a Workspace.
type Terminal ¶
type Terminal interface {
// StartPty creates a new pseudoterminal.
StartPty() (Pty, error)
// SetPtySize sets the width and height in columns and rows of
// a pseudoterminal.
SetPtySize(p Pty, width, height int) error
}
Terminal abstracts the ability to manage pseudoterminals.
type URI ¶
type URI struct {
// contains filtered or unexported fields
}
URI represents a parsed URI reference.
func CurrentUserHostURI ¶
CurrentUserHostURI builds a URI from a path. If path is relative it uses the current working directory as the base of the path and if ~ is used to identify the home directory, the current user's home directory is used as the base. This should only used instead of Manager.URI before a workspace.Manager is constructed or for other advanced uses cases.
func Join ¶
Join joins any number of path elements into this URI's path, separating them with slashes. For more details see path.Join.
func ParseURI ¶
ParseURI parses s as a URI in the form of: [scheme:][//[userinfo@]host][/]path[?query][#fragment]
func RandomURI ¶
RandomURI generates a random URI with the given scheme.
Under the hood it uses math.Rand so clients can manage seeding the default rand.Source, if desired.
func WithPath ¶
WithPath maps the given URI to returns a URI with the same components but path set to path.
func (URI) Hostname ¶
Hostname returns the hostname of this URI or an empty string if hostname is not specified.
func (URI) Password ¶
Password returns the password of this URI or an empty string if a password is not specified.