repl

package
v0.19.8 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: MIT Imports: 36 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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 (
	Sp   = utils.Sp
	Pass = am.Pass
)
View Source
var (
	CmdRoot = CmdName{"arpc"}

	CmdAdd         = CmdName{"add"}
	CmdRemove      = CmdName{"remove"}
	CmdSet         = CmdName{"set"}
	CmdGroupAdd    = CmdName{"group-add"}
	CmdGroupRemove = CmdName{"group-remove"}
	CmdGroupSet    = CmdName{"group-set"}

	CmdWhen     = CmdName{"when"}
	CmdWhenNot  = CmdName{"when-not"}
	CmdWhenTime = CmdName{"when-time"}

	CmdList    = CmdName{"list"}
	CmdMach    = CmdName{"mach"}
	CmdTime    = CmdName{"time"}
	CmdInspect = CmdName{"inspect"}
	CmdStatus  = CmdName{"status"}

	CmdScript     = CmdName{"script"}
	CmdExit       = CmdName{"exit"}
	CmdCheatsheet = CmdName{"cheatsheet"}
	CmdConnect    = CmdName{"connect"}

	CmdNames = enum.New(CmdRoot,
		CmdAdd, CmdRemove, CmdSet, CmdGroupAdd, CmdGroupRemove, CmdGroupSet,
		CmdWhen, CmdWhenNot, CmdWhenTime,
		CmdList, CmdMach, CmdTime, CmdInspect, CmdStatus,
		CmdScript, CmdExit, CmdCheatsheet, CmdConnect)
)
View Source
var (
	// CLI flags (root command)
	FlagCliFile         = FlagName{"file"}
	FlagCliFileShort    = FlagName{"f"}
	FlagCliDir          = FlagName{"dir"}
	FlagCliDirShort     = FlagName{"d"}
	FlagCliWatch        = FlagName{"watch"}
	FlagCliWatchShort   = FlagName{"w"}
	FlagCliAmDbgAddr    = FlagName{"am-dbg-addr"}
	FlagCliLogLevel     = FlagName{"log-level"}
	FlagCliLivepage     = FlagName{"livepage"}
	FlagCliLivepageAddr = FlagName{"livepage-addr"}
	FlagCliReqAll       = FlagName{"req-all"}
	FlagCliReqAllShort  = FlagName{"a"}

	// mutations
	FlagArg = FlagName{"arg"}
	FlagVal = FlagName{"val"}

	// listing
	FlagActive           = FlagName{"active"}
	FlagActiveShort      = FlagName{"a"}
	FlagInactive         = FlagName{"inactive"}
	FlagInactiveShort    = FlagName{"i"}
	FlagMtimeStates      = FlagName{"mtime-states"}
	FlagMtimeStatesShort = FlagName{"m"}
	FlagMtimeMin         = FlagName{"mtime-min"}
	FlagMtimeMinShort    = FlagName{"t"}
	FlagMtimeMax         = FlagName{"mtime-max"}
	FlagMtimeMaxShort    = FlagName{"T"}
	FlagParent           = FlagName{"parent"}
	FlagParentShort      = FlagName{"P"}
	FlagIdRegexp         = FlagName{"id-regexp"}
	FlagIdRegexpShort    = FlagName{"r"}
	FlagIdPartial        = FlagName{"id-partial"}
	FlagIdPartialShort   = FlagName{"I"}
	FlagIdPrefix         = FlagName{"id-prefix"}
	FlagIdPrefixShort    = FlagName{"p"}
	FlagIdSuffix         = FlagName{"id-suffix"}
	FlagIdSuffixShort    = FlagName{"s"}
	FlagLimit            = FlagName{"limit"}
	FlagLimitShort       = FlagName{"l"}
	FlagFrom             = FlagName{"from"}
	FlagFromShort        = FlagName{"f"}

	// waiting
	FlagState      = FlagName{"state"}
	FlagStateShort = FlagName{"s"}
	FlagTime       = FlagName{"time"}
	FlagTimeShort  = FlagName{"t"}

	// inspecting
	FlagStates         = FlagName{"states"}
	FlagStatesShort    = FlagName{"z"}
	FlagStatesAll      = FlagName{"states-all"}
	FlagStatesAllShort = FlagName{"Z"}
	FlagDisconn        = FlagName{"disconn"}
	FlagDisconnShort   = FlagName{"d"}
	FlagAll            = FlagName{"all"}
	FlagSum            = FlagName{"sum"}
)
View Source
var (
	GroupMutating   = GroupId{"mutating"}
	GroupWaiting    = GroupId{"waiting"}
	GroupInspecting = GroupId{"inspecting"}
	GroupRepl       = GroupId{"repl"}
)
View Source
var ErrSyntax = errors.New("syntax error")

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. TODO align with manual.md version, return am.Result

func InspectingCmds

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

func ListingFlags

func ListingFlags(cmd *cobra.Command)

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 ReplCmds

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

ReplCmds are cmds present only in the REPL, not CLI.

func SysCmds

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

func WaitingCmds

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

Types

type A

type A struct {
	Args `json:"-"`

	Id     string      `log:"id"`
	Addrs  []NamedAddr `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.

type Args added in v0.19.0

type Args struct {
	am.ArgsBase `json:"-"`
}

Args is shared pkg args for Any state

func (Args) ArgsPrefix added in v0.19.0

func (Args) ArgsPrefix() string

type CmdName added in v0.19.7

type CmdName enum.Member[string]

CmdName is a REPL command name.

type FlagName added in v0.19.7

type FlagName enum.Member[string]

FlagName is a REPL flag name, long or short. Repeated shorthand values are intentional, eg -a is used by --req-all and --active.

type GroupId added in v0.19.7

type GroupId enum.Member[string]

GroupId is a CLI command group Id.

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 {
	amhelp.MachGroupFilter

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

ListFilters are REPL-specific machine filters, based on amhelp.MachGroupFilter.

type NamedAddr added in v0.19.7

type NamedAddr struct {
	Name   string
	Addr   string
	Manual bool
}

NamedAddr is a named machine address. Names are stable across address file refreshes, and Addr may end with /* for WebSockets. Manual addresses are added from the REPL and survive watched address file updates.

type Repl

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

	Mach *am.Machine
	// Addrs are named addresses, ending with /* for WebSockets. Names are
	// stable across watched address file changes, keeping existing connections.
	Addrs []NamedAddr
	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)

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) CmdGroupSetEnter added in v0.19.7

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

func (*Repl) CmdGroupSetState added in v0.19.7

func (r *Repl) CmdGroupSetState(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) CmdSetEnter added in v0.19.7

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

func (*Repl) CmdSetState added in v0.19.7

func (r *Repl) CmdSetState(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) Machine added in v0.19.7

func (r *Repl) Machine() *am.Machine

Machine returns the REPL state machine.

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