Docopt

0.6.12

A command-line interface description language and parser that will make you smile http://docopt.org/
elegantchaos/docopt.swift

What's New

0.6.12

2020-02-10T14:40:12Z

Minor fixes for Swift 5.2.

5.2 has a few warnings where a generic method is being overridden with a different signature, eg:

Option.swift:86:19: Overridden method 'singleMatch' has generic signature <T where T : LeafPattern> which is incompatible with base method's generic signature <T where T : Pattern>; expected generic signature to be <T where T : Pattern>.

The fix is to change the constraint back to Pattern so that the signature is consistent, and then perform a dynamic check for a LeafPattern.

build status docopt.swift is a Swift port of docopt

docopt.swift helps you create most beautiful command-line interfaces easily:

Swift:

let doc : String = """
Not a serious example.

Usage:
  calculator_example.py <value> ( ( + | - | * | / ) <value> )...
  calculator_example.py <function> <value> [( , <value> )]...
  calculator_example.py (-h | --help)
  
Examples:
  calculator_example.py 1 + 2 + 3 + 4 + 5
  calculator_example.py 1 + 2 '*' 3 / 4 - 5    # note quotes around '*'
  calculator_example.py sum 10 , 20 , 30 , 40
  
Options:
  -h, --help
"""

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);

Installation

Swift:

  • Check out docopt.swift
  • Add docopt folder to your project

Swift Package Manager:

.package(url: "https://github.com/docopt/docopt.swift", from: "0.6.6"),

Objective-C:

  • Check out docopt.swift
  • Build Docopt target
  • Add Docopt.framework to your project

License

docopt.swift is released under the MIT License.

Description

  • Swift Tools 4.0.0
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Mar 12 2024 10:05:59 GMT-0900 (Hawaii-Aleutian Daylight Time)