Core CLI: Info & Versions
Relevant source files
The following files were used as context for generating this wiki page:
The Core CLI: Info & Versions system provides the primary interface for users to interact with the regxa package registry client. It encompasses the entrypoint logic, shared command utilities, and the specific implementations for retrieving package metadata and version history. This system is built using the citty framework and acts as an orchestration layer over the core logic, cache, and registry adapters.
The CLI is designed to be "PURL-first," meaning it natively understands Package URLs (PURLs) while also supporting shorthand inputs for ease of use. It handles command registration, argument parsing, error management, and output formatting (both human-readable and JSON).
CLI Architecture & Entrypoint
The CLI entrypoint is located in src/cli.ts. It uses the defineCommand function to structure the application into several subcommands. These subcommands are loaded dynamically to keep the initial startup fast.
The diagram above shows the routing of user input from the main entrypoint to specific command handlers.
Sources: src/cli.ts:4-16, src/commands/AGENTS.md:1-20
Shared Command Infrastructure
All commands in the regxa CLI rely on a shared set of utilities to ensure consistent behavior regarding input resolution and error handling. This logic is centralized in src/commands/shared.ts.
Argument Handling & PURL Resolution
Every command typically includes sharedArgs, which provide standard flags like --json for machine-readable output and --no-cache to bypass the local storage. The resolvePURL function is critical as it normalizes input (e.g., adding the pkg: prefix if missing) and instantiates the appropriate registry client.
| Argument | Type | Description |
|---|---|---|
--json | Boolean | Outputs results in JSON format. |
--no-cache | Boolean | Bypasses the cache decorator and fetches directly from the registry. |
Sources: src/commands/shared.ts:10-25, src/commands/info.ts:36-40
Error Handling Flow
The CLI utilizes a high-level wrapper, withErrorHandling, to catch and format errors from the core library. This ensures that technical exceptions like HTTPError or NotFoundError are presented to the user in a readable format.
The sequence diagram illustrates how errors from the underlying registry calls are intercepted by the shared command wrapper.
Sources: src/commands/shared.ts:30-45, src/commands/AGENTS.md:30-35
Metadata Retrieval (info)
The info command retrieves and displays comprehensive metadata for a specific package. It identifies the ecosystem, license, repository, and latest version.
Logic Flow
- Resolves the PURL from the command line argument.
- Calls
reg.fetchPackage(name). - If
--jsonis active, it prints the rawPackageobject. - Otherwise, it executes
outputPackageInfoto generate a formatted console output.
Documentation URL Resolution
The info command includes logic to display a documentation link. It uses resolveDocsUrl and compares the result against the homepage and repository URLs; if the documentation URL is unique, it is displayed in the output.
Sources: src/commands/info.ts:8-30, src/commands/info.ts:50-65
Version History (versions)
The versions command provides a chronological or list-based view of all published versions for a given package.
Configuration
Users can control the output volume using the --limit (or -l) flag, which defaults to 20.
Version Output Details
The command iterates through the list returned by reg.fetchVersions(name) and highlights specific metadata:
- Status: Versions marked as
yankedordeprecatedare flagged with a color-coded status. - Publication Date: The date is extracted from
v.publishedAtand formatted to YYYY-MM-DD.
for (const v of shown) {
const status = v.status ? ` \x1b[33m[${v.status}]\x1b[0m` : "";
const date = v.publishedAt
? ` \x1b[90m${v.publishedAt.toISOString().slice(0, 10)}\x1b[0m`
: "";
consola.log(` ${v.number}${status}${date}`);
}
Sources: [src/commands/versions.ts:25-45](https://github.com/agntn/registries/blob/HEAD/0m%60%20%3A%20%22%22%3B%0A%20%20const%20date%20%3D%20v.publishedAt%0A%20%20%20%20? \x1b[90m${v.publishedAt.toISOString().slice(0, 10)}\x1b[0m
: "";
consola.log( ${v.number}${status}${date});
}
Sources: [src/commands/versions.ts:25-45), [src/core/types.ts:16-23](https://github.com/agntn/registries/blob/HEAD/src/core/types.ts#L16-L23)
## Summary
The Core CLI system provides a streamlined, developer-friendly interface for querying package metadata and versions. By leveraging shared utilities for PURL resolution and error management, it maintains a consistent user experience across diverse ecosystems like npm, PyPI, and crates.io. The separation of command orchestration from registry-specific logic ensures the CLI remains lightweight and extensible.