docopt 0.6.6

docopt 0.6.6

测试已测试
Lang语言 SwiftSwift
许可证 MIT
发布最新发布2017年10月
SwiftSwift 版本4.0
SPM支持 SPM

Pavel Mazurin 维护。



docopt 0.6.6

  • 作者:
  • Pavel Mazurin

build status

docopt.swiftdocopt 的 Swift 版本

docopt.swift 帮助您轻松地创建最漂亮的命令行界面

Swift

let doc : String = "Not a serious example.\n" +
"\n" +
"Usage:\n" +
"  calculator_example.py <value> ( ( + | - | * | / ) <value> )...\n" +
"  calculator_example.py <function> <value> [( , <value> )]...\n" +
"  calculator_example.py (-h | --help)\n" +
"\n" +
"Examples:\n" +
"  calculator_example.py 1 + 2 + 3 + 4 + 5\n" +
"  calculator_example.py 1 + 2 '*' 3 / 4 - 5    # note quotes around '*'\n" +
"  calculator_example.py sum 10 , 20 , 30 , 40\n" +
"Options:\n" +
"  -h, --help\n"

var args = Process.arguments
args.removeAtIndex(0) // arguments[0] is always the program_name
let result = Docopt.parse(doc, argv: args, help: true, version: "1.0")
println("Docopt result: \(result)")

Objective-C

NSArray *arguments = [[NSProcessInfo processInfo] arguments];
arguments = arguments.count > 1 ? [arguments subarrayWithRange:NSMakeRange(1, arguments.count - 1)] : @[];

NSDictionary *result = [Docopt parse:doc argv:arguments help:YES version:@"1.0" optionsFirst:NO];
NSLog(@"Docopt result:\n%@", result);

安装

Swift

  • 检出 docopt.swift
  • docopt 文件夹添加到您的项目中

Objective-C

  • 检出 docopt.swift
  • 构建 Docopt 目标
  • 向您的项目添加 Docopt.framework

许可证

docopt.swift 采用 MIT 许可证发布。