shibapm / Komondor

Git Hooks for Swift projects 🐩
MIT License
552 stars 32 forks source link

Usage from within a Beak script & uninstallability? #20

Closed Jeehut closed 5 years ago

Jeehut commented 5 years ago

I'm just trying to use Komondor from within a Beak script, since there you can also specify SwiftPM dependencies and run them separately from the Package.swift file. I'm already confused because of #18 and #19, but what I also don't understand is how the definition of a config parameter leads to Komondor to know what things to run? Does that mean that Komondor is parsing the Package.swift file and trying to find a PackageConfig object there, I'm really confused about how this works.

Here's what I'm trying at the moment using Beak:

#!/usr/bin/env beak run --path

// MARK: - Script Dependencies
// beak: shibapm/Komondor @ .upToNextMajor(from: "1.0.4")

import Foundation
import PackageConfig

// MARK: - Runnable Tasks
/// Registers git hooks for the project to ensure you get notified of potential issues e.g. before committing.
public func register() throws {
    let config = PackageConfig([
        "komondor": [
            "pre-commit": ["bartycrouch lint --fail-on-warnings", "swiftlint lint --strict --quiet"]
        ]
    ])

    // TODO: make sure the `config` actually is being used by `kommondor install`, but how?
}

/// Unregisters any registered git hooks.
public func unregister() throws {
    let config = PackageConfig(["komondor": []])
    // TODO: make sure the `config` actually is being applied by `kommondor install` and updates previous hooks, but how?
}

My goal is to have both a hooks register and a hooks unregister command setup which developers who checkout the project can run in order to – well, register or unregister all hooks I might define within that file. Also, how does Komondor behave when I change my hooks and re-run kommondor install, does it remove all removed hooks and also ensure no duplicates appear in the final configured hooks?

Jeehut commented 5 years ago

Please note that I found a much easier way to configure git hooks in my project setup, so I won't need this feature, personally. Feel free to close it if you feel like you don't want it. Sorry for reporting it first, then not actually needing it. 😅

If anyone is curious how I got it working using Beak, checkout our hooks.swift file.

orta commented 5 years ago

I don't really know much about beak, the install script installs generic hooks which look in your config to decide if they should run or not. I think you miss the value of Komondor: it has a central & consistent way to do git hooks and is only responsible for running whatever is defined in your package.swift.

I'm not too suer what you're trying to do with the script in the OP, but I'm happy you found a way 👍