4 // Entry point of the application. This is the main executable
7 // Bariloche assumes at least one argument, so bypass
9 if CommandLine.arguments.count > 1 {
10 let parser = Bariloche(command: LyricliCommand())
11 let result = parser.parse()
13 if result.count == 0 {
17 if let lyricliCommand = result[0] as? LyricliCommand {
19 checkVersionFlag(lyricliCommand)
20 checkListSourcesFlag(lyricliCommand)
21 checkTitleFlag(lyricliCommand)
25 checkEnableSourceFlag(lyricliCommand)
26 checkDisableSourceFlag(lyricliCommand)
27 checkResetSourceFlag(lyricliCommand)
29 checkPositionalArguments(lyricliCommand)
38 // Handle the version flag
40 private func checkVersionFlag(_ command: LyricliCommand) {
41 if command.version.value {
42 print(Lyricli.version)
47 // Handle the list sources flag
49 private func checkListSourcesFlag(_ command: LyricliCommand) {
50 if command.listSources.value {
51 Lyricli.printSources()
56 // Handle the title flag
58 private func checkTitleFlag(_ command: LyricliCommand) {
59 Lyricli.showTitle = command.showTitle.value
62 // Handle the enable source flag
64 private func checkEnableSourceFlag(_ command: LyricliCommand) {
65 if let source = command.enableSource.value {
66 Lyricli.enableSource(source)
71 // Handle the disable source flag
73 private func checkDisableSourceFlag(_ command: LyricliCommand) {
74 if let source = command.disableSource.value {
75 Lyricli.disableSource(source)
80 // Handle the reset source flag
82 private func checkResetSourceFlag(_ command: LyricliCommand) {
83 if let source = command.resetSource.value {
84 Lyricli.resetSource(source)
89 // Handle the positional arguments
91 private func checkPositionalArguments(_ command: LyricliCommand) {
92 if let artist = command.artist.value {
94 let currentTrack: Track
96 if let trackName = command.trackName.value {
97 currentTrack = Track(withName: trackName, andArtist: artist)
99 currentTrack = Track(withName: "", andArtist: artist)
102 Lyricli.printLyrics(currentTrack)