/
extension_changelog.go
60 lines (47 loc) · 1.25 KB
/
extension_changelog.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package extension
import (
"fmt"
"os"
"path/filepath"
"github.com/spf13/cobra"
"github.com/FriendsOfShopware/shopware-cli/extension"
)
var extensionChangelogCmd = &cobra.Command{
Use: "get-changelog [path]",
Short: "Get the changelog",
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
path, err := filepath.Abs(args[0])
if err != nil {
return fmt.Errorf("cannot find path: %w", err)
}
stat, err := os.Stat(path)
if err != nil {
return fmt.Errorf("cannot find path: %w", err)
}
var ext extension.Extension
if stat.IsDir() {
ext, err = extension.GetExtensionByFolder(path)
} else {
ext, err = extension.GetExtensionByZip(path)
}
if err != nil {
return fmt.Errorf("changelog: cannot open extension %w", err)
}
changelog, err := ext.GetChangelog()
if err != nil {
return fmt.Errorf("cannot generate changelog: %w", err)
}
isGermanChangelog, _ := cmd.PersistentFlags().GetBool("german")
if isGermanChangelog {
fmt.Println(changelog.German)
} else {
fmt.Println(changelog.English)
}
return nil
},
}
func init() {
extensionRootCmd.AddCommand(extensionChangelogCmd)
extensionChangelogCmd.PersistentFlags().Bool("german", false, "Get the german changelog")
}