Skip to content

Extract require_confirmation() helper to de-duplicate CLI cancel pattern #78

@Desel72

Description

@Desel72

Problem

The click.confirm → print [yellow]Cancelled[/yellow] → early-return pattern repeats 7 times across 5 CLI files (verified against upstream test):

if not click.confirm('...'):
    console.print('[yellow]Cancelled[/yellow]')
    return

Callsites (non-admin):

  • allways/cli/swap_commands/claim.py:41
  • allways/cli/swap_commands/collateral.py:88, 174
  • allways/cli/swap_commands/miner_commands.py:293
  • allways/cli/swap_commands/pair.py:188
  • allways/cli/swap_commands/swap.py:528, 698

Proposal

Add a small helper to allways/cli/swap_commands/helpers.py:

def require_confirmation(prompt: str, default: bool = False) -> bool:
    """Prompt for Y/N confirmation; print a cancel notice and return False on decline.

    Returns True only when the user accepts. Callers should early-return on False.
    """
    if not click.confirm(prompt, default=default):
        console.print('[yellow]Cancelled[/yellow]')
        return False
    return True

Each callsite collapses to:

if not require_confirmation('...'):
    return

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions