Interactive Prompts
Relevant source files
The following files were used as context for generating this wiki page:
Interactive Prompts represent a core UX component of the Daco CLI, providing a structured and user-friendly way to collect configuration data for OpenDPI specifications. The system leverages the huh library to build terminal-based forms that handle data product initialization, connection management, and port configuration.
By using interactive forms, the CLI ensures that user input is validated in real-time before being committed to the project's configuration files. This module abstracts complex input logic into reusable validation functions and shared UI themes.
Sources: internal/prompts/prompts.go:8-10, internal/prompts/init.go:10-33
Core Architecture and Styling
The prompts system is built on top of the Charmbracelet huh and lipgloss libraries. It defines a centralized theme to ensure visual consistency across different command workflows.
Styling and Feedback
The Theme() function provides a base configuration for all CLI forms, specifically handling field separation and focused/blurred state colors. For post-form feedback, the PrintResult function generates a styled summary of the operation's outcome.
| Element | Description | Style/Color |
|---|---|---|
| Focused Title | The title of the currently active input field | #f9ca24 (Yellow) |
| Blurred Title | Titles of inactive or already completed fields | #bababa (Gray) |
| Success Icon | Checkmark used in result summaries | #27ca3f (Green) |
| Field Separator | Vertical spacing between form groups | 1 line margin |
Sources: internal/prompts/prompts.go:13-43
Validation Logic
Validators are implemented as closures to allow for context-aware checks, such as verifying if a name is already taken within an existing map of resources.
identifierValidator: Ensures strings start with a letter/underscore and contain only alphanumeric characters or underscores. It also checks against a map of existing keys to prevent duplicates.requiredValidator: Simple check to ensure a field is not empty.
Sources: internal/prompts/prompts.go:45-73
Form Implementation Workflows
The system provides specific entry points for different CLI operations, each wrapping complex form groups and validation rules.
Initialization Form
The RunInitForm function facilitates the daco init command by collecting essential metadata for a new data product.
Sources: internal/prompts/init.go:10-33
Connection Management
The RunAddNewConnectionForm captures technical details required to establish a data source connection.
| Field | Requirement | Purpose |
|---|---|---|
| Connection Name | Identifier Validator | Unique key for referencing the connection |
| Type | Required | Protocol (e.g., kafka, postgresql, s3) |
| Host | Required | Server address and port |
| Description | Optional | Human-readable context |
Sources: internal/prompts/connection_add.go:10-45
Port Configuration
Port addition involves a two-stage form. The first stage collects metadata, and the second stage (if connections exist) allows the user to link the port to a defined connection.
Sources: internal/prompts/port_add.go:13-64
Selection and Discovery
In addition to data entry, the prompts system is used for resource discovery. When a user executes a command like daco ports describe without arguments, the CLI invokes an interactive selector.
Port Selection
The selectPortToDescribe function retrieves all defined ports from the OpenDPI spec, sorts them alphabetically, and presents them in a filtered list. If a port has a description, it is truncated to 40 characters and displayed as a label.
Sources: internal/commands/ports_describe.go:73-107
Summary of Prompt Components
The following table summarizes the primary functions used to drive the interactive CLI experience:
| Function | Source File | Logic Summary |
|---|---|---|
Theme | prompts.go | Returns a shared huh.Theme with custom Lipgloss styles. |
RunInitForm | init.go | Collects name, version, and description for new products. |
RunAddNewConnectionForm | connection_add.go | Validates and collects server connection parameters. |
RunAddPortForm | port_add.go | Handles port metadata and connection mapping. |
selectPortToDescribe | ports_describe.go | Provides a searchable list of ports for inspection. |
The interactive prompts module ensures that the Daco CLI remains accessible to users while maintaining the strict structural integrity required by the OpenDPI specification.
Sources: internal/prompts/prompts.go:13-23, internal/prompts/init.go:10-33, internal/prompts/connection_add.go:10-45, internal/prompts/port_add.go:13-64, internal/commands/ports_describe.go:73-107