Skip to content

Commit

Permalink
feat: terminal ui rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
M0Rf30 committed May 5, 2024
1 parent a289e33 commit 587555f
Show file tree
Hide file tree
Showing 24 changed files with 275 additions and 367 deletions.
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
26 changes: 7 additions & 19 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,20 @@ 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)
utils.Logger.Fatal("fatal error",
utils.Logger.Args("error", 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 Down
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
5 changes: 2 additions & 3 deletions cmd/yap/command/container.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package command

import (
"log"

"github.com/M0Rf30/yap/pkg/utils"
"github.com/spf13/cobra"
)
Expand All @@ -14,7 +12,8 @@ var containerCmd = &cobra.Command{
Args: cobra.MinimumNArgs(1),
Run: func(_ *cobra.Command, args []string) {
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
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.20240408183022-de08bfa4c558
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,17 +57,21 @@ 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/sorairolake/lzip-go v0.3.1 // 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
Loading

0 comments on commit 587555f

Please sign in to comment.