4 /// Sets up and returns a new options parser
6 /// - Returns: A Dictionary of Options, and a new CommandLineKit instance
7 func createParser() -> ([String:Option], CommandLineKit) {
9 let parser = CommandLineKit()
10 var flags: [String:Option] = [:]
12 flags["help"] = BoolOption(shortFlag: "h", longFlag: "help", helpMessage: "Prints a help message.")
13 flags["version"] = BoolOption(shortFlag: "v", longFlag: "version", helpMessage: "Prints the version.")
15 flags["enableSource"] = StringOption(shortFlag: "e", longFlag: "enable-source", helpMessage: "Enables a source")
16 flags["disableSource"] = StringOption(shortFlag: "d", longFlag: "disable-source", helpMessage: "Disables a source")
17 flags["resetSource"] = StringOption(shortFlag: "r", longFlag: "reset-source", helpMessage: "Resets a source")
18 flags["listSources"] = BoolOption(shortFlag: "l", longFlag: "list-sources", helpMessage: "Lists all sources")
20 flags["title"] = BoolOption(shortFlag: "t", longFlag: "title", helpMessage: "Shows title of song if true")
22 parser.addOptions(Array(flags.values))
24 return (flags, parser)
29 let (flags, parser) = createParser()
35 parser.printUsage(error)
39 if let helpFlag = flags["help"] as? BoolOption {
40 if helpFlag.value == true {
46 if let versionFlag = flags["version"] as? BoolOption {
47 if versionFlag.value == true {
48 print(Lyricli.version)
53 if let listSourcesFlag = flags["listSources"] as? BoolOption {
54 if listSourcesFlag.value == true {
55 Lyricli.printSources()
60 if let enableSourceFlag = flags["enableSource"] as? StringOption {
61 if let source = enableSourceFlag.value {
62 Lyricli.enableSource(source)
67 if let disableSourceFlag = flags["disableSource"] as? StringOption {
68 if let source = disableSourceFlag.value {
69 Lyricli.disableSource(source)
74 if let resetSourceFlag = flags["resetSource"] as? StringOption {
75 if let source = resetSourceFlag.value {
76 Lyricli.resetSource(source)
81 if let titleFlag = flags["title"] as? BoolOption {
82 if titleFlag.value == true {
87 // Remove any flags so anyone after this gets the unprocessed values
88 let programName: [String] = [CommandLine.arguments[0]]
89 CommandLine.arguments = programName + parser.unparsedArguments