-
-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3ea36bd
commit 0ac1bc7
Showing
17 changed files
with
340 additions
and
315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// ExportCasks.swift | ||
// Applite | ||
// | ||
// Created by Milán Várady on 2023. 08. 11.. | ||
// | ||
|
||
import Foundation | ||
import OSLog | ||
|
||
enum CaskImportError: Error { | ||
case EmptyFile | ||
} | ||
|
||
enum AppMigration { | ||
static func export() async throws -> ExportFile { | ||
let output = try await Shell.runBrewCommand("list") | ||
|
||
let exportedCasks = output.trimmingCharacters(in: .whitespacesAndNewlines) | ||
|
||
return ExportFile(initialText: exportedCasks) | ||
} | ||
|
||
static func readCaskFile(url: URL) throws -> [CaskId] { | ||
let content = try String(contentsOf: url) | ||
var casks: [CaskId] = [] | ||
let brewfileRegex = /cask "([\w-]+)"/ | ||
|
||
// Check if the file being imported is a Brewfile | ||
// Brewfiles store casks as cask "caskName" | ||
if content.contains("cask \"") { | ||
// Brewfile | ||
let matches = content.matches(of: brewfileRegex) | ||
casks = matches.map({ String($0.1) }) | ||
} else { | ||
// Try to load casks as an Applite txt file export | ||
casks = content.components(separatedBy: .newlines) | ||
|
||
// Trim whitespace | ||
casks = casks.map({ $0.trimmingCharacters(in: .whitespaces) }) | ||
} | ||
|
||
// Remove empty elements | ||
casks = casks.filter({ !$0.isEmpty }) | ||
|
||
if casks.isEmpty { | ||
throw CaskImportError.EmptyFile | ||
} | ||
|
||
return casks | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.