Interfaces
cli-engine defines four core interfaces for dependency injection. You must provide implementations for all of them to use the engine.
FileSystem
Abstracts all file system operations.
typescript
interface FileSystem {
readFile(path: string): string
readFileBinary(path: string): Buffer
writeFile(path: string, content: string): void
writeFileBinary(path: string, content: Buffer): void
exists(path: string): boolean
mkdir(path: string, options?: { recursive?: boolean }): void
readdir(path: string): string[]
stat(path: string): { isDirectory: boolean; isFile: boolean; size: number }
unlink(path: string): void
rmdir(path: string, options?: { recursive?: boolean }): void
copyFile(src: string, dest: string): void
rename(src: string, dest: string): void
}Implementation notes
readFilemust return UTF-8 textreadFileBinarymust return raw bytes as aBuffermkdirwith{ recursive: true }must create parent directoriesstatmust return at minimumisDirectory,isFile, andsizermdirwith{ recursive: true }must remove directory trees
HttpClient
Abstracts HTTP requests. Follows the standard fetch API signature.
typescript
interface HttpClient {
fetch(url: string, options?: RequestInit): Promise<Response>
}Implementation notes
- Must return standard
Responseobjects - Used for registry API calls, tarball downloads, and OCI operations
- The response must support
.json(),.text(),.arrayBuffer(), and.blob()methods
ShellExecutor
Abstracts command execution. Uses array-based arguments for security.
typescript
interface ShellExecutor {
execFile(command: string, args: string[]): string
}Implementation notes
- Arguments must be passed as an array, not concatenated into a string. This prevents shell injection attacks.
- Must return stdout as a string
- Must throw on non-zero exit codes
- Used for tarball extraction (
tar), OCI push operations (oras), and git operations
typescript
// Correct
shell.execFile('tar', ['-xzf', tarballPath, '-C', targetDir])
// Wrong - would allow injection
shell.exec(`tar -xzf ${tarballPath} -C ${targetDir}`)TokenProvider
Abstracts credential retrieval for registries and git hosts.
typescript
interface TokenProvider {
getRegistryToken(scope: string): string | undefined
getGitToken(type: 'github' | 'gitlab', host?: string): string | undefined
}Implementation notes
getRegistryTokenreceives a scope like@myorgand should return the token for that scope's registrygetGitTokenreceives the host type and optional hostname- Returning
undefinedmeans no token is available (anonymous access)