X-Git-Url: https://git.r.bdr.sh/rbdr/lyricli/blobdiff_plain/026a2f69776d0a8c9e15e560bef4a8a01f510aa0..4425e9001e20e891dab7711644f83a1628788b47:/Sources/main.swift?ds=sidebyside diff --git a/Sources/main.swift b/Sources/main.swift index 61f4f71..0ae48bc 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -3,13 +3,21 @@ import Foundation /// Sets up and returns a new options parser /// -/// - Returns: A new OptionParser instance +/// - Returns: A Dictionary of Options, and a new CommandLineKit instance func createParser() -> ([String:Option], CommandLineKit) { let parser = CommandLineKit() var flags: [String:Option] = [:] flags["help"] = BoolOption(shortFlag: "h", longFlag: "help", helpMessage: "Prints a help message.") + flags["version"] = BoolOption(shortFlag: "v", longFlag: "version", helpMessage: "Prints the version.") + + flags["enableSource"] = StringOption(shortFlag: "e", longFlag: "enable-source", helpMessage: "Enables a source") + flags["disableSource"] = StringOption(shortFlag: "d", longFlag: "disable-source", helpMessage: "Disables a source") + flags["resetSource"] = StringOption(shortFlag: "r", longFlag: "reset-source", helpMessage: "Resets a source") + flags["listSources"] = BoolOption(shortFlag: "l", longFlag: "list-sources", helpMessage: "Lists all sources") + + flags["title"] = BoolOption(shortFlag: "t", longFlag: "title", helpMessage: "Shows title of song if true") parser.addOptions(Array(flags.values)) @@ -30,11 +38,57 @@ func main() { if let helpFlag = flags["help"] as? BoolOption { if helpFlag.value == true { - parser.printUsage() - exit(0) - } + parser.printUsage() + exit(0) + } + } + + if let versionFlag = flags["version"] as? BoolOption { + if versionFlag.value == true { + print(Lyricli.version) + exit(0) + } + } + + if let listSourcesFlag = flags["listSources"] as? BoolOption { + if listSourcesFlag.value == true { + Lyricli.printSources() + exit(0) + } + } + + if let enableSourceFlag = flags["enableSource"] as? StringOption { + if let source = enableSourceFlag.value { + Lyricli.enableSource(source) + exit(0) + } } + if let disableSourceFlag = flags["disableSource"] as? StringOption { + if let source = disableSourceFlag.value { + Lyricli.disableSource(source) + exit(0) + } + } + + if let resetSourceFlag = flags["resetSource"] as? StringOption { + if let source = resetSourceFlag.value { + Lyricli.resetSource(source) + exit(0) + } + } + + if let titleFlag = flags["title"] as? BoolOption { + if titleFlag.value == true { + Lyricli.printTitle() + } + } + + // Remove any flags so anyone after this gets the unprocessed values + let programName: [String] = [CommandLine.arguments[0]] + CommandLine.arguments = programName + parser.unparsedArguments + + Lyricli.printLyrics() } main()