repl

package
v0.18.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2026 License: MIT Imports: 30 Imported by: 0

Documentation

Overview

Package repl provides a REPL and CLI functionality for aRPC connections.

Index

Constants

View Source
const APrefix = "am_repl"

Variables

View Source
var ErrSyntax = errors.New("syntax error")
View Source
var Sp = utils.Sp

Functions

func AddErrSyntax

func AddErrSyntax(
	event *am.Event, mach *am.Machine, err error, args am.A,
) error

AddErrSyntax wraps an error in the ErrSyntax sentinel and adds to a machine.

func InspectingCmds

func InspectingCmds(repl *Repl) []*cobra.Command

func ListingFlags

func ListingFlags(cmd *cobra.Command)

func LogArgs

func LogArgs(args am.A) map[string]string

LogArgs is an args logger for A and rpc.A.

func MutationCmds

func MutationCmds(repl *Repl) []*cobra.Command

func MutationFlags

func MutationFlags(repl ReplApi, cmd *cobra.Command, groupCmd bool)

func NewRootCommand

func NewRootCommand(repl *Repl, cliArgs, osArgs []string) *cobra.Command

func Pass

func Pass(args *A) am.A

Pass prepares am.A from A to pass to further mutations.

func ReplCmds

func ReplCmds(repl *Repl) []*cobra.Command

func SysCmds

func SysCmds(repl *Repl) []*cobra.Command

func WaitingCmds

func WaitingCmds(repl *Repl) []*cobra.Command

Types

type A

type A struct {
	Id     string   `log:"id"`
	Addrs  []string `log:"addr"`
	Lines  []string
	States []string `log:"states"`
	// machine ID
	MachId string `log:"mach"`
	// list of machine IDs
	MachIds []string
	// Mutation arguments passed from a Cobra cmd handler.
	MutArgs [2][]string
	// Arguments passed to the CLI from the shell
	CliArgs []string
	// RpcCh is a return channel for a list of [rpc.NetworkMachine]. It has to be
	// buffered or the mutation will fail.
	RpcCh       chan<- []*rpc.Client
	ListFilters *ListFilters
}

A is a struct for node arguments. It's a typesafe alternative to am.A.

func ParseArgs

func ParseArgs(args am.A) *A

ParseArgs extracts A from am.Event.ArgsAPrefix.

type History

type History struct {
	// contains filtered or unexported fields
}

func (*History) Dump

func (h *History) Dump() interface{}

Dump returns the entire history file.

func (*History) GetLine

func (h *History) GetLine(pos int) (string, error)

GetLine returns a specific line from the history file.

func (*History) Len

func (h *History) Len() int

Len returns the number of items in the history file.

func (*History) Write

func (h *History) Write(s string) (int, error)

Write item to history file.

type HistoryItem

type HistoryItem struct {
	Index    int
	DateTime time.Time
	Block    string
}

type ListFilters

type ListFilters struct {
	IdExact  string
	IdSubstr string
	IdRegexp *regexp.Regexp
	IdPrefix string
	IdSuffix string
	Parent   string

	MtimeMin    uint64
	MtimeMax    uint64
	MtimeStates S

	StatesActive   S
	StatesInactive S

	Limit    int
	StartIdx int

	// Include never connected machines
	NoSchema bool
	// Exclude disconnected machines
	SkipDisconn bool
}

TODO merge with pkg/pubsub and pkg/integrations TODO extract to pkg/helpers.Group

type Repl

type Repl struct {
	// TODO JSON output
	*am.ExceptionHandler

	Mach *am.Machine
	// Addrs ending with /* are WebSockets
	// TODO keep NAMED addresses eg CLI0, filename1, filename2, CLI1
	//  and manipulate when watching for changes, keeping the prev ones
	Addrs []string
	Cmd   *cobra.Command
	C     *console.Console
	// am-dbg address for new clients
	DbgAddr string
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, id string) (*Repl, error)

func (*Repl) AddrChangedEnter added in v0.12.0

func (r *Repl) AddrChangedEnter(e *am.Event) bool

func (*Repl) AddrChangedState added in v0.12.0

func (r *Repl) AddrChangedState(e *am.Event)

TODO avoid a full restart

func (*Repl) CmdAddEnter

func (r *Repl) CmdAddEnter(e *am.Event) bool

func (*Repl) CmdAddState

func (r *Repl) CmdAddState(e *am.Event)

func (*Repl) CmdGroupAddEnter

func (r *Repl) CmdGroupAddEnter(e *am.Event) bool

func (*Repl) CmdGroupAddState

func (r *Repl) CmdGroupAddState(e *am.Event)

func (*Repl) CmdGroupRemoveEnter

func (r *Repl) CmdGroupRemoveEnter(e *am.Event) bool

func (*Repl) CmdGroupRemoveState

func (r *Repl) CmdGroupRemoveState(e *am.Event)

func (*Repl) CmdRemoveEnter

func (r *Repl) CmdRemoveEnter(e *am.Event) bool

func (*Repl) CmdRemoveState

func (r *Repl) CmdRemoveState(e *am.Event)

func (*Repl) ConnectedExit

func (r *Repl) ConnectedExit(e *am.Event) bool

func (*Repl) ConnectedFullyEnter

func (r *Repl) ConnectedFullyEnter(e *am.Event) bool

func (*Repl) ConnectedFullyExit

func (r *Repl) ConnectedFullyExit(e *am.Event) bool

func (*Repl) ConnectedState

func (r *Repl) ConnectedState(e *am.Event)

func (*Repl) ConnectingEnter

func (r *Repl) ConnectingEnter(e *am.Event) bool

func (*Repl) ConnectingExit

func (r *Repl) ConnectingExit(e *am.Event) bool

func (*Repl) ConnectingState

func (r *Repl) ConnectingState(e *am.Event)

func (*Repl) DisconnectedState

func (r *Repl) DisconnectedState(e *am.Event)

func (*Repl) DisconnectingState

func (r *Repl) DisconnectingState(e *am.Event)

func (*Repl) ErrNetworkState added in v0.12.0

func (r *Repl) ErrNetworkState(e *am.Event)

func (*Repl) ListMachines

func (r *Repl) ListMachines(filters *ListFilters) ([]*arpc.Client, error)

func (*Repl) ListMachinesEnter

func (r *Repl) ListMachinesEnter(e *am.Event) bool

func (*Repl) ListMachinesState

func (r *Repl) ListMachinesState(e *am.Event)

func (*Repl) NetMach added in v0.17.1

func (r *Repl) NetMach(machId string) *arpc.NetworkMachine

NetMach returns an RPC worker with a given ID, or nil.

func (*Repl) NetMachArgs added in v0.17.1

func (r *Repl) NetMachArgs(machId string) []string

NetMachArgs returns a list of registered typed args for a given machine.

func (*Repl) Print

func (r *Repl) Print(txt string, args ...any)

func (*Repl) PrintErr

func (r *Repl) PrintErr(txt string, args ...any)

func (*Repl) PrintMsg

func (r *Repl) PrintMsg(txt string, args ...any)

PrintMsg prints a message about the prompt.

func (*Repl) ReplModeState

func (r *Repl) ReplModeState(e *am.Event)

func (*Repl) RpcConnEnter added in v0.12.0

func (r *Repl) RpcConnEnter(e *am.Event) bool

func (*Repl) RpcConnState

func (r *Repl) RpcConnState(e *am.Event)

func (*Repl) RpcDisconnEnter added in v0.12.0

func (r *Repl) RpcDisconnEnter(e *am.Event) bool

func (*Repl) RpcDisconnState

func (r *Repl) RpcDisconnState(e *am.Event)

func (*Repl) StartEnter

func (r *Repl) StartEnter(e *am.Event) bool

func (*Repl) StartState

func (r *Repl) StartState(e *am.Event)

type ReplApi added in v0.17.1

type ReplApi interface {
	NetMachArgs(machId string) []string
}

type S

type S = am.S

type T

type T = am.Time

Directories

Path Synopsis
Package states contains a stateful schema-v2 for Repl.
Package states contains a stateful schema-v2 for Repl.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL