forked from rcmachado/changelog
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
latest.go
33 lines (30 loc) · 892 Bytes
/
latest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package cmd
import (
"fmt"
"io"
"github.com/cucumber/changelog/parser"
"github.com/spf13/cobra"
)
func newLatestCmd(iostreams *IOStreams) *cobra.Command {
return &cobra.Command{
Use: "latest",
Short: "Show latest released version number",
Long: `Show version number for the top (released) entry in the changelog`,
Args: cobra.ExactArgs(0),
RunE: func(cmd *cobra.Command, args []string) error {
changelog := parser.Parse(iostreams.In)
if len(changelog.Versions) == 0 {
cmd.SilenceUsage = true
return fmt.Errorf("There are no versions in the changelog yet")
}
releasedVersions := changelog.ReleasedVersions()
if len(releasedVersions) == 0 {
cmd.SilenceUsage = true
return fmt.Errorf("There are no released versions in the changelog yet")
}
v := releasedVersions[0]
io.WriteString(iostreams.Out, v.Name+"\n")
return nil
},
}
}