Skip to content

markusgrotz/click-prompt

Repository files navigation

click-prompt

Supported Python Versions PyPI version License Code style Downloads/Month

click-prompt extends the Click command-line interface library by adding intuitive, interactive prompts. It's perfect for building more user-friendly CLI tools.

This library is inspired by a post on stackoverflow.com.

Contributions are welcome! Open a pull request or submit an issue.

Installation

To install click-prompt, use pip:

pip install click-prompt

Usage

Here’s a basic example using the choice_option decorator:

import click
from click_prompt import choice_option

@click.command()
@choice_option('--fruit', type=click.Choice(['Apples', 'Bananas', 'Grapefruits', 'Mangoes']))
def select_fruit(fruit: str):
    """Prompt user to select a fruit from a list."""
    print(f"You selected: {fruit}")

if __name__ == '__main__':
    select_fruit()

Example

For more examples see the file example.py.

Example

Available Decorators

Each of these decorators replaces a click.Option (and also works with click.Argument):

  • choice_option
    Prompt the user to select one (or more with multiple=True) from a list.

  • confirm_option
    Yes/No confirmation prompt.

  • filepath_option
    Prompt the user to select a file path with auto-completion.

  • auto_complete_option
    Input prompt with tab completion from a list of choices.

  • input_text_option
    Prompt the user for free-form text input.

License

This project is licensed under the MIT License. See the LICENSE file for more information.

About

interactive command line options for the click library

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages