From 857ecb172d1d7c961b1bba87a0aacc0c21d629e0 Mon Sep 17 00:00:00 2001 From: Michael Lorant Date: Tue, 27 Dec 2022 13:46:36 +1100 Subject: [PATCH] :triangular_flag_on_post: Set release builds to apply commits by default Default release builds now apply commits by default. A dry run flag has been added to simulate commits. In development, the existing functionality remains which is to disable commits by default. --- .goreleaser.yaml | 2 ++ README.md | 12 ++++++------ cmd/root.go | 27 ++++++++++++++++++++++++++- cmd/root_release.go | 7 +++++++ 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 cmd/root_release.go 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 +}