Skip to content

Commit

Permalink
Merge pull request #4 from ypjama/add-preview-command
Browse files Browse the repository at this point in the history
Add preview command
  • Loading branch information
ypjama authored Oct 6, 2024
2 parents e982e45 + d3cb418 commit 70a3cbe
Show file tree
Hide file tree
Showing 14 changed files with 464 additions and 130 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.3.0] - 2024-10-06

[0.3.0]: https://github.com/ypjama/conflictless-keepachangelog/releases/tag/v0.3.0

### Added

- New command 'preview' which prints a preview of the next changelog entry.

## [0.2.0] - 2024-10-05

[0.2.0]: https://github.com/ypjama/conflictless-keepachangelog/releases/tag/v0.2.0
Expand Down
52 changes: 1 addition & 51 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,61 +59,11 @@ The commands are:
create Creates a new change-file
generate Generates a version entry to changelog file
help Prints this help message
preview Prints a preview of the next changelog entry
Use "conflictless help <topic>" for more information about that topic.
```

`conflictless help check`

``` txt
Usage: conflictless check [flags]
The flags are:
-d, --dir
Directory where to look for change-files (default: changes)
```

`conflictless help create`

```txt
Usage: conflictless create [flags]
The flags are:
-d, --dir
Directory where the change-file should be created (default: changes)
-f, --format
File format and extension yml/yaml/json for the change-file (default: yml)
-t, --types
Types of changes you want for the change-file (default: changed)
Multiple values can be given by separating values with commas.
Example: '--format added,changed,deprecated,removed,fixed,security'.
-n, --name
Name for the change-file without file extension
If this flag is not given the name will be derived from the name of the
current git branch you're on.
```

`conflictless help generate`

``` txt
Usage: conflictless generate [flags]
The flags are:
-b, --bump
Bump version patch/minor/major (default: minor)
-c, --changelog
Changelog file (default: CHANGELOG.md)
-d, --dir
Directory where to look for change-files (default: changes)
-s, --skip-version-links
Skip version links in changelog file (default: false)
```

## Suggested workflow

Each project should have a directory for storing unreleased changes, e.g. a directory named `changes`. In this directory developers can create _YAML_ or _JSON_ files for each merge/pull request. The filename can be freely chosen and can be derived from the branch name, e.g. `fix-broken-dependency.yml`. This way each merge/pull request would have its own `changes` file and there would not be any merge conflicts regarding the changelog.
Expand Down
77 changes: 56 additions & 21 deletions internal/pkg/conflictless/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const (
commandCreate = "create"
commandGen = "generate"
commandHelp = "help"
commandPreview = "preview"
defaultBump = BumpMinor
defaultChangeFileFormat = "yml"
defaultChangeTypesCSV = "changed"
Expand Down Expand Up @@ -59,6 +60,8 @@ func CLI() {
Create(&cfg)
case commandGen:
Generate(&cfg)
case commandPreview:
Preview(&cfg)
case commandHelp:
Help()
default:
Expand Down Expand Up @@ -116,6 +119,14 @@ func parseCLIFlags(cfg *Config) {
defineCreateTypeFlags(cfg, cmd)
defineDirFlags(cfg, cmd)
defineChangeFileNameFlags(cfg, cmd)
case commandPreview:
cmd = flag.NewFlagSet(commandPreview, flag.ExitOnError)
cmd.Usage = usagePreviewOnError

defineBumpFlags(cfg, cmd)
defineChangeLogFlags(cfg, cmd)
defineDirFlags(cfg, cmd)
defineSkipFlags(cfg, cmd)
}

if cmd != nil {
Expand All @@ -126,43 +137,67 @@ func parseCLIFlags(cfg *Config) {
}
}

func defineChangeLogFlags(cfg *Config, fs *flag.FlagSet) {
func defineChangeLogFlags(cfg *Config, flagset *flag.FlagSet) {
defaultChangelogFile := "CHANGELOG.md"

fs.StringVar(cfg.Flags.ChangelogFile, "changelog", defaultChangelogFile, "")
fs.StringVar(cfg.Flags.ChangelogFile, "c", defaultChangelogFile, "")
if cfg.Flags.ChangelogFile == nil {
cfg.Flags.ChangelogFile = new(string)
}

flagset.StringVar(cfg.Flags.ChangelogFile, "changelog", defaultChangelogFile, "")
flagset.StringVar(cfg.Flags.ChangelogFile, "c", defaultChangelogFile, "")
}

func defineBumpFlags(cfg *Config, fs *flag.FlagSet) {
func defineBumpFlags(cfg *Config, flagset *flag.FlagSet) {
defaultBumpStr := "minor"

fs.StringVar(cfg.Flags.Bump, "bump", defaultBumpStr, "")
fs.StringVar(cfg.Flags.Bump, "b", defaultBumpStr, "")
if cfg.Flags.Bump == nil {
cfg.Flags.Bump = new(string)
}

flagset.StringVar(cfg.Flags.Bump, "bump", defaultBumpStr, "")
flagset.StringVar(cfg.Flags.Bump, "b", defaultBumpStr, "")
}

func defineDirFlags(cfg *Config, fs *flag.FlagSet) {
func defineDirFlags(cfg *Config, flagset *flag.FlagSet) {
defaultDir := "changes"

fs.StringVar(cfg.Flags.Directory, "dir", defaultDir, "")
fs.StringVar(cfg.Flags.Directory, "d", defaultDir, "")
if cfg.Flags.Directory == nil {
cfg.Flags.Directory = new(string)
}

flagset.StringVar(cfg.Flags.Directory, "dir", defaultDir, "")
flagset.StringVar(cfg.Flags.Directory, "d", defaultDir, "")
}

func defineFormatFlags(cfg *Config, fs *flag.FlagSet) {
fs.StringVar(cfg.Flags.ChangeFileFormat, "format", defaultChangeFileFormat, "")
fs.StringVar(cfg.Flags.ChangeFileFormat, "f", defaultChangeFileFormat, "")
func defineFormatFlags(cfg *Config, flagset *flag.FlagSet) {
if cfg.Flags.ChangeFileFormat == nil {
cfg.Flags.ChangeFileFormat = new(string)
}

flagset.StringVar(cfg.Flags.ChangeFileFormat, "format", defaultChangeFileFormat, "")
flagset.StringVar(cfg.Flags.ChangeFileFormat, "f", defaultChangeFileFormat, "")
}

func defineCreateTypeFlags(cfg *Config, fs *flag.FlagSet) {
fs.StringVar(cfg.Flags.ChangeTypesCsv, "types", defaultChangeTypesCSV, "")
fs.StringVar(cfg.Flags.ChangeTypesCsv, "t", defaultChangeTypesCSV, "")
func defineCreateTypeFlags(cfg *Config, flagset *flag.FlagSet) {
if cfg.Flags.ChangeTypesCsv == nil {
cfg.Flags.ChangeTypesCsv = new(string)
}

flagset.StringVar(cfg.Flags.ChangeTypesCsv, "types", defaultChangeTypesCSV, "")
flagset.StringVar(cfg.Flags.ChangeTypesCsv, "t", defaultChangeTypesCSV, "")
}

func defineChangeFileNameFlags(cfg *Config, fs *flag.FlagSet) {
fs.StringVar(cfg.Flags.ChangeFileName, "name", "", "")
fs.StringVar(cfg.Flags.ChangeFileName, "n", "", "")
func defineChangeFileNameFlags(cfg *Config, flagset *flag.FlagSet) {
if cfg.Flags.ChangeFileName == nil {
cfg.Flags.ChangeFileName = new(string)
}

flagset.StringVar(cfg.Flags.ChangeFileName, "name", "", "")
flagset.StringVar(cfg.Flags.ChangeFileName, "n", "", "")
}

func defineSkipFlags(cfg *Config, fs *flag.FlagSet) {
fs.BoolVar(&cfg.Flags.SkipVersionLinks, "skip-version-links", false, "")
fs.BoolVar(&cfg.Flags.SkipVersionLinks, "s", false, "")
func defineSkipFlags(cfg *Config, flagset *flag.FlagSet) {
flagset.BoolVar(&cfg.Flags.SkipVersionLinks, "skip-version-links", false, "")
flagset.BoolVar(&cfg.Flags.SkipVersionLinks, "s", false, "")
}
Loading

0 comments on commit 70a3cbe

Please sign in to comment.