Commit 8168a446 authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

go fix

parent 184ac0d2
Loading
Loading
Loading
Loading
+2 −6
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import (
	"io"
	"os"
	"reflect"
	"slices"
	"sort"
	"strings"
	"testing"
@@ -180,12 +181,7 @@ func availableCommandNames(root *cobra.Command) []string {
}

func contains(values []string, needle string) bool {
	for _, v := range values {
		if v == needle {
			return true
		}
	}
	return false
	return slices.Contains(values, needle)
}

func withDiscardedStdIO(t *testing.T, fn func()) {
+3 −3
Original line number Diff line number Diff line
@@ -262,10 +262,10 @@ func resolveLocale(args []string) string {
}

func langFromArgs(args []string) string {
	for i := 0; i < len(args); i++ {
	for i := range args {
		arg := strings.TrimSpace(args[i])
		if strings.HasPrefix(arg, "--lang=") {
			return strings.TrimSpace(strings.TrimPrefix(arg, "--lang="))
		if after, ok := strings.CutPrefix(arg, "--lang="); ok {
			return strings.TrimSpace(after)
		}
		if arg == "--lang" && i+1 < len(args) {
			return strings.TrimSpace(args[i+1])
+8 −13
Original line number Diff line number Diff line
@@ -188,7 +188,7 @@ type projectRow struct {

type projectRecord struct {
	Path string      `json:"path"`
	Meta projectMeta `json:"meta,omitempty"`
	Meta projectMeta `json:"meta"`
}

type projectsStore struct {
@@ -1189,9 +1189,7 @@ func (p *downloadProgress) Write(b []byte) (int, error) {

func (p *downloadProgress) start() {
	p.render("|")
	p.wg.Add(1)
	go func() {
		defer p.wg.Done()
	p.wg.Go(func() {
		frames := []string{"|", "/", "-", "\\"}
		ticker := time.NewTicker(120 * time.Millisecond)
		defer ticker.Stop()
@@ -1205,7 +1203,7 @@ func (p *downloadProgress) start() {
				frameIndex++
			}
		}
	}()
	})
}

func (p *downloadProgress) finish() {
@@ -1220,10 +1218,7 @@ func (p *downloadProgress) render(frame string) {
	current := p.written.Load()
	base := T("msg.download_progress", p.label)
	if p.totalBytes > 0 {
		percent := int((float64(current) / float64(p.totalBytes)) * 100)
		if percent > 100 {
			percent = 100
		}
		percent := min(int((float64(current)/float64(p.totalBytes))*100), 100)
		fmt.Fprintf(
			os.Stderr,
			"\r%s %s %3d%% (%s/%s)",
@@ -1400,8 +1395,8 @@ func syncBundles(rootDirectory string) error {
				_ = os.Rename(filepath.Join(officialBundlesDir, dirName), bundleDir)
				_ = os.Remove(bundleArchivePath)
			}
			if strings.HasPrefix(bundle.URL, "local://") {
				zipName := strings.TrimPrefix(bundle.URL, "local://")
			if after, ok := strings.CutPrefix(bundle.URL, "local://"); ok {
				zipName := after
				bundleArchivePath := filepath.Join(dotMaxDir, "resources", "local_bundles", zipName)
				if err := extractArchive(bundleArchivePath, officialBundlesDir); err != nil {
					return err
@@ -1827,7 +1822,7 @@ func runInfo(directory string, jsonOut bool) error {
	}

	if jsonOut {
		out := map[string]interface{}{
		out := map[string]any{
			"max_version":       config.Cfg.Version.Name,
			"title":             config.title(),
			"environment":       config.Cfg.Env,
@@ -2627,7 +2622,7 @@ func runProjects(jsonOut bool) error {
	}

	if jsonOut {
		payload := map[string]interface{}{"projects": out}
		payload := map[string]any{"projects": out}
		b, _ := json.MarshalIndent(payload, "", "    ")
		fmt.Println(string(b))
		return nil