//
//  TagsConfiguration+Runnable.swift
//  
//
//  Created by Thibaut Schmitt on 30/08/2022.
//

import Foundation

extension TagsConfiguration: Runnable {

    func run(projectDirectory: String, force: Bool) {
        let args = getArguments(projectDirectory: projectDirectory, force: force)
        Tags.main(args)
    }

    func getArguments(projectDirectory: String, force: Bool) -> [String] {
        var args = [String]()

        if force {
            args += ["-f"]
        }

        args += [
            inputFile.prependIfRelativePath(projectDirectory),
            "--lang",
            lang,
            "--extension-output-path",
            extensionOutputPath.prependIfRelativePath(projectDirectory)
        ]

        // Add optional parameters
        [
            ("--extension-name", extensionName),
            ("--extension-suffix", extensionSuffix),
            ("--visibility", visibility),
            ("--static-members", staticMembers?.description)
        ].forEach { argumentName, argumentValue in
            if let argumentValue {
                args += [
                    argumentName,
                    argumentValue
                ]
            }
        }

        return args
    }
}
