Skip to content

Updating to work with Swift 5.8 #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 6 additions & 7 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
// swift-tools-version:4.0
// swift-tools-version:5.8
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

let package = Package(
name: "CodeRunnerCLI",
dependencies: [
.package(url: "https://github.com/JohnSundell/Files", from: "1.9.0"),
.package(url: "https://github.com/JohnSundell/ShellOut", from: "1.0.0"),
.package(url: "https://github.com/JohnSundell/Require", from: "1.0.0")
.package(url: "https://github.com/JohnSundell/Files", from: "3.1.0"),
.package(url: "https://github.com/JohnSundell/ShellOut", from: "2.3.0"),
.package(url: "https://github.com/JohnSundell/Require", from: "2.0.0")
],
targets: [
.target(name: "CodeRunnerCLI", dependencies: ["CodeRunnerCore"]),
.executableTarget(name: "CodeRunnerCLI", dependencies: ["CodeRunnerCore"]),
.testTarget(name: "CodeRunnerCLITests", dependencies: ["CodeRunnerCore"]),
.target(name: "CodeRunnerCore", dependencies: ["Files", "ShellOut", "Require"])
],
swiftLanguageVersions: [4]
]
)
1 change: 0 additions & 1 deletion Sources/CodeRunnerCLI/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import CodeRunnerCore

if #available(OSX 10.11, *) {
let tool = CommandLineTool()

do {
try tool.run()
} catch {
Expand Down
5 changes: 3 additions & 2 deletions Sources/CodeRunnerCore/CommandLineTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@ public final class CommandLineTool {
private let fileSystem = FileSystem()
private let arguments: [String]
private var path: String { return arguments[1] }

public init(arguments: [String] = CommandLine.arguments) {
self.arguments = arguments
}

public func run() throws {
do {
if arguments.count == 1 {
throw CLTError.missingPath
}
let createdFilePath = try fileSystem.createItem(at: path)
print(createdFilePath)
try shellOut(to: "open", arguments: ["-a CodeRunner", createdFilePath])
}
}
Expand Down
3 changes: 1 addition & 2 deletions Sources/CodeRunnerCore/Enums.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ public enum Kind {

public enum CLTError: Error {
case cannotCreateURL(path: String)
case missingFileName
case failedToCreateFile
case missingPath
}
7 changes: 4 additions & 3 deletions Sources/CodeRunnerCore/FileSystem+Creation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import Files
extension FileSystem {
func createItem(at path: String) throws -> String {
let kind = try itemKind(atPath: path)

switch kind {
case .file:
return try createFileIfNeeded(at: path).path
Expand All @@ -22,10 +21,12 @@ extension FileSystem {
}

private func itemKind(atPath path: String) throws -> Kind {
let fileManager = FileManager.default
guard let item = URL(string: path) else {
throw CLTError.cannotCreateURL(path: path)
}

return item.hasDirectoryPath ? .folder : .file
let lazyDirPath = item.appendingPathComponent("/")
let slashedIsDir = fileManager.fileExists(atPath: lazyDirPath.absoluteString)
return item.hasDirectoryPath||slashedIsDir ? .folder : .file
}
}