Skip to content

Commit

Permalink
feat: add flag clean for deploy command (#26)
Browse files Browse the repository at this point in the history
Refs: #26
  • Loading branch information
lgdd committed Oct 25, 2024
1 parent 4552e6d commit 8a8d1b1
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 17 deletions.
28 changes: 24 additions & 4 deletions internal/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
package deploy

import (
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/lgdd/lfr-cli/internal/cmd/exec"
"github.com/lgdd/lfr-cli/internal/conf"
"github.com/lgdd/lfr-cli/pkg/util/fileutil"
"github.com/lgdd/lfr-cli/pkg/util/logger"
)
Expand All @@ -17,22 +21,38 @@ var (
Args: cobra.NoArgs,
Run: run,
}

DeployClean bool
)

func init() {
conf.Init()
defaultDeployClean := viper.GetBool(conf.DeployClean)
Cmd.Flags().BoolVarP(&DeployClean, "clean", "c", defaultDeployClean, "run a clean deploy command")
}

func run(cmd *cobra.Command, args []string) {
liferayWorkspace, err := fileutil.GetLiferayWorkspacePath()
if err != nil {
logger.Fatal(err.Error())
}
if fileutil.IsGradleWorkspace(liferayWorkspace) {
cmdArgs := []string{"deploy"}
if DeployClean {
cmdArgs = []string{"clean", "deploy"}
}
logger.Print("\nRunning ")
logger.PrintlnInfo("lfr exec deploy\n")
exec.RunWrapperCmd([]string{"deploy"})
logger.PrintfInfo("lfr exec %s\n", strings.Join(cmdArgs, " "))
exec.RunWrapperCmd(cmdArgs)
}
if fileutil.IsMavenWorkspace(liferayWorkspace) {
cmdArgs := []string{"package"}
if DeployClean {
cmdArgs = []string{"clean", "package"}
}
logger.Print("\nRunning ")
logger.PrintlnInfo("lfr exec package\n")
exec.RunWrapperCmd([]string{"package"})
logger.PrintfInfo("lfr exec %s\n", strings.Join(cmdArgs, " "))
exec.RunWrapperCmd(cmdArgs)
logger.Print("\nRunning ")
logger.PrintlnInfo("lfr exec bundle-support:deploy\n")
exec.RunWrapperCmd([]string{"bundle-support:deploy"})
Expand Down
34 changes: 21 additions & 13 deletions internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const (
WorkspaceBuild = "workspace.build"
WorkspaceInit = "workspace.init"
LogsFollow = "logs.follow"
DeployClean = "deploy.clean"
ModulePackage = "module.package"
DockerMultistage = "docker.multistage"
DockerJDK = "docker.jdk"
Expand Down Expand Up @@ -47,12 +48,12 @@ func Init() {
os.Remove(configFilePath)
}

setDefaults()
viper.SafeWriteConfig()

if err := viper.ReadInConfig(); err != nil {
log.Fatal(err.Error())
}

setDefaults()
viper.WriteConfig()
}

func GetConfigPath() string {
Expand All @@ -66,16 +67,23 @@ func GetConfigPath() string {
}

func setDefaults() {
viper.SetDefault(WorkspaceEdition, "portal")
viper.SetDefault(WorkspaceVersion, "7.4")
viper.SetDefault(WorkspaceBuild, "gradle")
viper.SetDefault(WorkspaceInit, false)
viper.SetDefault(LogsFollow, false)
viper.SetDefault(ModulePackage, "org.acme")
viper.SetDefault(DockerMultistage, false)
viper.SetDefault(DockerJDK, 11)
viper.SetDefault(OutputNoColor, false)
viper.SetDefault(OutputAccessible, false)
setDefault(WorkspaceEdition, "portal")
setDefault(WorkspaceVersion, "7.4")
setDefault(WorkspaceBuild, "gradle")
setDefault(WorkspaceInit, false)
setDefault(LogsFollow, false)
setDefault(DeployClean, false)
setDefault(ModulePackage, "org.acme")
setDefault(DockerMultistage, false)
setDefault(DockerJDK, 11)
setDefault(OutputNoColor, false)
setDefault(OutputAccessible, false)
}

func setDefault(key string, value any) {
if viper.Get(key) == nil {
viper.SetDefault(key, value)
}
}

func createConfigFolder() {
Expand Down

0 comments on commit 8a8d1b1

Please sign in to comment.