8f45b40528
12 funciones Bash del dominio shell: utilidades de scripting (bash_log, bash_colors, bash_check_deps, bash_confirm, bash_handle_error, bash_safe_run), manipulacion de texto (convert_text_case), estructura de proyectos (create_project_structure), y operaciones git (git_clean_branches, git_log_visual, git_push_all_remotes, git_repo_status). Cada una con su .sh y .md de frontmatter.
53 lines
1.7 KiB
Markdown
53 lines
1.7 KiB
Markdown
---
|
|
name: bash_confirm
|
|
kind: function
|
|
lang: bash
|
|
domain: shell
|
|
version: "1.0.0"
|
|
purity: impure
|
|
signature: "bash_confirm(prompt: string, [default: string]) -> exit_code"
|
|
description: "Dialogo interactivo de confirmacion y/n con valor por defecto configurable. Soporta respuestas yes/y/si."
|
|
tags: [bash, confirm, prompt, interactive, dialog]
|
|
uses_functions: [bash_colors_bash_shell]
|
|
uses_types: []
|
|
returns: []
|
|
returns_optional: false
|
|
error_type: "error_go_core"
|
|
imports: []
|
|
params:
|
|
- name: prompt
|
|
desc: "pregunta a mostrar al usuario; default '¿Continuar?'"
|
|
- name: default
|
|
desc: "valor por defecto cuando el usuario presiona Enter sin escribir nada; 'y' o 'n'; default 'n'"
|
|
output: "exit code 0 si el usuario confirma (y/yes/si), exit code 1 si niega o acepta el default negativo"
|
|
tested: false
|
|
tests: []
|
|
test_file_path: ""
|
|
file_path: "bash/functions/shell/bash_confirm.sh"
|
|
source_repo: "https://gitea-dgg044oo04woo4ggcsws4gk0.organic-machine.com/egutierrez/DevLauncher.git"
|
|
source_license: "MIT"
|
|
source_file: "scripts/lib/common.sh"
|
|
---
|
|
|
|
## Ejemplo
|
|
|
|
```bash
|
|
source bash/functions/shell/bash_confirm.sh
|
|
|
|
# Con default no (muestra [y/N])
|
|
if bash_confirm "¿Deseas continuar?"; then
|
|
echo "Continuando..."
|
|
fi
|
|
|
|
# Con default yes (muestra [Y/n])
|
|
bash_confirm "¿Eliminar archivos temporales?" "y" && rm -rf /tmp/cache
|
|
```
|
|
|
|
## Notas
|
|
|
|
El prompt muestra el default en mayuscula: `[Y/n]` cuando default=y, `[y/N]` cuando default=n. Si el usuario presiona Enter sin escribir, se usa el valor por defecto.
|
|
|
|
Acepta variantes: y, Y, yes, YES, si, SI como afirmativo. Cualquier otra respuesta se trata como negativo.
|
|
|
|
Usa colores de `bash_colors` para el prompt en amarillo. Requiere terminal interactiva (lee de stdin con `read -r`).
|