Skip to content

Commit

Permalink
git: add tag
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed May 7, 2021
1 parent c7cd6bd commit 6eba98c
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 42 deletions.
75 changes: 75 additions & 0 deletions completers/git_completer/cmd/tag.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package cmd

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

var tagCmd = &cobra.Command{
Use: "tag",
Short: "Create, list, delete or verify a tag object signed with GPG",
Run: func(cmd *cobra.Command, args []string) {},
}

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

tagCmd.Flags().BoolS("n", "n", false, "print <n> lines of each tag message")
tagCmd.Flags().BoolP("annotate", "a", false, "annotated tag, needs a message")
tagCmd.Flags().String("cleanup", "", "how to strip spaces and #comments from message")
tagCmd.Flags().String("color", "", "respect format colors")
tagCmd.Flags().String("column", "", "show tag list in columns")
tagCmd.Flags().String("contains", "", "print only tags that contain the commit")
tagCmd.Flags().Bool("create-reflog", false, "create a reflog")
tagCmd.Flags().BoolP("delete", "d", false, "delete tags")
tagCmd.Flags().BoolP("edit", "e", false, "force edit of tag message")
tagCmd.Flags().StringP("file", "F", "", "read message from file")
tagCmd.Flags().BoolP("force", "f", false, "replace the tag if exists")
tagCmd.Flags().String("format", "", "format to use for the output")
tagCmd.Flags().BoolP("ignore-case", "i", false, "sorting and filtering are case insensitive")
tagCmd.Flags().BoolP("list", "l", false, "list tag names")
tagCmd.Flags().StringP("local-user", "u", "", "use another key to sign the tag")
tagCmd.Flags().String("merged", "", "print only tags that are merged")
tagCmd.Flags().StringP("message", "m", "", "tag message")
tagCmd.Flags().String("no-contains", "", "print only tags that don't contain the commit")
tagCmd.Flags().String("no-merged", "", "print only tags that are not merged")
tagCmd.Flags().String("points-at", "", "print only tags of the object")
tagCmd.Flags().BoolP("sign", "s", false, "annotated and GPG-signed tag")
tagCmd.Flags().String("sort", "", "field name to sort on")
tagCmd.Flags().BoolP("verify", "v", false, "verify tags")
rootCmd.AddCommand(tagCmd)

tagCmd.Flag("color").NoOptDefVal = " "

carapace.Gen(tagCmd).FlagCompletion(carapace.ActionMap{
"file": carapace.ActionFiles(),
"cleanup": git.ActionCleanupMode(),
"local-user": os.ActionGpgKeyIds(),
"contains": git.ActionRefs(git.RefOption{Commits: 100}),
"no-contains": git.ActionRefs(git.RefOption{Commits: 100}),
"merged": git.ActionRefs(git.RefOption{Commits: 100}),
"no-merged": git.ActionRefs(git.RefOption{Commits: 100}),
"points-at": git.ActionRefs(git.RefOption{LocalBranches: true, RemoteBranches: true, Commits: 100}),
"color": carapace.ActionValues("always", "never", "auto"),
})

carapace.Gen(tagCmd).PositionalAnyCompletion(
carapace.ActionCallback(func(c carapace.Context) carapace.Action {
if tagCmd.Flag("delete").Changed ||
tagCmd.Flag("list").Changed ||
tagCmd.Flag("verify").Changed {
return git.ActionRefs(git.RefOption{Tags: true}).Invoke(c).Filter(c.Args).ToA()
}
switch len(c.Args) {
case 0:
return git.ActionRefs(git.RefOption{Tags: true})
case 1:
return git.ActionRefs(git.RefOption{LocalBranches: true, Commits: 100})
default:
return carapace.ActionValues()
}
}),
)
}
39 changes: 0 additions & 39 deletions completers/git_completer/cmd/tag_generated.go

This file was deleted.

2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/go-ps v1.0.0
github.com/pelletier/go-toml v1.8.1
github.com/rsteube/carapace v0.5.9
github.com/rsteube/carapace v0.5.10
github.com/spf13/cobra v1.1.1
gopkg.in/ini.v1 v1.62.0
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ github.com/prometheus/procfs v0.0.0-20190507164030-5867b95ac084/go.mod h1:TjEm7z
github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rsteube/carapace v0.5.9 h1:QPdp3Vq6SZ/zm65Ga9jlBZau4UgV8RfdfTli5ZHlYqg=
github.com/rsteube/carapace v0.5.9/go.mod h1:PyIaGGutQyWKcjsoKN7E1tqu8ktOkVF5MYdAd1p4gwE=
github.com/rsteube/carapace v0.5.10 h1:C8k1g49JdAuL3u83CLG2kTWmmo8XfvcgG+Oaw/zfb9g=
github.com/rsteube/carapace v0.5.10/go.mod h1:PyIaGGutQyWKcjsoKN7E1tqu8ktOkVF5MYdAd1p4gwE=
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/ryanuber/columnize v0.0.0-20160712163229-9b3edd62028f/go.mod h1:sm1tb6uqfes/u+d4ooFouqFdy9/2g9QGwK3SQygK0Ts=
github.com/sean-/seed v0.0.0-20170313163322-e2103e2c3529/go.mod h1:DxrIzT+xaE7yg65j358z/aeFdxmN0P9QXhEzd20vsDc=
Expand Down

0 comments on commit 6eba98c

Please sign in to comment.