From 8bdc4d3f8044b1a20e10a9f519b5f738e8188877 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Thu, 24 Mar 2022 12:49:36 +0100 Subject: [PATCH] fix: help command (#2681) --- pkg/commands/executor.go | 2 +- scripts/expand_website_templates/main.go | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/commands/executor.go b/pkg/commands/executor.go index 622b5372bff8..d9c747f6f1b5 100644 --- a/pkg/commands/executor.go +++ b/pkg/commands/executor.go @@ -110,7 +110,7 @@ func NewExecutor(version, commit, date string) *Executor { e.log.Fatalf("Can't read config: %s", err) } - if commandLineCfg.Run.Go == "" && e.cfg.Run.Go == "" { + if (commandLineCfg == nil || commandLineCfg.Run.Go == "") && e.cfg != nil && e.cfg.Run.Go == "" { e.cfg.Run.Go = config.DetectGoVersion() } diff --git a/scripts/expand_website_templates/main.go b/scripts/expand_website_templates/main.go index c1afb699e633..c3247c8cd26e 100644 --- a/scripts/expand_website_templates/main.go +++ b/scripts/expand_website_templates/main.go @@ -143,22 +143,22 @@ func getLatestVersion() (string, error) { http.NoBody, ) if err != nil { - return "", fmt.Errorf("failed to prepare a http request: %s", err) + return "", fmt.Errorf("failed to prepare a http request: %w", err) } req.Header.Add("Accept", "application/vnd.github.v3+json") resp, err := http.DefaultClient.Do(req) if err != nil { - return "", fmt.Errorf("failed to get http response for the latest tag: %s", err) + return "", fmt.Errorf("failed to get http response for the latest tag: %w", err) } defer resp.Body.Close() body, err := io.ReadAll(resp.Body) if err != nil { - return "", fmt.Errorf("failed to read a body for the latest tag: %s", err) + return "", fmt.Errorf("failed to read a body for the latest tag: %w", err) } release := latestRelease{} err = json.Unmarshal(body, &release) if err != nil { - return "", fmt.Errorf("failed to unmarshal the body for the latest tag: %s", err) + return "", fmt.Errorf("failed to unmarshal the body for the latest tag: %w", err) } return release.TagName, nil } @@ -166,21 +166,21 @@ func getLatestVersion() (string, error) { func buildTemplateContext() (map[string]string, error) { golangciYamlExample, err := os.ReadFile(".golangci.example.yml") if err != nil { - return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err) + return nil, fmt.Errorf("can't read .golangci.example.yml: %w", err) } snippets, err := extractExampleSnippets(golangciYamlExample) if err != nil { - return nil, fmt.Errorf("can't read .golangci.example.yml: %s", err) + return nil, fmt.Errorf("can't read .golangci.example.yml: %w", err) } if err = exec.Command("make", "build").Run(); err != nil { - return nil, fmt.Errorf("can't run go install: %s", err) + return nil, fmt.Errorf("can't run go install: %w", err) } lintersOut, err := exec.Command("./golangci-lint", "help", "linters").Output() if err != nil { - return nil, fmt.Errorf("can't run linters cmd: %s", err) + return nil, fmt.Errorf("can't run linters cmd: %w", err) } lintersOutParts := bytes.Split(lintersOut, []byte("\n\n")) @@ -190,7 +190,7 @@ func buildTemplateContext() (map[string]string, error) { helpCmd.Env = append(helpCmd.Env, "HELP_RUN=1") // make default concurrency stable: don't depend on machine CPU number help, err := helpCmd.Output() if err != nil { - return nil, fmt.Errorf("can't run help cmd: %s", err) + return nil, fmt.Errorf("can't run help cmd: %w", err) } helpLines := bytes.Split(help, []byte("\n")) @@ -202,7 +202,7 @@ func buildTemplateContext() (map[string]string, error) { latestVersion, err := getLatestVersion() if err != nil { - return nil, fmt.Errorf("failed to get latest version: %s", err) + return nil, fmt.Errorf("failed to get the latest version: %w", err) } return map[string]string{