Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Confirmation Option

Some commands are destructive or irreversible — dropping databases, deleting files, deploying to production. The confirmation option adds a built-in --yes / -y flag that lets users skip an interactive confirmation prompt. This is equivalent to Click’s confirmation_option decorator.

Basic Usage (Confirmation Option)

from argmojo import Command, Argument

def main() raises:
    var cmd = Command("drop", "Drop the database")
    cmd.add_argument(
        Argument("name", help="Database name").positional().required()
    )
    cmd.confirmation_option()

    var result = cmd.parse()
    # Without --yes: prompts "Are you sure? [y/N]: "
    # With --yes or -y: skips the prompt
    print("Dropping database:", result.get_string("name"))

Running without --yes:

$ ./drop mydb
Are you sure? [y/N]: y
Dropping database: mydb

Running with --yes:

$ ./drop mydb --yes
Dropping database: mydb

Custom Prompt Text (Confirmation Option)

Use the compile-time parameter overload to set a custom prompt:

cmd.confirmation_option["Drop the database? This cannot be undone."]()

This changes the prompt to:

Drop the database? This cannot be undone. [y/N]: 

Using with Subcommands (Confirmation Option)

Confirmation works naturally with subcommands. The --yes flag is registered on the command that calls confirmation_option():

var app = Command("app", "My app")
app.confirmation_option()

var deploy = Command("deploy", "Deploy to production")
deploy.add_argument(Argument("env", help="Environment").positional().required())
app.add_subcommand(deploy^)

var result = app.parse()
# app --yes deploy prod  →  skips confirmation

Non-Interactive Use (Confirmation Option)

When stdin is not available (piped input, CI environments, /dev/null), the confirmation prompt cannot be displayed. In this case, the command aborts with an error unless --yes is passed. This ensures that destructive commands never run silently without explicit opt-in:

$ echo "" | ./drop mydb
error: drop: Aborted (no interactive input available)

$ ./drop mydb --yes    # works in CI
Dropping database: mydb