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

#109: code clean up #112

Merged
merged 1 commit into from
May 20, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading