-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add extension get-version, can be used in ci to obtain extensio…
…n version
- Loading branch information
Showing
2 changed files
with
77 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,53 @@ | ||
package extension | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/FriendsOfShopware/shopware-cli/extension" | ||
) | ||
|
||
var extensionVersionCmd = &cobra.Command{ | ||
Use: "get-version [path]", | ||
Short: "Get the version of the given extension", | ||
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("version: cannot open extension %w", err) | ||
} | ||
|
||
version, err := ext.GetVersion() | ||
if err != nil { | ||
return fmt.Errorf("cannot generate version: %w", err) | ||
} | ||
|
||
fmt.Println(version.String()) | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
extensionRootCmd.AddCommand(extensionVersionCmd) | ||
} |
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