Prompter 0.1.2

Prompter 0.1.2

测试已测试
语言 SwiftSwift
许可协议 MIT
发布最新发布2016年1月
SPM支持SPM

Matthew Clarkson维护。



Prompter 0.1.2

Prompter - 使用Swift捕获命令行输入

Prompter是一个轻量级的Swift 2+库,极大地简化了在OSX和Linux上为命令行(cli)应用程序捕获用户输入。

具体来说,它允许您提示用户进行输入并验证响应是否为(目前)StringIntBool或从给定列表中选择的有效单选选项。

安装

Swift包管理器

要通过SPM添加Prompter,请将以下内容添加到您的Package.swift文件中:

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

说明

文档

此库有很好的文档。查看文档

概述

每个ask方法都包括以下参数

  • question - 必需的
  • message - 可选字符串,用于覆盖默认验证消息
  • block - 可选闭包,在成功时调用
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
 }

待办事项

  • askDate
  • askMultiple
  • initWithStyle

测试

使用xctool运行测试

xctool -workspace Prompter.xcworkspace -scheme Prompter test

作者

来自Hilenium的Matthew Clarkson @matt_clarkson

许可协议

Prompter在MIT许可下提供。有关更多信息,请参阅LICENSE文件。