From c3180470b5b2549a6fd5833e85a8bcbfad818fb3 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sat, 12 Nov 2016 23:23:35 -0600 Subject: Add the package manager manifest --- Package.swift | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 Package.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..602b04b --- /dev/null +++ b/Package.swift @@ -0,0 +1,8 @@ +import PackageDescription + +let package = Package( + name: "lyricli", + dependencies: [ + .Package(url: "https://github.com/rbdr/CommandLineKit", majorVersion: 4, minor: 0), + ] +) -- cgit From 026a2f69776d0a8c9e15e560bef4a8a01f510aa0 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sat, 12 Nov 2016 23:23:46 -0600 Subject: Add basic option parsing --- README.md | 10 +++++++++- Sources/main.swift | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 49 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6713a7d..71d7259 100644 --- 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/main.swift b/Sources/main.swift index f7cf60e..61f4f71 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -1 +1,40 @@ -print("Hello, world!") +import CommandLineKit +import Foundation + +/// Sets up and returns a new options parser +/// +/// - Returns: A new OptionParser 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.") + + 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) + } + } + +} + +main() -- cgit From 194a358163d7ac0a1f0ea61b1be3372c3532e1c5 Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sat, 12 Nov 2016 23:40:17 -0600 Subject: Print the version with -v / --version --- Sources/Lyricli.swift | 3 +++ Sources/main.swift | 10 +++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 Sources/Lyricli.swift diff --git a/Sources/Lyricli.swift b/Sources/Lyricli.swift new file mode 100644 index 0000000..669dac9 --- /dev/null +++ b/Sources/Lyricli.swift @@ -0,0 +1,3 @@ +public class Lyricli { + public static var version = "0.0.0-feature/option-parsing" +} diff --git a/Sources/main.swift b/Sources/main.swift index 61f4f71..b4d3ebf 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -3,13 +3,14 @@ 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.") parser.addOptions(Array(flags.values)) @@ -35,6 +36,13 @@ func main() { } } + if let versionFlag = flags["version"] as? BoolOption { + if versionFlag.value == true { + print(Lyricli.version) + exit(0) + } + } + } main() -- cgit From 0b3e11a806e704fa373f0549fb3b6164d45c564a Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sat, 12 Nov 2016 23:55:27 -0600 Subject: Add all options from original lyricli Options are mocked but pointing to correct place in library --- Sources/Lyricli.swift | 25 ++++++++++++++++++++++++ Sources/main.swift | 54 +++++++++++++++++++++++++++++++++++++++++++++------ 2 files changed, 73 insertions(+), 6 deletions(-) diff --git a/Sources/Lyricli.swift b/Sources/Lyricli.swift index 669dac9..6c73e02 100644 --- a/Sources/Lyricli.swift +++ b/Sources/Lyricli.swift @@ -1,3 +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") + } } diff --git a/Sources/main.swift b/Sources/main.swift index b4d3ebf..47720ad 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -12,6 +12,13 @@ func createParser() -> ([String:Option], CommandLineKit) { 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) @@ -31,18 +38,53 @@ 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) - } + 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() -- cgit From 8b945f7eefe50a5d4230a765b8be9adb94e1678b Mon Sep 17 00:00:00 2001 From: Ben Beltran Date: Sat, 12 Nov 2016 23:57:19 -0600 Subject: Adds a changelog --- CHANGELOG.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..b6712ba --- /dev/null +++ b/CHANGELOG.md @@ -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 -- cgit