ask-yn

Crates.ioask-yn
lib.rsask-yn
version0.3.0
created_at2025-10-31 16:54:29.236178+00
updated_at2025-12-20 15:13:25.014793+00
descriptionTerminal utility program to prompt the user to answer yes or no.
homepagehttps://github.com/zfzackfrost/ask-yn
repositoryhttps://github.com/zfzackfrost/ask-yn
max_upload_size
id1910329
size13,131
Zachary Frost (zfzackfrost)

documentation

README

ask-yn

Terminal utility program to prompt the user to answer yes or no.

Example usage

Simplest Usage — No Default Argument

Without a default argument, the program with ask the user again if no input is given.

if ask-yn "Do a task?"; then
    echo "Doing a task"
else
    echo "Task canceled"
fi

The output in this case should look something like the following. Program output is in bold, user input is in italic:

Do a task? [y/n] maybe
Unrecognized response! Do a task? [y/n]
Unrecognized response! Do a task? [y/n] yes
Doing a task

With Default Argument

With a default argument, the program will use it when no input is provided.

if ask-yn "Do a task?" -d n; then
    echo "Doing a task"
else
    echo "Task canceled"
fi

The output in this case should look something like the following. Program output is in bold, user input is in italic:

Do a task? [y/N] maybe
Unrecognized response! Do a task? [y/N]
Task canceled

Invert Return code

The -i/--invert flag in this program inverts the return code. With this flag, the program will return a 1 when given a yes answer and a 0 otherwise.

if ask-yn "Don't do a task?" -i; then
    echo "Task canceled"
else
    echo "Doing a task"
fi
Commit count: 0

cargo fmt