From 4f88ac654d179757e7f07d309670bf30b9405c4d Mon Sep 17 00:00:00 2001 From: Gianluca Boiano Date: Sun, 5 May 2024 18:38:18 +0200 Subject: [PATCH] feat: add zap flag to reset the environment --- cmd/yap/command/build.go | 9 ++----- cmd/yap/command/zap.go | 52 ++++++++++++++++++++++++++++++++++++++++ pkg/project/project.go | 7 ++++++ 3 files changed, 61 insertions(+), 7 deletions(-) create mode 100644 cmd/yap/command/zap.go diff --git a/cmd/yap/command/build.go b/cmd/yap/command/build.go index f715828..9e70dce 100644 --- a/cmd/yap/command/build.go +++ b/cmd/yap/command/build.go @@ -35,13 +35,6 @@ var ( utils.Logger.Args("error", err)) } - if project.CleanBuild { - if err := mpc.Clean(); err != nil { - utils.Logger.Fatal("fatal error", - utils.Logger.Args("error", err)) - } - } - if err := mpc.BuildAll(); err != nil { utils.Logger.Fatal("fatal error", utils.Logger.Args("error", err)) @@ -70,4 +63,6 @@ func init() { "to", "", "", "Build until a defined package name") buildCmd.PersistentFlags().BoolVarP(&pkgbuild.Verbose, "verbose", "v", false, "Verbose output") + buildCmd.Flags().BoolVarP(&project.Zap, + "zap", "z", false, "Remove entire staging dir before building the package") } diff --git a/cmd/yap/command/zap.go b/cmd/yap/command/zap.go new file mode 100644 index 0000000..3599a76 --- /dev/null +++ b/cmd/yap/command/zap.go @@ -0,0 +1,52 @@ +package command + +import ( + "path/filepath" + "strings" + + "github.com/M0Rf30/yap/pkg/project" + "github.com/M0Rf30/yap/pkg/utils" + "github.com/spf13/cobra" +) + +var ( + // zapCmd represents the command to build the entire project. + zapCmd = &cobra.Command{ + Use: "zap [target] [path]", + Short: "Deeply clean the build environment of a project", + Args: cobra.MinimumNArgs(2), + Run: func(_ *cobra.Command, args []string) { + fullJSONPath, _ := filepath.Abs(args[1]) + split := strings.Split(args[0], "-") + distro := split[0] + release := "" + + if len(split) > 1 { + release = split[1] + } + + mpc := project.MultipleProject{} + + project.NoMakeDeps = true + project.SkipSyncDeps = true + project.Zap = true + + err := mpc.MultiProject(distro, release, fullJSONPath) + if err != nil { + utils.Logger.Fatal("fatal error", + utils.Logger.Args("error", err)) + } + + if err := mpc.Clean(); err != nil { + utils.Logger.Fatal("fatal error", + utils.Logger.Args("error", err)) + } + + utils.Logger.Info("zap done", utils.Logger.Args("distro", distro, "release", release)) + }, + } +) + +func init() { + rootCmd.AddCommand(zapCmd) +} diff --git a/pkg/project/project.go b/pkg/project/project.go index ba6bfc1..1ca8f10 100644 --- a/pkg/project/project.go +++ b/pkg/project/project.go @@ -209,6 +209,13 @@ func (mpc *MultipleProject) MultiProject(distro, release, path string) error { return err } + if CleanBuild || Zap { + if err := mpc.Clean(); err != nil { + utils.Logger.Fatal("fatal error", + utils.Logger.Args("error", err)) + } + } + if !NoMakeDeps { mpc.getMakeDeps()