Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: Interactive CLI input #947

Merged
merged 2 commits into from
Nov 7, 2024

Conversation

raxhvl
Copy link
Contributor

@raxhvl raxhvl commented Nov 7, 2024

🗒️ Description

This PR adds a set of simple, HTML-like input functions to the cli.input package, which internally use the questionary library to handle various types of interactive CLI inputs. The goal is to provide a simplified API for capturing user input, WITHOUT exposing the details of questionary.

This makes it easy to swap out questionary for another library in the future, without changing the interface. Use away!

Changes

  • New Input Functions:
    • input_text(question: str): Ask a text input question.
    • input_password(question: str): Ask a password input question (hidden text).
    • input_select(question: str, choices: list): Ask a single-choice selection question.
    • input_checkbox(question: str, choices: list): Ask a multi-choice question.
    • input_confirm(question: str): Ask a yes/no confirmation question.

Usage Example

from cli.input import input_checkbox, input_confirm, input_password, input_select, input_text


def main():
    name = input_text("What is your name?")
    password = input_password("Enter your password:")
    color = input_select("Choose your favorite color", choices=["Red", "Green", "Blue"])
    selected_colors = input_checkbox(
        "What colors do you like?", choices=["Red", "Green", "Blue", "Yellow"]
    )
    continue_choice = input_confirm("Do you want to continue?")

    print(f"Hello, {name}!")
    print(f"Password received length {len(password)}.")
    print(f"You selected {color}.")
    print(f"Selected colors: {', '.join(selected_colors)}")
    print("Continuing..." if continue_choice else "Stopping.")


if __name__ == "__main__":
    main()

🔗 Related Issues

closes #945

✅ Checklist

  • All: Set appropriate labels for the changes.
  • All: Considered squashing commits to improve commit history.
  • All: Added an entry to CHANGELOG.md.
  • All: Considered updating the online docs in the ./docs/ directory.
  • Tests: All converted JSON/YML tests from ethereum/tests have been added to converted-ethereum-tests.txt.
  • Tests: A PR with removal of converted JSON/YML tests from ethereum/tests have been opened.
  • Tests: Included the type and version of evm t8n tool used to locally execute test cases: e.g., ref with commit hash or geth 1.13.1-stable-3f40e65.
  • Tests: Ran mkdocs serve locally and verified the auto-generated docs for new tests in the Test Case Reference are correctly formatted.

Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @raxhvl, very clean ✨

One minor comment about versions. Could you plz update uv.lock?

Co-authored-by: danceratopz <[email protected]>
@raxhvl raxhvl requested a review from danceratopz November 7, 2024 11:44
Copy link
Member

@danceratopz danceratopz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @raxhvl!

@danceratopz danceratopz merged commit e69aae5 into ethereum:main Nov 7, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

✨ (cli): Add support for interactive CLI input
2 participants