From f94b516b9b4608c9280f3c374854f3fe7adc7a5a Mon Sep 17 00:00:00 2001 From: rsteube Date: Sat, 17 Aug 2024 21:23:52 +0200 Subject: [PATCH] git: hook --- completers/git_completer/cmd/hook.go | 19 ++++++++++++++++ completers/git_completer/cmd/hook_run.go | 29 ++++++++++++++++++++++++ go.mod | 8 ++++--- go.sum | 8 +++---- pkg/actions/tools/git/hook.go | 16 +++++++++++++ 5 files changed, 73 insertions(+), 7 deletions(-) create mode 100644 completers/git_completer/cmd/hook.go create mode 100644 completers/git_completer/cmd/hook_run.go create mode 100644 pkg/actions/tools/git/hook.go diff --git a/completers/git_completer/cmd/hook.go b/completers/git_completer/cmd/hook.go new file mode 100644 index 0000000000..5e6aea87b5 --- /dev/null +++ b/completers/git_completer/cmd/hook.go @@ -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) +} diff --git a/completers/git_completer/cmd/hook_run.go b/completers/git_completer/cmd/hook_run.go new file mode 100644 index 0000000000..6789cb4695 --- /dev/null +++ b/completers/git_completer/cmd/hook_run.go @@ -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=] [-- ]", + 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(), + ) +} diff --git a/go.mod b/go.mod index 7bf75bf5a4..56bca5fed7 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index b0852945a2..c73859eb82 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/actions/tools/git/hook.go b/pkg/actions/tools/git/hook.go new file mode 100644 index 0000000000..8b7a437113 --- /dev/null +++ b/pkg/actions/tools/git/hook.go @@ -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") +}