changelog generator & diff tool
stormlightlabs.github.io/git-storm/
changelog
changeset
markdown
golang
git
1package main
2
3import (
4 "fmt"
5 "path/filepath"
6
7 "github.com/spf13/cobra"
8 "github.com/stormlightlabs/git-storm/internal/changelog"
9 "github.com/stormlightlabs/git-storm/internal/style"
10 "github.com/stormlightlabs/git-storm/internal/versioning"
11)
12
13func bumpCmd() *cobra.Command {
14 var bumpKind string
15 var toolchainSelectors []string
16
17 cmd := &cobra.Command{
18 Use: "bump",
19 Short: "Calculate the next semantic version and optionally update toolchain manifests",
20 RunE: func(cmd *cobra.Command, args []string) error {
21 kind, err := versioning.ParseBumpType(bumpKind)
22 if err != nil {
23 return err
24 }
25
26 changelogPath := filepath.Join(repoPath, output)
27 parsed, err := changelog.Parse(changelogPath)
28 if err != nil {
29 return fmt.Errorf("failed to parse changelog: %w", err)
30 }
31
32 current, _ := versioning.LatestVersion(parsed)
33 nextVersion, err := versioning.Next(current, kind)
34 if err != nil {
35 return err
36 }
37
38 style.Headlinef("Next version: %s", nextVersion)
39
40 updated, err := updateToolchainTargets(repoPath, nextVersion, toolchainSelectors)
41 if err != nil {
42 return err
43 }
44 for _, manifest := range updated {
45 style.Addedf("✓ Updated %s", manifest.RelPath)
46 }
47
48 fmt.Fprintln(cmd.OutOrStdout(), nextVersion)
49 return nil
50 },
51 }
52
53 cmd.Flags().StringVar(&bumpKind, "bump", "", "Which semver component to bump (major, minor, or patch)")
54 cmd.Flags().StringSliceVar(&toolchainSelectors, "toolchain", nil, "Toolchain manifests to update (paths, types, or 'interactive')")
55 cmd.MarkFlagRequired("bump")
56
57 return cmd
58}