https://github.com/docopt/docopt.swift
A command-line interface description language and parser that will make you smile http://docopt.org/
https://github.com/docopt/docopt.swift
argument-parser command-line docopt swift
Last synced: 7 months ago
JSON representation
A command-line interface description language and parser that will make you smile http://docopt.org/
- Host: GitHub
- URL: https://github.com/docopt/docopt.swift
- Owner: docopt
- License: mit
- Created: 2015-03-04T20:40:06.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2018-11-24T17:22:21.000Z (about 7 years ago)
- Last Synced: 2025-06-08T04:43:03.552Z (7 months ago)
- Topics: argument-parser, command-line, docopt, swift
- Language: Swift
- Size: 130 KB
- Stars: 52
- Watchers: 10
- Forks: 18
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README

``docopt.swift`` is a Swift port of [docopt](https://github.com/docopt/docopt)
======================================================================
**docopt.swift** helps you create most beautiful command-line interfaces *easily*:
Swift:
``` Swift
let doc : String = """
Not a serious example.
Usage:
calculator_example.py ( ( + | - | * | / ) )...
calculator_example.py [( , )]...
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:
``` 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:
```swift
.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.