Latest 0.1.2
Homepage https://github.com/mpclarkson/Prompter
License MIT
Platforms osx 10.11, requires ARC
Authors

Prompter – Capture Command Line Input with Swift

CI Status
Version
License
Platform

Prompter is lightweight Swift 2+ library that greatly simplifies capturing user input for command line (cli) applications on OSX and Linux.

Specifically, it allows you to prompt the user for input and validate that responses are (currently) String, Int, Bool, or a valid single choice from a given list.

Installation

Swift Package Manager

To add Prompter via the SPM, add the following to your Package.swift file:

let package = Package(
    name: "YourPackageName"
    dependencies: [
        .Package(url: "https://github.com/mpclarkson/Prompter.git", majorVersion: 1),
    ]
)

CocoaPods

Prompter is available through CocoaPods.

To install it, simply add the following line to your Podfile:

pod "Prompter"

Instructions

Documentation

This library is well documented. View the documentation.

Overview

Each ask method includes the following arguments:

  • question – required
  • message – optional string to override the default validation message
  • block – an optional closure that is called on success

import Prompter

let prompt = Prompt()

//Prompt the user for a string input
let name = prompt.askString("What is your name?",
  message: "This is an optional validation message!") { string in
  //this is an optional block
}

//Prompt the user for a string input
let age = prompt.askInt("How old are you?")

//Prompt the user for a Boolean response
//y, Y, Yes, yes, t, True, 1 are all true etc
let age = prompt.askBool("Do you like beans")

//Ask the user to select from a list of choices
let choices = ["beans", "apples"]
let age = prompt.askChoice("Which of these do you prefer",
  choices: choices) { (index, string) in
    print(index, string)
    //0, beans
 }

Todo

  • askDate
  • askMultiple
  • initWithStyle

Tests

Run the tests using xctool:

xctool -workspace Prompter.xcworkspace -scheme Prompter test

Author

Matthew Clarkson from Hilenium @matt_clarkson

License

Prompter is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "Prompter",
    "version": "0.1.2",
    "summary": "Light weight helpers for developing interactive command line (cli) scripts in Swift.",
    "license": {
        "type": "MIT",
        "file": "LICENSE.md"
    },
    "authors": {
        "Matthew Clarkson": "[email protected]"
    },
    "social_media_url": "http://twitter.com/matt_clarkson",
    "platforms": {
        "osx": "10.11"
    },
    "requires_arc": true,
    "source": {
        "git": "https://github.com/mpclarkson/Prompter.git",
        "tag": "0.1.2"
    },
    "homepage": "https://github.com/mpclarkson/Prompter",
    "source_files": "Source/*.{swift}",
    "documentation_url": "http://mpclarkson.github.io/Prompter/"
}

Pin It on Pinterest

Share This