diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 4118d46..b6c634d 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -6,6 +6,8 @@ builds: goarch: - amd64 - arm64 + tags: + - release release: github: diff --git a/README.md b/README.md index e255be5..f4da1a4 100644 --- a/README.md +++ b/README.md @@ -79,15 +79,15 @@ Usage: committed [flags] Flags: - -a, --amend Replace the tip of the current branch by creating a new commit - -h, --help help for committed - -y, --yes Specify --yes to apply the commit + -a, --amend Replace the tip of the current branch by creating a new commit + --dry-run Simulate applying a commit + -h, --help help for committed ``` -To apply a commit use `committed --yes `. Shell or Git aliases can be used to -tailor this to your preferred workflow. +To create and apply a commit run `committed ` without any arguments. Shell or +Git aliases can be used to tailor this to your preferred workflow. -To amend an existing commit use `committed --yes --amend`. There are certain +To amend an existing commit use `committed --amend`. There are certain limitations when amending commits and it is recommended only for use with commits created with Committed. The limitations are: diff --git a/cmd/root.go b/cmd/root.go index ef0583c..a69b762 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,13 +15,18 @@ import ( "github.com/spf13/cobra" ) +var hideApplyFlag bool + func NewRootCmd() *cobra.Command { var opts commit.Options + var dryRun bool cmd := &cobra.Command{ Use: "committed", Short: "Committed is a WYSIWYG Git commit editor", RunE: func(cmd *cobra.Command, args []string) error { + opts.Apply = apply(opts.Apply, dryRun) + c, err := commit.New(opts) switch { case err == nil: @@ -48,9 +53,13 @@ func NewRootCmd() *cobra.Command { }, } - cmd.Flags().BoolVarP(&opts.Apply, "yes", "y", false, "Specify --yes to apply the commit") + cmd.Flags().BoolVarP(&dryRun, "dry-run", "", false, "Simulate applying a commit") cmd.Flags().BoolVarP(&opts.Amend, "amend", "a", false, "Replace the tip of the current branch by creating a new commit") + if !hideApplyFlag { + cmd.Flags().BoolVarP(&opts.Apply, "yes", "y", false, "Specify --yes to apply the commit") + } + cc.Init(&cc.Config{ RootCmd: cmd, Headings: cc.HiGreen + cc.Bold, @@ -86,3 +95,19 @@ func Commit(c *commit.Commit, res ui.Result) error { return nil } + +func apply(a bool, dr bool) bool { + if a { + return true + } + + if hideApplyFlag { + a = true + } + + if dr { + a = false + } + + return a +} diff --git a/cmd/root_release.go b/cmd/root_release.go new file mode 100644 index 0000000..6bc62fd --- /dev/null +++ b/cmd/root_release.go @@ -0,0 +1,7 @@ +//go:build release + +package cmd + +func init() { + hideApplyFlag = true +}