Skip to content

boss modernize #189

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
528 changes: 262 additions & 266 deletions .golangci.yml

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ builds:
goos:
- linux
- windows
- darwin
ldflags:
- github.com/hashload/boss/internal/version.metadata={{.Version}}
- github.com/hashload/boss/internal/version.gitCommit={{.Commit}}
Expand Down
2 changes: 0 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,4 @@ repos:
rev: v1.64.5
hooks:
- id: golangci-lint-config-verify
entry: go tool golangci-lint config verify
- id: golangci-lint-full
entry: go tool golangci-lint run --fix
5 changes: 4 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,12 @@
"type": "go",
"request": "launch",
"mode": "auto",
"console": "integratedTerminal",
"program": "${workspaceFolder}",
"cwd": "${workspaceFolder}/test_dir",
"args": ["install", "jhonson"],
// "args": ["install", "jhonson"],
"args": ["install", "https://github.com/ModernDelphiWorks/fluent4d.git"],
// "args": ["upgrade"],
}
]
}
2 changes: 1 addition & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import (

func main() {
if err := cmd.Execute(); err != nil {
msg.Die(err.Error())
msg.Fatal(err.Error())
}
}
1 change: 0 additions & 1 deletion cmd/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ func RegisterConfigCommand(root *cobra.Command) {

root.AddCommand(configCmd)
delphiCmd(configCmd)
registryGitCmd(configCmd)
}
19 changes: 15 additions & 4 deletions cmd/config/delphi.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@ func delphiCmd(root *cobra.Command) {
Use: "delphi",
Short: "Configure Delphi version",
Long: `Configure Delphi version to compile modules`,
Run: func(cmd *cobra.Command, _ []string) {
msg.Info("Running in path %s", env.GlobalConfiguration().DelphiPath)
_ = cmd.Usage()
},
}

list := &cobra.Command{
Expand All @@ -40,6 +36,20 @@ func delphiCmd(root *cobra.Command) {
},
}

current := &cobra.Command{
Use: "current",
Short: "Show current Delphi version",
Long: `Show current Delphi version to compile modules`,
Run: func(_ *cobra.Command, _ []string) {
config := env.GlobalConfiguration()
if config.DelphiPath == "" {
msg.Warn("No Delphi version set")
return
}
msg.Info("Current Delphi version: %s", config.DelphiPath)
},
}

use := &cobra.Command{
Use: "use [path]",
Short: "Use Delphi version",
Expand Down Expand Up @@ -75,4 +85,5 @@ func delphiCmd(root *cobra.Command) {

delphiCmd.AddCommand(list)
delphiCmd.AddCommand(use)
delphiCmd.AddCommand(current)
}
54 changes: 0 additions & 54 deletions cmd/config/git.go

This file was deleted.

11 changes: 8 additions & 3 deletions cmd/config/purgeCache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ func RegisterCmd(cmd *cobra.Command) {
Short: "Configure cache",
}

cleanAll := false

rmCacheCmd := &cobra.Command{
Use: "rm",
Short: "Remove cache",
Use: "clean",
Aliases: []string{"rm"},
Short: "Clean cache based on TTL and usage",
RunE: func(_ *cobra.Command, _ []string) error {
return gc.RunGC(true)
return gc.CleanupCache(true, cleanAll)
},
}

rmCacheCmd.Flags().BoolVarP(&cleanAll, "all", "a", false, "clean all cache")

purgeCacheCmd.AddCommand(rmCacheCmd)

cmd.AddCommand(purgeCacheCmd)
Expand Down
8 changes: 5 additions & 3 deletions cmd/dependencies.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ func printDependencies(showVersion bool) {
pkg, err := models.LoadPackage(false)
if err != nil {
if os.IsNotExist(err) {
msg.Die("boss.json not exists in " + env.GetCurrentDir())
msg.Fatal("boss.json not exists in " + env.GetCurrentDir())
} else {
msg.Die("Fail on open dependencies file: %s", err)
msg.Fatal("Fail on open dependencies file: %s", err)
}
}

Expand All @@ -83,7 +83,9 @@ func printDeps(dep *models.Dependency,
}

for _, dep := range deps {
pkgModule, err := models.LoadPackageOther(filepath.Join(env.GetModulesDir(), dep.Name(), consts.FilePackage))
pkgModule, err := models.LoadPackageFromFile(
filepath.Join(env.GetModulesDir(), dep.Name(), consts.FilePackage),
)
if err != nil {
printSingleDependency(&dep, lock, localTree, showVersion)
} else {
Expand Down
2 changes: 1 addition & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func doInitialization(quiet bool) {

packageData, err := models.LoadPackage(true)
if err != nil && !os.IsNotExist(err) {
msg.Die("Fail on open dependencies file: %s", err)
msg.Fatal("Fail on open dependencies file: %s", err)
}

rxp := regexp.MustCompile(`^.+\` + string(filepath.Separator) + `([^\\]+)$`)
Expand Down
15 changes: 11 additions & 4 deletions cmd/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ func loginCmdRegister(root *cobra.Command) {
root.AddCommand(logoutCmd)
}

func login(removeLogin bool, useSSH bool, privateKey string, userName string, password string, args []string) {
func login(
removeLogin bool,
useSSH bool,
privateKey string,
userName string,
password string,
args []string,
) {
configuration := env.GlobalConfiguration()

if removeLogin {
Expand All @@ -65,7 +72,7 @@ func login(removeLogin bool, useSSH bool, privateKey string, userName string, pa
} else {
repo = getParamOrDef("Url to login (ex: github.com)", "")
if repo == "" {
msg.Die("Empty is not valid!!")
msg.Fatal("Empty is not valid!!")
}
auth = configuration.Auth[repo]
}
Expand Down Expand Up @@ -111,15 +118,15 @@ func setAuthInteractively(auth *env.Auth) {
func getPass(description string) string {
pass, err := pterm.DefaultInteractiveTextInput.WithMask("•").Show(description)
if err != nil {
msg.Die("Error on get pass: %s", err)
msg.Fatal("Error on get pass: %s", err)
}
return pass
}

func getSSHKeyPath() string {
usr, err := user.Current()
if err != nil {
msg.Die(err.Error())
msg.Fatal(err.Error())
}
return filepath.Join(usr.HomeDir, ".ssh", "id_rsa")
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func Execute() error {
dependenciesCmdRegister(root)
versionCmdRegister(root)

if err := gc.RunGC(false); err != nil {
if err := gc.CleanupCache(false, false); err != nil {
return err
}

Expand Down
47 changes: 44 additions & 3 deletions cmd/run.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,60 @@
package cmd

import (
"strings"

"github.com/hashload/boss/pkg/models"
"github.com/hashload/boss/pkg/scripts"
"github.com/spf13/cobra"
)

func runCmdRegister(root *cobra.Command) {
var runScript = &cobra.Command{
Use: "run",
Short: "Run cmd script",
Long: `Run cmd script`,
Use: "run",
Short: "Run cmd script",
Long: `Run cmd script`,
Args: cobra.MinimumNArgs(1),
ValidArgsFunction: validScripts,
Run: func(_ *cobra.Command, args []string) {
scripts.Run(args)
},
}

root.AddCommand(runScript)
}

func validScripts(
_ *cobra.Command,
args []string,
_ string,
) ([]string, cobra.ShellCompDirective) {
packageData, err := models.LoadPackage(false)
if err != nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}

if packageData.Scripts == nil {
return nil, cobra.ShellCompDirectiveNoFileComp
}

var scripts []string
for script := range packageData.Scripts {
scripts = append(scripts, script)
}

if len(args) == 0 {
return scripts, cobra.ShellCompDirectiveDefault
}

if len(args) == 1 {
var completions []string
for _, script := range scripts {
if script != args[0] && strings.HasPrefix(script, args[0]) {
completions = append(completions, script)
}
}
return completions, cobra.ShellCompDirectiveNoFileComp
}

return scripts, cobra.ShellCompDirectiveNoFileComp
}
7 changes: 5 additions & 2 deletions cmd/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"github.com/hashload/boss/internal/upgrade"
"github.com/hashload/boss/pkg/msg"
"github.com/spf13/cobra"
)

Expand All @@ -16,8 +17,10 @@ func upgradeCmdRegister(root *cobra.Command) {

Upgrade boss with pre-release:
boss upgrade --dev`,
RunE: func(_ *cobra.Command, _ []string) error {
return upgrade.BossUpgrade(preRelease)
Run: func(_ *cobra.Command, _ []string) {
if err := upgrade.BossUpgrade(preRelease); err != nil {
msg.Fatal("Failed to upgrade boss: %s", err)
}
},
}

Expand Down
Loading
Loading