All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pinterest.ktlint.internal.GitPrePushHookSubCommand.kt Maven / Gradle / Ivy

There is a newer version: 0.51.0-FINAL
Show newest version
package com.pinterest.ktlint.internal

import com.pinterest.ktlint.KtlintCommandLine
import picocli.CommandLine

@CommandLine.Command(
    description = [
        "Install git hook to automatically check files for style violations before push",
        "Usage of \"--install-git-pre-push-hook\" command line option is deprecated!"
    ],
    aliases = ["--install-git-pre-push-hook"],
    mixinStandardHelpOptions = true,
    versionProvider = KtlintVersionProvider::class
)
class GitPrePushHookSubCommand : Runnable {
    @CommandLine.ParentCommand
    private lateinit var ktlintCommand: KtlintCommandLine

    @CommandLine.Spec
    private lateinit var commandSpec: CommandLine.Model.CommandSpec

    override fun run() {
        commandSpec.commandLine().printHelpOrVersionUsage()

        GitHookInstaller.installGitHook("pre-push") {
            loadHookContent()
        }
    }

    private fun loadHookContent() = ClassLoader
        .getSystemClassLoader()
        .getResourceAsStream(
            "ktlint-git-pre-push-hook${if (ktlintCommand.android) "-android" else ""}.sh"
        )
        .readBytes()

    companion object {
        const val COMMAND_NAME = "installGitPrePushHook"
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy