From 3a6d9497dd6f626abfdbdd883c2e6ab69d3a2c51 Mon Sep 17 00:00:00 2001 From: kcmvp Date: Mon, 20 May 2024 22:56:43 +0800 Subject: [PATCH] #109: code clean up --- cmd/gbc/artifact/project.go | 17 ----------------- cmd/gbc/command/root.go | 7 +++---- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/cmd/gbc/artifact/project.go b/cmd/gbc/artifact/project.go index a3806dd..4b5a06b 100644 --- a/cmd/gbc/artifact/project.go +++ b/cmd/gbc/artifact/project.go @@ -1,7 +1,6 @@ package artifact import ( - "bufio" "errors" "fmt" "github.com/fatih/color" //nolint @@ -128,22 +127,6 @@ func (project *Project) Target() string { return target } -// sourceFileInPkg return all go source file in a package -func (project *Project) sourceFileInPkg(pkg string) ([]string, error) { - _ = os.Chdir(project.Root()) - cmd := exec.Command("go", "list", "-f", fmt.Sprintf("{{if eq .Name \"%s\"}}{{.Dir}}{{end}}", pkg), "./...") - output, _ := cmd.Output() - scanner := bufio.NewScanner(strings.NewReader(string(output))) - var dirs []string - for scanner.Scan() { - line := strings.TrimSpace(scanner.Text()) - if len(line) > 0 { - dirs = append(dirs, line) - } - } - return dirs, nil -} - func (project *Project) MainFiles() []string { return lo.FilterMap(project.pkgs, func(pkg *packages.Package, _ int) (string, bool) { if pkg.Name != "main" { diff --git a/cmd/gbc/command/root.go b/cmd/gbc/command/root.go index d446ea0..8974a14 100644 --- a/cmd/gbc/command/root.go +++ b/cmd/gbc/command/root.go @@ -42,23 +42,22 @@ func usageTemplate() string { return usage } -func parseArtifacts(cmd *cobra.Command, args []string, name string) (gjson.Result, error) { +func parseArtifacts(cmd *cobra.Command, args []string, section string) (gjson.Result, error) { var result gjson.Result var data []byte var err error if test, uqf := utils.TestCaller(); test { data, err = os.ReadFile(filepath.Join(artifact.CurProject().Root(), "target", uqf, "config.json")) } else { - path.Join() data, err = resources.ReadFile(path.Join(resourceDir, "config.json")) } if err != nil { return result, err } key := strings.ReplaceAll(cmd.CommandPath(), " ", "_") - result = gjson.GetBytes(data, fmt.Sprintf("%s.%s", key, name)) + result = gjson.GetBytes(data, fmt.Sprintf("%s.%s", key, section)) if !result.Exists() { - result = gjson.GetBytes(data, fmt.Sprintf("%s_%s.%s", key, strings.Join(args, "_"), name)) + result = gjson.GetBytes(data, fmt.Sprintf("%s_%s.%s", key, strings.Join(args, "_"), section)) } return result, nil }