<commit_before>//
//  ChuteCommandLine.swift
//  chute
//
//  Created by <NAME> on 9/10/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

//  Chute Command Line Reference:
//
//  chute
//      -project                The Xcode project to use when creating the Chute report
//      -branch                 The branch that resprents the captured test results
//      -compareFolder          The folder to compare the results with
//      -saveFolder             The folder to save the test input data into

//      To post a summary and optional link to full report in a github pull request, the following are needed:
//      -githubRepository       The repository to use when posting a comment to github (format of <owner>/<repo>)
//      -githubToken            The token to use for posting a comment to github
//      -pullRequestNumber      The pull request number (optional)

import Foundation

struct ChuteCommandLineParameters {

    let project: String?
    let branch: String?
    let compareFolder: String?
    let saveFolder: String?

    let githubRepository: String?
    let githubToken: String?
    let pullRequestNumber: String?

    let slackWebhook: String?

    var hasRequiredParameters: Bool {
        return project != nil
    }

    var hasParametersForGithubNotification: Bool {
        return githubRepository != nil && githubToken != nil && pullRequestNumber != nil
    }

    var hasParametersForSlackNotification: Bool {
        return slackWebhook != nil
    }

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

        var foundArguments: [String: String] = [:]
        for (index, value) in arguments.enumerated() {

            if value.hasPrefix("-") && index < (arguments.count - 1) && !arguments[index+1].hasPrefix("-") {
                let parameter = String(value.suffix(value.count - 1))
                foundArguments[parameter] = arguments[index+1]
            }
        }

        project = foundArguments["project"]
        branch = foundArguments["branch"]
        compareFolder = foundArguments["compareFolder"]
        saveFolder = foundArguments["saveFolder"]

        githubRepository = foundArguments["githubRepository"]
        githubToken = foundArguments["githubToken"]
        pullRequestNumber = foundArguments["pullRequestNumber"]

        slackWebhook = foundArguments["slackWebhook"]
    }

    func printInstructions() {
        var instructions = "Usage: chute -project <project>"
        instructions += " [-branch <branch>]"
        instructions += " [-compareFolder <compareFolder>]"
        instructions += " [-saveFolder <saveFolder>]"
        instructions += " [-githubRepository <githubRepository>]"<commit_msg>Allow parameters to come from the environment<commit_after>//
//  ChuteCommandLine.swift
//  chute
//
//  Created by <NAME> on 9/10/17.
//  Copyright © 2017 <NAME>. All rights reserved.
//

//  Chute Command Line Reference:
//
//  chute
//      -project                The Xcode project to use when creating the Chute report
//      -branch                 The branch that resprents the captured test results
//      -compareFolder          The folder to compare the results with
//      -saveFolder             The folder to save the test input data into

//      To post a summary and optional link to full report in a github pull request, the following are needed:
//      -githubRepository       The repository to use when posting a comment to github (format of <owner>/<repo>)
//      -githubToken            The token to use for posting a comment to github
//      -pullRequestNumber      The pull request number (optional)

import Foundation

struct ChuteCommandLineParameters {

    let project: String?
    let branch: String?
    let compareFolder: String?

    let githubRepository: String?
    let githubToken: String?
    let pullRequestNumber: String?

    let slackWebhook: String?

    var hasRequiredParameters: Bool {
        return project != nil
    }

    var hasParametersForGithubNotification: Bool {
        return githubRepository != nil && githubToken != nil && pullRequestNumber != nil
    }

    var hasParametersForSlackNotification: Bool {
        return slackWebhook != nil
    }

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

        var foundArguments: [String: String] = [:]
        for (index, value) in arguments.enumerated() {

            if value.hasPrefix("-") && index < (arguments.count - 1) && !arguments[index+1].hasPrefix("-") {
                let parameter = String(value.suffix(value.count - 1))
                foundArguments[parameter] = arguments[index+1]
            }
        }

        project = foundArguments["project"]
        branch = foundArguments["branch"] != nil ? foundArguments["branch"] : ProcessInfo.processInfo.environment["CHUTE_BRANCH"]
        compareFolder = foundArguments["compareFolder"] != nil ? foundArguments["compareFolder"] : ProcessInfo.processInfo.environment["CHUTE_COMPARE_FOLDER"]

        githubRepository = foundArguments["githubRepository"] != nil ? foundArguments["githubRepository"] : ProcessInfo.processInfo.environment["CHUTE_GITHUB_REPOSITORY"]
        githubToken = foundArguments["githubToken"] != nil ? foundArguments["githubToken"] : ProcessInfo.processInfo.environment["CHUTE_GITHUB_TOKEN"]
        pullRequestNumber = foundArguments["pullRequestNumber"] != nil ? foundArguments["pullRequestNumber"] : ProcessInfo.processInfo.environment["CHUTE_PULL_REQUEST_NUMBER"]

        slackWebhook = foundArguments["slackWebhook"] != nil ? foundArguments["slackWebhook"] : ProcessInfo.processInfo.environment["CHUTE_SLACK_WEBHOOK"]
    }

    func printInstructions() {
        var instructions = "Usage: chute -project <project>"
        instructions += " [-branch <branch>]"
        instructions += " [-compareFolder <compareFolder>]"
        instructions += " [-githubRepository <githubRepository>]"
{'fraction_non_alphanumeric': 0.100169779286927, 'fraction_numerical': 0.004414261460101867, 'mean_word_length': 2.8129449838187703, 'pattern_counts': {'":': 0, '<': 22, '<?xml version=': 0, '>': 20, 'https://': 0, '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': '3854079', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1456, 'n_words': 451}