Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/UI term #71

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ linters:
# here some dropped deprecated checks
# reduce warning messages
- deadcode
- execinquery
- exhaustivestruct
- golint
- ifshort
- interfacer
- maligned
- mnd
- nosnakecase
- scopelint
- structcheck
Expand Down
31 changes: 7 additions & 24 deletions cmd/yap/command/build.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package command

import (
"fmt"
"log"
"path/filepath"
"strings"

"github.com/M0Rf30/yap/pkg/constants"
"github.com/M0Rf30/yap/pkg/parser"
"github.com/M0Rf30/yap/pkg/pkgbuild"
"github.com/M0Rf30/yap/pkg/project"
"github.com/M0Rf30/yap/pkg/source"
"github.com/M0Rf30/yap/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -22,7 +20,6 @@ var (
Args: cobra.MinimumNArgs(2),
Run: func(_ *cobra.Command, args []string) {
fullJSONPath, _ := filepath.Abs(args[1])

split := strings.Split(args[0], "-")
distro := split[0]
release := ""
Expand All @@ -34,29 +31,13 @@ var (
mpc := project.MultipleProject{}
err := mpc.MultiProject(distro, release, fullJSONPath)
if err != nil {
fmt.Printf("%s❌ :: %sError:\n%s",
string(constants.ColorBlue),
string(constants.ColorYellow),
string(constants.ColorWhite))
log.Fatal(err)
}

if project.CleanBuild {
if err := mpc.Clean(); err != nil {
fmt.Printf("%s❌ :: %sError:\n%s",
string(constants.ColorBlue),
string(constants.ColorYellow),
string(constants.ColorWhite))
log.Fatal(err)
}
utils.Logger.Fatal("fatal error",
utils.Logger.Args("error", err))
}

if err := mpc.BuildAll(); err != nil {
fmt.Printf("%s❌ :: %sError:\n%s",
string(constants.ColorBlue),
string(constants.ColorYellow),
string(constants.ColorWhite))
log.Fatal(err)
utils.Logger.Fatal("fatal error",
utils.Logger.Args("error", err))
}
},
}
Expand All @@ -82,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")
}
19 changes: 10 additions & 9 deletions cmd/yap/command/completion.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package command

import (
"log"
"os"

"github.com/M0Rf30/yap/pkg/utils"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -48,19 +46,22 @@ $ yap completion zsh > "${fpath[1]}/_yap"
Run: func(cmd *cobra.Command, args []string) {
switch args[0] {
case "bash":
err := cmd.Root().GenBashCompletion(os.Stdout)
err := cmd.Root().GenBashCompletion(utils.MultiPrinter.Writer)
if err != nil {
log.Fatal(err)
utils.Logger.Fatal("failed to generate bash completion",
utils.Logger.Args("error", err))
}
case "fish":
err := cmd.Root().GenFishCompletion(os.Stdout, true)
err := cmd.Root().GenFishCompletion(utils.MultiPrinter.Writer, true)
if err != nil {
log.Fatal(err)
utils.Logger.Fatal("failed to generate fish completion",
utils.Logger.Args("error", err))
}
case "zsh":
err := cmd.Root().GenZshCompletion(os.Stdout)
err := cmd.Root().GenZshCompletion(utils.MultiPrinter.Writer)
if err != nil {
log.Fatal(err)
utils.Logger.Fatal("failed to generate zsh completion",
utils.Logger.Args("error", err))
}
}
},
Expand Down
10 changes: 8 additions & 2 deletions cmd/yap/command/container.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package command

import (
"log"
"strings"

"github.com/M0Rf30/yap/pkg/utils"
"github.com/spf13/cobra"
Expand All @@ -13,8 +13,14 @@ var containerCmd = &cobra.Command{
Short: "Pull the built images",
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
split := strings.Split(args[0], "-")
if len(split) <= 1 {
utils.Logger.Fatal("for pre-built container images specify also the codename (i. e. rocky-9, ubuntu-focal)")
}

err := utils.PullContainers(args[0])
log.Fatal(err)
utils.Logger.Fatal("failed to pull containers",
utils.Logger.Args("error", err))
},
}

Expand Down
5 changes: 2 additions & 3 deletions cmd/yap/command/list_targets.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package command

import (
"fmt"

"github.com/M0Rf30/yap/pkg/constants"
"github.com/pterm/pterm"
"github.com/spf13/cobra"
)

Expand All @@ -18,7 +17,7 @@ var listTargetsCmd = &cobra.Command{

func ListTargets() {
for _, release := range constants.Releases {
fmt.Println(release)
pterm.Println(release)
}
}

Expand Down
19 changes: 6 additions & 13 deletions cmd/yap/command/prepare.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package command

import (
"fmt"
"log"
"strings"

"github.com/M0Rf30/yap/pkg/constants"
"github.com/M0Rf30/yap/pkg/packer"
"github.com/M0Rf30/yap/pkg/pkgbuild"
"github.com/M0Rf30/yap/pkg/project"
"github.com/M0Rf30/yap/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -27,25 +25,20 @@ var (
packageManager := packer.GetPackageManager(&pkgbuild.PKGBUILD{}, distro)
if !project.SkipSyncDeps {
if err := packageManager.Update(); err != nil {
log.Fatal(err)
utils.Logger.Error(err.Error(),
utils.Logger.Args("error", err))
}
}

err := packageManager.PrepareEnvironment(GoLang)
if err != nil {
log.Fatal(err)
utils.Logger.Error(err.Error())
}

fmt.Printf("%s🪛 :: %sBasic build environment successfully prepared%s\n",
string(constants.ColorBlue),
string(constants.ColorYellow),
string(constants.ColorWhite))
utils.Logger.Info("basic build environment successfully prepared")

if GoLang {
fmt.Printf("%s🪛 :: %sGO successfully installed%s\n",
string(constants.ColorBlue),
string(constants.ColorYellow),
string(constants.ColorWhite))
utils.Logger.Info("go successfully installed")
}
},
}
Expand Down
18 changes: 15 additions & 3 deletions cmd/yap/command/version.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package command

import (
"fmt"

"github.com/pterm/pterm"
"github.com/pterm/pterm/putils"
"github.com/spf13/cobra"
)

Expand All @@ -11,7 +11,19 @@ var versionCmd = &cobra.Command{
Short: "Print the version number of Yap",
Long: `All software has versions. This is Yap's`,
Run: func(_ *cobra.Command, _ []string) {
fmt.Println("Yap v1.9")
logo, _ := pterm.DefaultBigText.WithLetters(
putils.LettersFromStringWithStyle("Y", pterm.NewStyle(pterm.FgBlue)),
putils.LettersFromStringWithStyle("A", pterm.NewStyle(pterm.FgLightBlue)),
putils.LettersFromStringWithStyle("P", pterm.NewStyle(pterm.FgLightCyan))).
Srender()

pterm.DefaultCenter.Print(logo)

pterm.DefaultCenter.Print(
pterm.DefaultHeader.WithFullWidth().WithMargin(10).Sprint("Yet Another Packager"))

pterm.Println("Version v1.9")
pterm.Println("Coded with \u2764 by M0Rf30")
},
}

Expand Down
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)
}
3 changes: 1 addition & 2 deletions examples/yap.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"output": "artifacts",
"projects": [
{
"name": "yap",
"install": true
"name": "yap"
}
]
}
10 changes: 10 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/mholt/archiver/v4 v4.0.0-alpha.8.0.20240213202252-43a073ede779
github.com/otiai10/copy v1.14.0
github.com/pkg/errors v0.9.1
github.com/pterm/pterm v0.12.79
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
mvdan.cc/sh/v3 v3.8.0
Expand All @@ -24,6 +25,9 @@ require (
)

require (
atomicgo.dev/cursor v0.2.0 // indirect
atomicgo.dev/keyboard v0.2.9 // indirect
atomicgo.dev/schedule v0.1.0 // indirect
dario.cat/mergo v1.0.0 // indirect
github.com/Microsoft/go-winio v0.6.1 // indirect
github.com/ProtonMail/go-crypto v1.0.0 // indirect
Expand All @@ -33,6 +37,7 @@ require (
github.com/bodgit/sevenzip v1.4.3 // indirect
github.com/bodgit/windows v1.0.1 // indirect
github.com/cloudflare/circl v1.3.7 // indirect
github.com/containerd/console v1.0.3 // indirect
github.com/cyphar/filepath-securejoin v0.2.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dsnet/compress v0.0.1 // indirect
Expand All @@ -43,6 +48,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/gookit/color v1.5.4 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -51,16 +57,20 @@ require (
github.com/klauspost/compress v1.16.7 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/lithammer/fuzzysearch v1.1.8 // indirect
github.com/mattn/go-runewidth v0.0.15 // indirect
github.com/nwaples/rardecode/v2 v2.0.0-beta.2 // indirect
github.com/pierrec/lz4/v4 v4.1.18 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/therootcompany/xz v1.0.1 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/crypto v0.21.0 // indirect
golang.org/x/net v0.22.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions pkg/apk/apk.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (a *Apk) Install(artifactsPath string) error {

pkgFilePath := filepath.Join(artifactsPath, a.PKGBUILD.PkgName, arch, pkgName)

if err := utils.Exec("",
if err := utils.Exec(true,
"apk",
"add",
"--allow-untrusted",
Expand Down Expand Up @@ -109,7 +109,7 @@ func (a *Apk) PrepareEnvironment(golang bool) error {
args = append(args, "go")
}

return utils.Exec("", "apk", args...)
return utils.Exec(true, "", "apk", args...)
}

// Update updates the APK package manager's package database.
Expand All @@ -121,14 +121,14 @@ func (a *Apk) Update() error {
// apkBuild compiles the APK package using 'abuild-keygen' and 'abuild'.
// It returns an error if any compilation step fails.
func (a *Apk) apkBuild(artifactsPath string) error {
if err := utils.Exec(a.apkDir,
if err := utils.Exec(true, a.apkDir,
"abuild-keygen",
"-n",
"-a"); err != nil {
return err
}

if err := utils.Exec(a.apkDir,
if err := utils.Exec(true, a.apkDir,
"abuild",
"-F",
"-K",
Expand Down
Loading
Loading