mirror of
https://github.com/softinio/Fishee.git
synced 2025-02-22 21:46:05 -08:00
Add comments to code
This commit is contained in:
parent
02f14b70bf
commit
4287ddfed9
5 changed files with 63 additions and 3 deletions
|
@ -16,15 +16,18 @@
|
||||||
|
|
||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
|
/// Data Structure/Schema representing an entry in a fish history file.
|
||||||
struct FishHistoryEntry: Equatable {
|
struct FishHistoryEntry: Equatable {
|
||||||
let cmd: String
|
let cmd: String
|
||||||
let when: Int
|
let when: Int
|
||||||
let paths: [String]
|
let paths: [String]
|
||||||
|
|
||||||
|
/// Converts time to Date object
|
||||||
func getDate() -> Date {
|
func getDate() -> Date {
|
||||||
Date(timeIntervalSince1970: TimeInterval(when))
|
Date(timeIntervalSince1970: TimeInterval(when))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Converts structure back to list of strings as expected in a fish history file.
|
||||||
func writeEntry() -> [String] {
|
func writeEntry() -> [String] {
|
||||||
var output: [String] = []
|
var output: [String] = []
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,12 @@
|
||||||
import Foundation
|
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? {
|
func getPath(_ pathStr: String) -> URL? {
|
||||||
let userHomeDirectory = FileManager.default.homeDirectoryForCurrentUser.path
|
let userHomeDirectory = FileManager.default.homeDirectoryForCurrentUser.path
|
||||||
var filePath: String = pathStr
|
var filePath: String = pathStr
|
||||||
|
|
|
@ -18,6 +18,18 @@
|
||||||
import Foundation
|
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 {
|
func backupHistory(_ path: String) -> Bool {
|
||||||
let fileManager = FileManager.default
|
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 {
|
func writeFishHistory(to path: String, history: [FishHistoryEntry], backup: Bool = true) -> Bool {
|
||||||
var output = ""
|
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]? {
|
func parseFishHistory(from filePath: String) -> [FishHistoryEntry]? {
|
||||||
guard let fileContents = try? String(contentsOfFile: filePath) else {
|
guard let fileContents = try? String(contentsOfFile: filePath) else {
|
||||||
print("Failed to open file.")
|
print("Failed to open file.")
|
||||||
|
@ -113,6 +139,14 @@ func parseFishHistory(from filePath: String) -> [FishHistoryEntry]? {
|
||||||
return result.entries
|
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] {
|
func mergeFishHistory(_ left: [FishHistoryEntry], _ right: [FishHistoryEntry], removeDuplicates: Bool = false) -> [FishHistoryEntry] {
|
||||||
|
|
||||||
let merged = left + right
|
let merged = left + right
|
||||||
|
@ -127,5 +161,4 @@ func mergeFishHistory(_ left: [FishHistoryEntry], _ right: [FishHistoryEntry], r
|
||||||
} else {
|
} else {
|
||||||
return merged
|
return merged
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
0
Tests/FisheeTests.swift
Normal file
0
Tests/FisheeTests.swift
Normal file
18
Tests/TestPlan.xctestplan
Normal file
18
Tests/TestPlan.xctestplan
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
{
|
||||||
|
"configurations" : [
|
||||||
|
{
|
||||||
|
"id" : "1485A2F9-7AD1-4B2E-9F5B-CADD587FC5F6",
|
||||||
|
"name" : "Configuration 1",
|
||||||
|
"options" : {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"defaultOptions" : {
|
||||||
|
"testTimeoutsEnabled" : true
|
||||||
|
},
|
||||||
|
"testTargets" : [
|
||||||
|
|
||||||
|
],
|
||||||
|
"version" : 1
|
||||||
|
}
|
Loading…
Reference in a new issue