Skip to content

Commit

Permalink
Merge pull request #2510 from carapace-sh/git-hook
Browse files Browse the repository at this point in the history
git: hook
  • Loading branch information
rsteube authored Aug 17, 2024
2 parents 257f9d0 + f94b516 commit bb651d4
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 7 deletions.
19 changes: 19 additions & 0 deletions completers/git_completer/cmd/hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/spf13/cobra"
)

var hookCmd = &cobra.Command{
Use: "hook",
Short: "Run git hooks",
Run: func(cmd *cobra.Command, args []string) {},
GroupID: groups[group_low_level_helper].ID,
}

func init() {
carapace.Gen(hookCmd).Standalone()

rootCmd.AddCommand(hookCmd)
}
29 changes: 29 additions & 0 deletions completers/git_completer/cmd/hook_run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package cmd

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/git"
"github.com/spf13/cobra"
)

var hook_runCmd = &cobra.Command{
Use: "run [--ignore-missing] [--to-stdin=<path>] <hook-name> [-- <hook-args>]",
Short: "Run git hooks",
Run: func(cmd *cobra.Command, args []string) {},
}

func init() {
carapace.Gen(hook_runCmd).Standalone()

hook_runCmd.Flags().Bool("ignore-missing", false, "ignore any missing hook by quietly returning zero")
hook_runCmd.Flags().String("to-stdin", "", "specify a file which will be streamed into the hook’s stdin")
hookCmd.AddCommand(hook_runCmd)

carapace.Gen(hook_runCmd).FlagCompletion(carapace.ActionMap{
"to-stdin": carapace.ActionFiles(),
})

carapace.Gen(hook_runCmd).PositionalCompletion(
git.ActionHooks(),
)
}
8 changes: 5 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module github.com/carapace-sh/carapace-bin

go 1.21
go 1.22

toolchain go1.22.5

require (
github.com/carapace-sh/carapace v1.1.5
github.com/carapace-sh/carapace v1.1.6
github.com/carapace-sh/carapace-bridge v1.0.2
github.com/carapace-sh/carapace-shlex v1.0.1
github.com/carapace-sh/carapace-spec v1.0.1
github.com/carapace-sh/carapace-spec v1.0.2
github.com/pelletier/go-toml v1.9.5
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPn
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/carapace-sh/carapace v1.1.5 h1:nacO1H9k8towi/PZDv/kbEi5Rn6+xC8gdjidax2ccqk=
github.com/carapace-sh/carapace v1.1.5/go.mod h1:djegtVDi/3duSAqZNU+/nCq7XtDRMRZUb5bW0O/HnEs=
github.com/carapace-sh/carapace v1.1.6 h1:1aQlqtyg/HzzwFdDi0HzbfFjaPy/YIfN0TllJPSkYZ0=
github.com/carapace-sh/carapace v1.1.6/go.mod h1:djegtVDi/3duSAqZNU+/nCq7XtDRMRZUb5bW0O/HnEs=
github.com/carapace-sh/carapace-bridge v1.0.2 h1:q2yVrhpxjxA0p3ZcGHpjns99KE9lCrJLc3Zgaa7kMK4=
github.com/carapace-sh/carapace-bridge v1.0.2/go.mod h1:1tuz7tWpJeGMHa6Yvwlkb9QCNqxRD5VsS/4iZdK9ofQ=
github.com/carapace-sh/carapace-pflag v1.0.0 h1:uJMhl+vwEM/Eb0UdxZUuv4jo4rUAyPijkRGP5gfCuCE=
github.com/carapace-sh/carapace-pflag v1.0.0/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
github.com/carapace-sh/carapace-shlex v1.0.1 h1:ww0JCgWpOVuqWG7k3724pJ18Lq8gh5pHQs9j3ojUs1c=
github.com/carapace-sh/carapace-shlex v1.0.1/go.mod h1:lJ4ZsdxytE0wHJ8Ta9S7Qq0XpjgjU0mdfCqiI2FHx7M=
github.com/carapace-sh/carapace-spec v1.0.1 h1:K9ZlmAefR0TzUGeCDGmEgjUX9e17++tp3J7jylrCRSY=
github.com/carapace-sh/carapace-spec v1.0.1/go.mod h1:Zh41opce5OTkqn6a5Old7Az+czPgEg2N3j0uNtDfXbA=
github.com/carapace-sh/carapace-spec v1.0.2 h1:6RJ58d8woTfk0RQeCX38oZzF+U+072BzEZ1eftlOzXw=
github.com/carapace-sh/carapace-spec v1.0.2/go.mod h1:pl0BYhAXpEtNC3NeCoCYmQotVz11SbTRtquXhymXgu8=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
16 changes: 16 additions & 0 deletions pkg/actions/tools/git/hook.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package git

import (
"github.com/carapace-sh/carapace"
"github.com/carapace-sh/carapace/pkg/traverse"
)

// ActionHooks completes hooks
//
// pre-commit.sample
// pre-merge-commit.sample
func ActionHooks() carapace.Action {
return carapace.ActionExecutables("hooks").
ChdirF(traverse.GitDir).
Tag("hooks")
}

0 comments on commit bb651d4

Please sign in to comment.