diff --git a/Sources/Algebra.swift b/Sources/Algebra.swift index 75b883a..8eb89c8 100644 --- a/Sources/Algebra.swift +++ b/Sources/Algebra.swift @@ -16,15 +16,18 @@ import Foundation +/// Data Structure/Schema representing an entry in a fish history file. struct FishHistoryEntry: Equatable { let cmd: String let when: Int let paths: [String] - + + /// Converts time to Date object func getDate() -> Date { Date(timeIntervalSince1970: TimeInterval(when)) } - + + /// Converts structure back to list of strings as expected in a fish history file. func writeEntry() -> [String] { var output: [String] = [] diff --git a/Sources/FileHelpers.swift b/Sources/FileHelpers.swift index 42e0a94..b00adfc 100644 --- a/Sources/FileHelpers.swift +++ b/Sources/FileHelpers.swift @@ -18,6 +18,12 @@ import Foundation +/// Gets the full file path to a given file. +/// +/// - Parameters +/// - pathStr: The file path to a file. +/// +/// - Returns: A Valid file URL or None if invalid. func getPath(_ pathStr: String) -> URL? { let userHomeDirectory = FileManager.default.homeDirectoryForCurrentUser.path var filePath: String = pathStr diff --git a/Sources/Parser.swift b/Sources/Parser.swift index d1b5bf7..2c04349 100644 --- a/Sources/Parser.swift +++ b/Sources/Parser.swift @@ -18,6 +18,18 @@ import Foundation +/// Make a backup of the fish history. +/// +/// ``` +///The copied files name will have _copy appended to the filename before the file extension. +///For example: +/// if the file was example.txt the copied file will be example_copy.txt +/// ``` +/// +/// - Parameters +/// - path: The file path to the fish history file. +/// +/// - Returns: true if backup copy successful, false if not. func backupHistory(_ path: String) -> Bool { let fileManager = FileManager.default @@ -46,6 +58,14 @@ func backupHistory(_ path: String) -> Bool { } +/// Write fish history to file. +/// +/// - Parameters +/// - path: The file path to the fish history file. +/// - history: History list to write to file. +/// - backup: Should the current history file be backed up first boolean. +/// +/// - Returns: true if writing to file copy successful, false if not. func writeFishHistory(to path: String, history: [FishHistoryEntry], backup: Bool = true) -> Bool { var output = "" @@ -75,6 +95,12 @@ func writeFishHistory(to path: String, history: [FishHistoryEntry], backup: Bool } } +/// Parse the fish history file. +/// +/// - Parameters +/// - filePath: The file path to the fish history file. +/// +/// - Returns: List of ``FishHistoryEntry`` entries from history file. func parseFishHistory(from filePath: String) -> [FishHistoryEntry]? { guard let fileContents = try? String(contentsOfFile: filePath) else { print("Failed to open file.") @@ -113,6 +139,14 @@ func parseFishHistory(from filePath: String) -> [FishHistoryEntry]? { return result.entries } +/// Merge two given ``FishHistoryEntry`` lists into one list. +/// +/// - Parameters +/// - left: The file path to the first fish history file. +/// - right: The file path to the second fish history file. +/// - removeDuplicates: if true, remove any duplicates found after merging the two lists. +/// +/// - Returns: Single list of ``FishHistoryEntry`` entries. func mergeFishHistory(_ left: [FishHistoryEntry], _ right: [FishHistoryEntry], removeDuplicates: Bool = false) -> [FishHistoryEntry] { let merged = left + right @@ -127,5 +161,4 @@ func mergeFishHistory(_ left: [FishHistoryEntry], _ right: [FishHistoryEntry], r } else { return merged } - } diff --git a/Tests/FisheeTests.swift b/Tests/FisheeTests.swift new file mode 100644 index 0000000..e69de29 diff --git a/Tests/TestPlan.xctestplan b/Tests/TestPlan.xctestplan new file mode 100644 index 0000000..ddd7728 --- /dev/null +++ b/Tests/TestPlan.xctestplan @@ -0,0 +1,18 @@ +{ + "configurations" : [ + { + "id" : "1485A2F9-7AD1-4B2E-9F5B-CADD587FC5F6", + "name" : "Configuration 1", + "options" : { + + } + } + ], + "defaultOptions" : { + "testTimeoutsEnabled" : true + }, + "testTargets" : [ + + ], + "version" : 1 +}