diff --git a/README.md b/README.md index f252543..ed6e837 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,61 @@ # gotaglog [![Go Report Card](https://goreportcard.com/badge/github.com/frgrisk/gotaglog)](https://goreportcard.com/report/github.com/frgrisk/gotaglog) + +GoTagLog is a simple command-line application to automatically generate a +changelog from git tags based on the semantic versioning. It categorizes +commits into groups and outputs them in a formatted markdown file or +directly to the terminal with highlighting. + +## Prerequisites + +To use GoTagLog, you'll need to have: + +- [Go](https://golang.org/dl/) installed on your local machine. + +## Installation + +```bash +go install github.com/frgrisk/gotaglog@latest +``` + +## Usage + +To generate a changelog, use the following command: + +```bash +gotaglog +``` + +### Flags + +The application accepts several flags: + +- `--config`: path to configuration file (default is `$HOME/.gotaglog.yaml`). +- `-o, --output`: path to output file (default if to print to stdout). +- `-r, --repo`: repo to generate changelog for (default is current directory). +- `--unreleased`: show only unreleased changes. + +### Environment variables + +In addition to flags and the configuration file, you can also use +environment variables to set parameters. The application will automatically +look for any environment variables beginning with `GOTAGLOG_`. For +instance, to set the repo, you could use the following command: + +```bash +export GOTAGLOG_REPO=/path/to/repo +``` + +## License + +GoTagLog is released under the MIT License. See the [LICENSE](./LICENSE) +file for more details. + +## Acknowledgments + +- Inspired by [git-cliff](https://github.com/orhun/git-cliff) +- Built with [go-git](https://github.com/go-git/go-git) +- Command line interface powered by [cobra](https://github.com/spf13/cobra) +- Configuration management using [viper](https://github.com/spf13/viper) +- Markdown rendering by [glamour](https://github.com/charmbracelet/glamour) diff --git a/cmd/generate.go b/cmd/generate.go index dc457ed..7481734 100644 --- a/cmd/generate.go +++ b/cmd/generate.go @@ -15,35 +15,12 @@ import ( "github.com/go-git/go-git/v5/plumbing/object" "github.com/go-git/go-git/v5/plumbing/storer" log "github.com/sirupsen/logrus" - "github.com/spf13/cobra" "github.com/spf13/viper" "golang.org/x/term" "golang.org/x/text/cases" "golang.org/x/text/language" ) -// generateCmd represents the generate command -var generateCmd = &cobra.Command{ - Use: "generate", - Short: "Generate a changelog from git tags", - Run: func(cmd *cobra.Command, args []string) { - getChangeLog() - }, -} - -func init() { - rootCmd.AddCommand(generateCmd) - generateCmd.Flags().StringP("output", "o", "", "output file") - err := generateCmd.MarkFlagFilename("output", "md") - if err != nil { - panic(err) - } - err = viper.BindPFlags(generateCmd.Flags()) - if err != nil { - panic(err) - } -} - type CommitGroup struct { Message string Group string @@ -113,8 +90,13 @@ func getChangeLog() { prevTag = tag if ver == semverTags[len(semverTags)-1] { entry = getTagEntryDetails(repo, tag, nil) + unreleasedEntry := []string{"## [unreleased]", entry} if entry != "" { - changelog = append([]string{"## [unreleased]", entry}, changelog...) + if viper.GetBool("unreleased") { + changelog = unreleasedEntry + } else { + changelog = append(unreleasedEntry, changelog...) + } } } } diff --git a/cmd/root.go b/cmd/root.go index 23fd8d1..0628c25 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -15,7 +15,9 @@ var cfgFile string var rootCmd = &cobra.Command{ Use: "gotaglog", Short: "Generate a changelog from git tags", - // Run: func(cmd *cobra.Command, args []string) { }, + Run: func(cmd *cobra.Command, args []string) { + getChangeLog() + }, } // Execute adds all child commands to the root command and sets flags appropriately. @@ -38,10 +40,16 @@ func init() { panic(err) } - // Cobra also supports local flags, which will only run - // when this action is called directly. - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.Flags().Bool("unreleased", false, "show only unreleased changes") + rootCmd.Flags().StringP("output", "o", "", "output file") + err = rootCmd.MarkFlagFilename("output", "md") + if err != nil { + panic(err) + } err = viper.BindPFlags(rootCmd.Flags()) + if err != nil { + panic(err) + } err = viper.BindPFlags(rootCmd.PersistentFlags()) if err != nil { panic(err)