Skip to content
Merged
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
9 changes: 7 additions & 2 deletions Sources/markdown-tool/Commands/FormatCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,16 @@ extension MarkdownCommand {
/// Search for the an executable with a given base name.
func findExecutable(named name: String) throws -> String? {
let which = Process()
which.launchPath = "/usr/bin/which"
which.arguments = [name]
let standardOutput = Pipe()
which.standardOutput = standardOutput
which.launch()
if #available(macOS 10.13, *) {
which.executableURL = URL(fileURLWithPath: "/usr/bin/which")
try which.run()
} else {
which.launchPath = "/usr/bin/which"
which.launch()
}
which.waitUntilExit()

guard which.terminationStatus == 0,
Expand Down
9 changes: 7 additions & 2 deletions Sources/markdown-tool/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,20 @@ struct MarkdownCommand: ParsableCommand {
])

static func parseFile(at path: String, options: ParseOptions) throws -> (source: String, parsed: Document) {
let data = try Data(contentsOf: URL( fileURLWithPath: path))
let data = try Data(contentsOf: URL(fileURLWithPath: path))
guard let inputString = String(data: data, encoding: .utf8) else {
throw Error.couldntDecodeInputAsUTF8
}
return (inputString, Document(parsing: inputString, options: options))
}

static func parseStandardInput(options: ParseOptions) throws -> (source: String, parsed: Document) {
let stdinData = FileHandle.standardInput.readDataToEndOfFile()
let stdinData: Data
if #available(macOS 10.15.4, *) {
stdinData = try FileHandle.standardInput.readToEnd() ?? Data()
} else {
stdinData = FileHandle.standardInput.readDataToEndOfFile()
}
guard let stdinString = String(data: stdinData, encoding: .utf8) else {
throw Error.couldntDecodeInputAsUTF8
}
Expand Down