<commit_before>struct CommandLine {

    var text = "Hello, World!"
}<commit_msg>Add implementation of command line<commit_after>import Foundation

#if !os(macOS)
public typealias Process = Task
#endif

public typealias Command = String

public enum CommandLineResult {

    case output(String)
    case error(String)

}

/// Ref.: https://github.com/spotify/HubFramework/blob/master/live/sources/CommandLine.swift
public struct CommandLine {

    public func execute(_ command: Command, with arguments: [String] = []) -> CommandLineResult {
        let process = Process()
        process.launchPath = command
        process.arguments = arguments

        let outputPipe = Pipe()
        let errorPipe = Pipe()
        process.standardOutput = outputPipe
        process.standardError = errorPipe
        process.launch()

        if let errorOutput = output(from: errorPipe), errorOutput.characters.count > 0 {
            return .error(errorOutput)
        } else {
            return .output(output(from: outputPipe) ?? "")
        }
    }

    private func output(from pipe: Pipe) -> String? {
        let outputData = pipe.fileHandleForReading.readDataToEndOfFile()
        return String(data: outputData, encoding: .utf8)
    }
    
}
{'fraction_non_alphanumeric': 0.09903381642512077, 'fraction_numerical': 0.001610305958132045, 'mean_word_length': 2.848297213622291, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2233408', 'n_tokens_mistral': 350, 'n_tokens_neox': 337, 'n_words': 89}