answer: str, _: columbo.Answers) -> columbo.ValidationResponse: canonical_name = canonicalize_name(answer).replace("-", "_") if not canonical_name == answer: error_message = ("Import names should follow PEP-8 naming conventions." f" Did you mean {canonical_name}?") return columbo.ValidationFailure(error=error_message) if not answer.replace("_", "").isalpha(): error_message = ( "Import names may only contain alphabetical characters and underscores. " "They may not contain spaces, numbers, or other characters.") return columbo.ValidationFailure(error=error_message) return columbo.ValidationSuccess() interactions: List[columbo.Interaction] = [ columbo.Echo("Please answer the following questions!"), columbo.BasicQuestion( "full_name", "What is your name?", default="First Last", ), columbo.BasicQuestion( "email", lambda answers: f"What is {answers['full_name']}'s email address?", default="*****@*****.**", ), columbo.BasicQuestion( "github_username", lambda answers: f"What is {answers['full_name']}'s github username?", default="yourGithubUsername", ),
import columbo interactions = [ columbo.Echo("Welcome to the Columbo example"), columbo.Acknowledge("Press enter to start"), columbo.BasicQuestion( "user", "What is your name?", default="Patrick", ), columbo.BasicQuestion( "user_email", lambda answers: f"""What email address should be used to contact {answers["user"]}?""", default="*****@*****.**", ), columbo.Choice( "mood", "How are you feeling today?", options=["happy", "sad", "sleepy", "confused"], default="happy", ), columbo.Confirm("likes_dogs", "Do you like dogs?", default=True), ] answers = columbo.get_answers(interactions) print(answers)
def outcome(answers: columbo.Answers) -> str: if answers.get("has_key", False): return "You try the the key on the lock. With a little jiggling, it finally opens. You open the gate and leave." if answers.get("has_hammer", False): return "You hit the lock with the hammer and it falls to the ground. You open the gate and leave." return ( "Unable to open the gate yourself, you yell for help. A farmer in the nearby field hears you. " "He reaches into his pocket and pulls out a key to unlock the gate and open it. " "As you walk through the archway he says, " '"What I don\'t understand is how you got in there. This is the only key."' ) interactions = [ columbo.Echo( "You wake up in a room that you do not recognize. " "In the dim light, you can see a large door to the left and a small door to the right." ), columbo.Choice( "which_door", "Which door do you walk through?", options=["left", "right"], default="left", ), columbo.Confirm( "has_key", "You step into a short hallway and the door closes behind you, refusing to open again. " "As you walk down the hallway, there is a small side table with a key on it.\n" "Do you pick up the key before going through the door at the other end?", should_ask=went_left, default=True, ),