InquirerPy icon indicating copy to clipboard operation
InquirerPy copied to clipboard

Add extra information to Choice

Open Gracecr opened this issue 2 years ago • 4 comments

This adds Choice.instruction.

tmp2

Supports all prompts that use Choice.

I've only added support for Alternative Syntax, but am open to adding support for Classic syntax if you'd like.

Closes #55.

Gracecr avatar Feb 13 '23 16:02 Gracecr

@kazhala hate to be a bother, but would you mind giving this PR a look when you get a chance?

Gracecr avatar Apr 26 '23 15:04 Gracecr

@Gracecr this is a nice add. While testing it out it seems that instruction is a required attribute despite it being marked optional?

i.e. if instruction isn't defined then you end up with a lengthy stack trace error ending in: TypeError: can only concatenate str (not "NoneType") to str

e.g. removing instruction attribute from the below example results the mentioned error.

from InquirerPy import inquirer
from InquirerPy.base.control import Choice

region = inquirer.select(
        message="Select regions:",
        choices=[
            Choice("ap-southeast-2", name="Sydney", instruction="Region in Australia"),
            Choice("ap-southeast-1", name="Singapore", instruction="Region in Southeast Asia"),
        ],
    ).execute()

Might be worth looking into?

exastone avatar Aug 21 '23 04:08 exastone

Strange, I'm not getting the same error. I'm able to run your example code (minus the instruction's) without error:

from InquirerPy import inquirer
from InquirerPy.base.control import Choice

region = inquirer.select(
    message="Select regions:",
    choices=[
        Choice("ap-southeast-2", name="Sydney"),
        Choice("ap-southeast-1", name="Singapore"),
    ],
).execute()

I just tested with py3.7 and py3.10 on windows in CMD. If you don't mind posting your stack trace, perhaps that will help me resolve the issue.

Gracecr avatar Oct 03 '23 21:10 Gracecr

@kazhala any chance you could take a look into this? I find it really helpful

lt-mayonesa avatar Mar 30 '24 10:03 lt-mayonesa