Prompts

Interactive prompts for collecting user input in CLI commands. Nimbus provides five built-in prompt types via the cli/ui package, accessible through ctx.UI in any command.

Text Input

Prompt for a single line of text with an optional default value:

func SetupCommand(ctx *cli.Context) error {
    name, err := ctx.UI.AskInput("Model name:", "User")
    if err != nil {
        return err
    }
    ctx.UI.Successf("Creating model: %s", name)
    return nil
}

Password Input

Prompt for sensitive input — characters are hidden as the user types:

secret, err := ctx.UI.AskPassword("Database password:")
if err != nil {
    return err
}
// secret contains the password, never echoed to terminal

Confirmation

Ask a yes/no question with a default value:

confirmed, err := ctx.UI.AskConfirm("Run migrations?", true)
if err != nil {
    return err
}
if confirmed {
    // run migrations
}

Single Select

Present a list and let the user pick one option with arrow keys:

driver, err := ctx.UI.AskSelect("Database driver:", []string{
    "postgres",
    "mysql",
    "sqlite",
}, "postgres")
if err != nil {
    return err
}
ctx.UI.Infof("Selected: %s", driver)

Multi Select

Checkbox-style selection — the user can pick multiple options with space, then confirm with enter:

plugins, err := ctx.UI.AskMultiSelect("Enable plugins:", []string{
    "auth",
    "inertia",
    "transmit",
    "pulse",
    "horizon",
}, []string{"auth"}) // "auth" pre-selected
if err != nil {
    return err
}
for _, p := range plugins {
    ctx.UI.Successf("Enabled: %s", p)
}

Prompt Reference

MethodSignatureReturns
AskInputAskInput(label, default string)(string, error)
AskPasswordAskPassword(label string)(string, error)
AskConfirmAskConfirm(label string, def bool)(bool, error)
AskSelectAskSelect(label string, options []string, def string)(string, error)
AskMultiSelectAskMultiSelect(label string, options, defaults []string)([]string, error)

Styled Output

The same ctx.UI object provides styled output helpers powered by lipgloss:

ctx.UI.Successf("Created %s successfully", name)  // green ✓
ctx.UI.Warnf("SSL expires in %d days", 30)          // yellow ⚠
ctx.UI.Errorf("Migration failed: %v", err)           // red ✖
ctx.UI.Infof("Using driver: %s", driver)             // blue ℹ

// Boxed panel
ctx.UI.Panel("Server Started", "Local: http://localhost:3333\nNetwork: http://192.168.1.5:3333")

Complete Command Example

package commands

import (
    "github.com/CodeSyncr/nimbus/cli"
    "github.com/spf13/cobra"
)

func SetupCmd() *cobra.Command {
    return &cobra.Command{
        Use:   "setup",
        Short: "Interactive project setup",
        RunE: func(cmd *cobra.Command, args []string) error {
            ctx := cli.NewContext(cmd, args)

            name, _ := ctx.UI.AskInput("Project name:", "my-app")
            driver, _ := ctx.UI.AskSelect("Database:", []string{
                "postgres", "mysql", "sqlite", "mongodb",
            }, "postgres")
            plugins, _ := ctx.UI.AskMultiSelect("Plugins:", []string{
                "auth", "inertia", "transmit", "pulse",
            }, []string{"auth"})
            confirmed, _ := ctx.UI.AskConfirm("Generate scaffolding?", true)

            if confirmed {
                ctx.UI.Successf("Creating %s with %s and %v", name, driver, plugins)
            }
            return nil
        },
    }
}

See also: Terminal UI (tables, stickers, colors), Creating Commands.