<commit_before>/**
 *  TestDrive
 *  Copyright (c) <NAME> 2017
 *  Licensed under the MIT license. See LICENSE file.
 */

import Foundation
import Xgen
import Files
import ShellOut
import Releases

// MARK: - Extensions

extension CommandLine {
    static func parseArguments() throws -> Arguments {
        var parsedArguments = Arguments()
        var expectingPlatform = false
        var expectingCheckout = false

        for argument in arguments[1..<arguments.count] {
            if expectingPlatform {
                guard let platform = Playground.Platform(rawValue: argument.lowercased()) else {
                    throw TestDriveError.invalidPlatform(argument)
                }

                parsedArguments.platform = platform
                expectingPlatform = false
                continue
            } else if expectingCheckout {
                parsedArguments.addTagToLastTarget(.checkout(argument))
                expectingCheckout = false
                continue
            }

            switch argument {
            case "--platform", "-p":
                expectingPlatform = true
            case "--version", "-v":
                expectingCheckout = true
            case "--master", "-m":
                parsedArguments.addTagToLastTarget(.master)
            default:
                let target = try Target(kind: targetKind(from: argument), tag: .latestVersion)
                parsedArguments.targets.append(target)
            }
        }

        return parsedArguments
    }

    private static func targetKind(from argument: String) throws -> Target.Kind {
        if argument.hasSuffix(".git") {
            guard let url = URL(string: argument) else {
                throw TestDriveError.invalidURL(argument)
            }

            return .repository(url)
        }

        if argument.contains("github.com/") {
            let components = argument.components(separatedBy: "github.com/")

            guard let url = URL(string: "git@github.com:\(components[1])") else {
                throw TestDriveError.invalidURL(argument)
            }

            return .repository(url)
        }

        return .pod(argument)
    }
}

// MARK: - Types

enum TestDriveError: Error {
    case invalidURL(String)
    case missingPlatform
    case invalidPlatform(String)
    case missingXcodeProject(URL)
    case invalidPodName(String)
    case invalidPodSourceURL(String)
}

extension TestDriveError: CustomStringConvertible {
    var description: String {<commit_msg>Use HTTPS instead of SSH for repository URL<commit_after>/**
 *  TestDrive
 *  Copyright (c) <NAME> 2017
 *  Licensed under the MIT license. See LICENSE file.
 */

import Foundation
import Xgen
import Files
import ShellOut
import Releases

// MARK: - Extensions

extension CommandLine {
    static func parseArguments() throws -> Arguments {
        var parsedArguments = Arguments()
        var expectingPlatform = false
        var expectingCheckout = false

        for argument in arguments[1..<arguments.count] {
            if expectingPlatform {
                guard let platform = Playground.Platform(rawValue: argument.lowercased()) else {
                    throw TestDriveError.invalidPlatform(argument)
                }

                parsedArguments.platform = platform
                expectingPlatform = false
                continue
            } else if expectingCheckout {
                parsedArguments.addTagToLastTarget(.checkout(argument))
                expectingCheckout = false
                continue
            }

            switch argument {
            case "--platform", "-p":
                expectingPlatform = true
            case "--version", "-v":
                expectingCheckout = true
            case "--master", "-m":
                parsedArguments.addTagToLastTarget(.master)
            default:
                let target = try Target(kind: targetKind(from: argument), tag: .latestVersion)
                parsedArguments.targets.append(target)
            }
        }

        return parsedArguments
    }

    private static func targetKind(from argument: String) throws -> Target.Kind {
        if argument.hasSuffix(".git") {
            guard let url = URL(string: argument) else {
                throw TestDriveError.invalidURL(argument)
            }

            return .repository(url)
        }

        if argument.contains("github.com/") {
            let components = argument.components(separatedBy: "github.com/")

            guard let url = URL(string: "https://github.com/\(components[1])") else {
                throw TestDriveError.invalidURL(argument)
            }

            return .repository(url)
        }

        return .pod(argument)
    }
}

// MARK: - Types

enum TestDriveError: Error {
    case invalidURL(String)
    case missingPlatform
    case invalidPlatform(String)
    case missingXcodeProject(URL)
    case invalidPodName(String)
    case invalidPodSourceURL(String)
}

extension TestDriveError: CustomStringConvertible {
    var description: String {
{'fraction_non_alphanumeric': 0.083596214511041, 'fraction_numerical': 0.002365930599369085, 'mean_word_length': 1.9138426191843767, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, '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': '3913123', 'n_tokens_mistral': 1266, 'n_tokens_neox': 1196, 'n_words': 321}