Skip to content

Commit

Permalink
Merge pull request #112 from kcmvp/deps
Browse files Browse the repository at this point in the history
#109: code clean up
  • Loading branch information
kcmvp authored May 20, 2024
2 parents 1e55d87 + 3a6d949 commit b1dd884
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 21 deletions.
17 changes: 0 additions & 17 deletions cmd/gbc/artifact/project.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package artifact

import (
"bufio"
"errors"
"fmt"
"github.com/fatih/color" //nolint
Expand Down Expand Up @@ -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" {
Expand Down
7 changes: 3 additions & 4 deletions cmd/gbc/command/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit b1dd884

Please sign in to comment.