]> git.r.bdr.sh - rbdr/lyricli/blob - Sources/main.swift
61f4f7154e11a8acbd658186d835a39da65274e3
[rbdr/lyricli] / Sources / main.swift
1 import CommandLineKit
2 import Foundation
3
4 /// Sets up and returns a new options parser
5 ///
6 /// - Returns: A new OptionParser instance
7 func createParser() -> ([String:Option], CommandLineKit) {
8
9 let parser = CommandLineKit()
10 var flags: [String:Option] = [:]
11
12 flags["help"] = BoolOption(shortFlag: "h", longFlag: "help", helpMessage: "Prints a help message.")
13
14 parser.addOptions(Array(flags.values))
15
16 return (flags, parser)
17 }
18
19 func main() {
20
21 let (flags, parser) = createParser()
22
23 do {
24 try parser.parse()
25 }
26 catch {
27 parser.printUsage(error)
28 exit(EX_USAGE)
29 }
30
31 if let helpFlag = flags["help"] as? BoolOption {
32 if helpFlag.value == true {
33 parser.printUsage()
34 exit(0)
35 }
36 }
37
38 }
39
40 main()