D4rtCliApi class abstract

Programmatic interface to D4rt CLI functionality.

Accessed via the cli global variable in D4rt scripts.

This API provides programmatic access to all REPL commands and functionality, enabling:

  • Script automation of REPL operations
  • Testing of CLI functionality
  • Programmatic code execution and introspection

Example:

// In a D4rt script
cli.cd('/project');
cli.replay('setup.d4rt');

final allClasses = cli.classes();
for (final c in allClasses) {
  print('${c.name}: ${c.methods.length} methods');
}

final result = await cli.eval('1 + 2');
print(result); // 3
Implementers

Constructors

D4rtCliApi()

Properties

configuration → D4rtConfiguration
Get the D4rt bridge configuration.
no setter
currentSessionId String?
Current session ID, or null if no session active.
no setter
d4rt → D4rt
The underlying D4rt interpreter.
no setter
dataDirectory String
The data directory (~/.tom/d4rt or ~/.tom/dcli).
no setter
hashCode int
The hash code for this object.
no setterinherited
isMultilineMode bool
Check if currently in multiline mode.
no setter
multilineBuffer List<String>
Get the current multiline buffer contents.
no setter
multilineMode MultilineMode
Get the current multiline mode type.
no setter
runtime CliRuntime
Access process and platform runtime information.
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
toolName String
The tool name (e.g., 'D4rt', 'DCLI').
no setter

Methods

cd(String path) String
Change current directory. Maps to: cd <path>
classes() List<ClassInfo>
List classes in current environment. Maps to: classes
clear() → void
Clear the screen. Maps to: clear Note: No-op in headless/API mode.
clearMultilineBuffer() → void
Clear multiline buffer without executing.
closeSession() → void
Close the current session.
cwd() String
Show current working directory. Maps to: cwd
define(String name, String template) → void
Create a command alias. Maps to: define <name>=<template>
defines() Map<String, String>
List all defines. Maps to: defines
end() Future
End multiline input and execute. Maps to: .end
enums() List<EnumInfo>
List enums in current environment. Maps to: enums
eval(String expression) Future
Evaluate an expression and return the result.
execute(String source, {String? basePath}) Future<ExecuteResult>
Execute source code as a fresh program. Maps to: .execute <path> (when given source) or D4rt.execute()
executeContinued(String source, {String? basePath}) Future<ExecuteResult>
Execute source code in the current environment (continued). Maps to D4rt.continuedExecute()
executeFile(String path) Future<ExecuteResult>
Execute a file as a fresh program. Maps to: .execute <path>
executes() List<String>
List executable files (*.d4rt.dart). Maps to: executes
expandDefine(String input) String?
Expand a define invocation string (e.g., "@greet World"). Returns null if input doesn't match any define.
file(String path) Future<ExecuteResult>
Execute file in current environment. Maps to: .file <path>
help() String
Show detailed help text. Maps to: help
home() String
Return to data directory (~/.tom/d4rt or ~/.tom/dcli). Maps to: home
imports() List<ImportInfo>
Show imports in current environment. Maps to: imports
info([String? name]) SymbolInfo?
Show details and suggestions for a symbol. Maps to: info [name]
invokeDefine(String name, [List<String>? args]) String?
Invoke a define with arguments. Maps to: @<name> [args]
load(String path) Future<int>
Replay file with output. Maps to: .load <path>
loadDefines(String path) int
Load defines from a file. Maps to: .load-defines <path>
loadFile(String path) String
Load file contents (*.exec.dart). Replaces: .print-file <path>
loadReplay(String path) String
Load replay contents (*.replay.txt). Replaces: .print-replay <path>
loadScript(String path) String
Load script contents (*.script.txt). Replaces: .print-script <path>
loadSession(String sessionId) String
Load session contents (*.session.txt). Replaces: .print-session <name>
ls([String? path]) List<String>
List all files in current (or specified) directory. Maps to: ls
methods() List<FunctionInfo>
List methods/functions in current environment. Maps to: methods
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
plays() List<String>
List replay files (*.d4rt for D4rt, *.dcli for DCli). Maps to: plays
processPrompt(String line) Future
Process a command line as if entered interactively.
processPrompts(List<String> lines, {bool continueOnError = false}) Future<List>
Process multiple prompts in sequence.
registeredClasses() List<ClassInfo>
List registered bridge classes. Maps to: registered-classes
registeredEnums() List<EnumInfo>
List registered bridge enums. Maps to: registered-enums
registeredImports() List<ImportInfo>
List registered bridge imports. Maps to: registered-imports
registeredMethods() List<FunctionInfo>
List registered bridge methods. Maps to: registered-methods
registeredVariables() List<VariableInfo>
List registered bridge variables. Maps to: registered-variables
replay(String path) Future<int>
Replay file silently. Maps to: .replay <path>
reset({String? replayPath}) Future<void>
Reset environment, optionally replay session/file. Maps to: .reset [name]
script(String path) Future<int>
Load file line-by-line as script. Maps to: .script <path>
scripts() List<String>
List script files (*.script.txt). Maps to: scripts
session(String sessionId) Future<void>
Switch to a session. Maps to: .session <name>
sessions() List<String>
List session IDs. Maps to: sessions
showInit() String
Show initialization source. Maps to: show-init
startDefine() → void
Start multiline define mode (functions/classes persist). Maps to: .start-define
startExecute() → void
Start multiline execute mode (run as fresh program). Maps to: .start-execute
startFile() → void
Start multiline file mode (run as file in current environment). Maps to: .start-file
startScript() → void
Start multiline script mode (run code block with return value). Maps to: .start-script
toString() String
A string representation of this object.
inherited
undefine(String name) bool
Remove a command alias. Maps to: undefine <name>
variables() List<VariableInfo>
List variables in current environment. Maps to: variables

Operators

operator ==(Object other) bool
The equality operator.
inherited