Skip to content

Commit

Permalink
feat: add zap flag to reset the environment
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed May 13, 2024
1 parent de1eae5 commit e92f7b3
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cmd/yap/command/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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")
}
52 changes: 52 additions & 0 deletions cmd/yap/command/zap.go
Original file line number Diff line number Diff line change
@@ -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)
}
7 changes: 7 additions & 0 deletions pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit e92f7b3

Please sign in to comment.