]> git.r.bdr.sh - rbdr/lyricli/blobdiff - Sources/lyricli.swift
Merge branch 'release/0.3.0' into develop
[rbdr/lyricli] / Sources / lyricli.swift
index d55b500af960bb8b39c5c571ea78fbe91bec4aff..8aeb5c01b530ea74b923080e4b69c985e0828375 100644 (file)
@@ -1,37 +1,60 @@
-/// The main Lyricli interface
-public class Lyricli {
-    public static var version = "0.0.0-feature/option-parsing"
+// The main class, handles all the actions that the executable will call
+class Lyricli {
 
-    public static func printLyrics() {
+    // Version of the application
+    static var version = "0.3.0"
+
+    // Flag that controls whether we should show the track artist and name before
+    // the lyrics
+    static var showTitle = false
+
+    // Obtains the name of the current track from a source, fetches the lyrics
+    // from an engine and prints them
+    static func printLyrics() {
 
         let sourceManager = SourceManager()
 
         if let currentTrack = sourceManager.currentTrack {
-            print(currentTrack.artist)
-            print(currentTrack.name)
-        }
-        else {
-            print("Current track not found")
-        }
-    }
+            let engine = LyricsEngine(withTrack: currentTrack)
 
-    public static func printTitle() {
-        print("Getting Song Title: Not yet implemented")
+            if let lyrics = engine.lyrics {
+                if showTitle {
+                    printTitle(currentTrack)
+                }
+
+                print(lyrics)
+            } else {
+                print("Lyrics not found :(")
+            }
+
+        } else {
+            print("No Artist/Song could be found :(")
+        }
     }
 
-    public static func printSources() {
+    // Print the currently available sources
+    static func printSources() {
         print("Listing Sources: Not yet implemented")
     }
 
-    public static func enableSource(_ sourceName: String) {
+    // Runs the enable method of a source and writes the configuration to set it
+    // as enabled
+    static func enableSource(_ sourceName: String) {
         print("Enable source \(sourceName): Not yet implemented")
     }
 
-    public static func disableSource(_ sourceName: String) {
+    // Remove a source from the enabled sources configuration
+    static func disableSource(_ sourceName: String) {
         print("Disable source \(sourceName): Not yet implemented")
     }
 
-    public static func resetSource(_ sourceName: String) {
+    // Removes any configuration for a source, and disables it
+    static func resetSource(_ sourceName: String) {
         print("Reset source \(sourceName): Not yet implemented")
     }
+
+    // Prints the track artist and name
+    private static func printTitle(_ track: Track) {
+        print("\(track.artist) - \(track.name)")
+    }
 }