diff --git a/internal/cmd/deploy/deploy.go b/internal/cmd/deploy/deploy.go index 65f8c6f..14e12dc 100644 --- a/internal/cmd/deploy/deploy.go +++ b/internal/cmd/deploy/deploy.go @@ -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" ) @@ -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"}) diff --git a/internal/conf/conf.go b/internal/conf/conf.go index 582efba..6f2f1de 100644 --- a/internal/conf/conf.go +++ b/internal/conf/conf.go @@ -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" @@ -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 { @@ -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() {