-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add changelog extraction command
- Loading branch information
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package extension | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/FriendsOfShopware/shopware-cli/extension" | ||
) | ||
|
||
var extensionChangelogCmd = &cobra.Command{ | ||
Use: "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") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters