{"id":13872338,"url":"https://github.com/getGuaka/Prompt","last_synced_at":"2025-07-16T02:30:36.306Z","repository":{"id":63910834,"uuid":"151293904","full_name":"getGuaka/Prompt","owner":"getGuaka","description":"Prompts the user for more information.","archived":false,"fork":false,"pushed_at":"2018-10-04T11:51:20.000Z","size":14,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-11-17T17:35:54.206Z","etag":null,"topics":["agree","ask","choose","cli","command-line","command-line-tool","guaka","prompt","swift","swift-package-manager"],"latest_commit_sha":null,"homepage":null,"language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/getGuaka.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-02T17:19:28.000Z","updated_at":"2021-11-14T15:46:40.000Z","dependencies_parsed_at":"2022-11-29T07:16:43.131Z","dependency_job_id":null,"html_url":"https://github.com/getGuaka/Prompt","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getGuaka%2FPrompt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getGuaka%2FPrompt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getGuaka%2FPrompt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/getGuaka%2FPrompt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/getGuaka","download_url":"https://codeload.github.com/getGuaka/Prompt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226095681,"owners_count":17572970,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["agree","ask","choose","cli","command-line","command-line-tool","guaka","prompt","swift","swift-package-manager"],"created_at":"2024-08-05T23:00:40.327Z","updated_at":"2024-11-23T20:30:54.910Z","avatar_url":"https://github.com/getGuaka.png","language":"Swift","funding_links":[],"categories":["Swift"],"sub_categories":[],"readme":"# Prompt [![Build Status](https://travis-ci.com/getGuaka/Prompt.svg?branch=master)](https://travis-ci.com/getGuaka/Prompt)\n\nPrompts the user for more information.\n\n## Usage\n\n### Ask\nAsk presents the user with a prompt and waits for the user input.\n```swift\nlet userName = ask(\"Enter user name?\")\n```\n`userName` will contain the name entered by the user\n\nAsk can be used to ask for value of Int, Double or Float types, to ask for an integer for example:\n\n```swift\nlet age = ask(\"How old are you?\", type: Int.self)\n```\nIf the user prints something thats not convertible to integer, a new prompt is displayed to him, this prompt will keep displaying until the user enters an Int:\n\n    How old are you?\n    None\n    You must enter a valid Integer.\n    ?  Error\n    You must enter a valid Integer.\n    ?  5\n    5\n\nValidations are added by calling `addInvalidCase` on `AskSettings`.\n\n```swift\nlet name = ask(\"Who are you?\") { settings in\n    settings.addInvalidCase(\"Snuffles is not allowed\") { value in\n        value.containsString(\"Snuffles\")\n    }\n}\n```\nIf the user entered `Snuffles` ask will keep displaying the invalid message passed to `addInvalidCase`\n\n    Who are you?\n    Snuffles\n    Snuffles is not allowed\n    ?  Snuffles\n    Snuffles is not allowed\n    ?  Snowball\n\n    Your name is Snowball\n\n`AskSettings.confirm` will ask the user to confirm his choice after entering it\n\n```swift\nlet name = ask(\"Who are you?\") { settings in\n    settings.confirm = true\n}\n```\n\nThe above will output:\n\n    Who are you?\n    Snuffles\n    Are you sure?  YES\n\n    Your name is Snuffles\n\n### Choose\nChoose is used to prompt the user to select an item between several possible items.\n\nTo display a choice of programming lanaugage for example:\n```swift\nlet choice = choose(\"Whats your favorite programming language? \",\n    choices: \"Swift\", \"Objective C\", \"Ruby\", \"Python\", \"Java :S\")\n```\n\nThis will print:\n\n    1. Swift\n    2. Objective C\n    3. Ruby\n    4. Python\n    5. Java :S\n    Whats your favorite programming language?\n\nThe user can either choose the numbers (1..5) or the item itself. If the user enters a wrong input. A prompt will keep showing until the user makes a correct choice\n\n    Whats your favorite programming language? JavaScript\n    You must choose one of [1, 2, 3, 4, 5, Swift, Objective C, Ruby, Python, Java :S].\n    ?  BBB\n    You must choose one of [1, 2, 3, 4, 5, Swift, Objective C, Ruby, Python, Java :S].\n    ?  Swift\n\n    You selected Swift, good choice!\n\nYou can customize the return value for each choice element. For example if you want to get an Int from the choice, you would do this\n\n```swift\nlet choice = choose(\"Whats your favorite programming language? \", type: Int.self) { settings in\n    settings.addChoice(\"Swift\") { 42 }\n    settings.addChoice(\"Objective C\") { 20 }\n}\n```\n\nThe number on the left can be changed to letters, here is how you could do that:\n\n```siwft\nlet choice = choose(\"Whats your favorite programming language? \", type: String.self) { settings in\n   //choice value will be set to GOOD\n   settings.addChoice(\"Swift\") { \"GOOD\" }\n\n   //choice value will be set to BAD\n   settings.addChoice(\"Java\") { \"BAD\" }\n\n   settings.index = .Letters\n   settings.indexSuffix = \" ----\u003e \"\n   }\n```\n\nThat will print:\n\n    a ----\u003e Swift\n    b ----\u003e Java\n    Whats your favorite programming language?\n\n### Agree\nAgree is used to ask a user for a Yes/No question. It returns a boolean representing the user input.\n\n```swift\nlet choice = agree(\"Are you sure you want to `rm -rf /` ?\")\n```\n\nIf the user enters any invalid input, agree will keep prompting him for a Yes/No question\n\n    Are you sure you want to `rm -rf /` ?  What!\n    Please enter \"yes\" or \"no\".\n    Are you sure you want to `rm -rf /` ?  Wait\n    Please enter \"yes\" or \"no\".\n    Are you sure you want to `rm -rf /` ?  No\n\n    You entered false\n\n## Installation\n\n### Swift Package Manager\n\n```swift\n.package(url: \"https://github.com/getGuaka/Prompt.git\", from: \"0.0.0\"),\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FgetGuaka%2FPrompt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FgetGuaka%2FPrompt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FgetGuaka%2FPrompt/lists"}