]> git.r.bdr.sh - rbdr/lyricli/commitdiff
Merge branch 'feature/option-parsing' into develop
authorBen Beltran <redacted>
Sun, 13 Nov 2016 06:01:00 +0000 (00:01 -0600)
committerBen Beltran <redacted>
Sun, 13 Nov 2016 06:01:00 +0000 (00:01 -0600)
CHANGELOG.md [new file with mode: 0644]
Package.swift [new file with mode: 0644]
README.md
Sources/Lyricli.swift [new file with mode: 0644]
Sources/main.swift

diff --git a/CHANGELOG.md b/CHANGELOG.md
new file mode 100644 (file)
index 0000000..b6712ba
--- /dev/null
@@ -0,0 +1,12 @@
+# Changelog
+All notable changes to this project will be documented in this file.
+
+The format is based on [Keep a Changelog](http://keepachangelog.com/)
+and this project adheres to [Semantic Versioning](http://semver.org/).
+
+## [Unreleased]
+### Added
+- Parsing of options to match legacy lyricli
+- Placeholder for the library with expected endpoints
+
+[Unreleased]: https://github.com/olivierlacan/keep-a-changelog/compare/master...develop
diff --git a/Package.swift b/Package.swift
new file mode 100644 (file)
index 0000000..602b04b
--- /dev/null
@@ -0,0 +1,8 @@
+import PackageDescription
+
+let package = Package(
+    name: "lyricli",
+    dependencies: [
+        .Package(url: "https://github.com/rbdr/CommandLineKit", majorVersion: 4, minor: 0),
+    ]
+)
index 6713a7d8d4c33d3d885767ec78cb086f07242fa2..71d72599319231f4d6a93baee8fc643609a982b6 100644 (file)
--- a/README.md
+++ b/README.md
@@ -1,3 +1,11 @@
-#Lyricli (lrc)
+# Lyricli (lrc)
 
 A command line tool to show the lyrics of your current song
+
+## Building
+
+Run `swift build`
+
+## Running tests
+
+Run `swift test`
diff --git a/Sources/Lyricli.swift b/Sources/Lyricli.swift
new file mode 100644 (file)
index 0000000..6c73e02
--- /dev/null
@@ -0,0 +1,28 @@
+/// The main Lyricli interface
+public class Lyricli {
+    public static var version = "0.0.0-feature/option-parsing"
+
+    public static func printLyrics() {
+        print("Getting Lyrics: Not yet implemented")
+    }
+
+    public static func printTitle() {
+        print("Getting Song Title: Not yet implemented")
+    }
+
+    public static func printSources() {
+        print("Listing Sources: Not yet implemented")
+    }
+
+    public static func enableSource(_ sourceName: String) {
+        print("Enable source \(sourceName): Not yet implemented")
+    }
+
+    public static func disableSource(_ sourceName: String) {
+        print("Disable source \(sourceName): Not yet implemented")
+    }
+
+    public static func resetSource(_ sourceName: String) {
+        print("Reset source \(sourceName): Not yet implemented")
+    }
+}
index f7cf60e14f9a9e9805e0463e7fa33b6c91204c4d..47720ad3a631b15d7feed0637520a729bf3c8662 100644 (file)
@@ -1 +1,90 @@
-print("Hello, world!")
+import CommandLineKit
+import Foundation
+
+/// Sets up and returns a new options parser
+/// 
+/// - 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))
+
+    return (flags, parser)
+}
+
+func main() {
+
+    let (flags, parser) = createParser()
+
+    do {
+        try parser.parse()
+    }
+    catch {
+        parser.printUsage(error)
+        exit(EX_USAGE)
+    }
+
+    if let helpFlag = flags["help"] as? BoolOption {
+        if helpFlag.value == true {
+            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()
+        }
+    }
+
+    Lyricli.printLyrics()
+}
+
+main()