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

fix: help command #2681

Merged
merged 1 commit into from Mar 24, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/commands/executor.go
Expand Up @@ -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()
}

Expand Down
20 changes: 10 additions & 10 deletions scripts/expand_website_templates/main.go
Expand Up @@ -143,44 +143,44 @@ 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
}

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"))
Expand All @@ -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"))
Expand All @@ -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{
Expand Down