From 743b73c1515abe1bf480b7d4926dbc3b6f9fad3f Mon Sep 17 00:00:00 2001 From: kcmvp Date: Sun, 28 Jan 2024 12:45:11 +0800 Subject: [PATCH] add test --- cmd/action.go | 18 ++++++++---------- cmd/deps.go | 9 +-------- internal/project.go | 8 +------- 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/cmd/action.go b/cmd/action.go index e3b0e68..ec42e56 100644 --- a/cmd/action.go +++ b/cmd/action.go @@ -43,20 +43,17 @@ func beforeExecution(cmd *cobra.Command, arg string) error { return nil } -func afterExecution(cmd *cobra.Command, arg string) error { +func afterExecution(cmd *cobra.Command, arg string) { if action, ok := lo.Find(buildActions(), func(action Action) bool { return action.A == fmt.Sprintf("after_%s", arg) }); ok { - return action.B(cmd, arg) + action.B(cmd, arg) //nolint } - return nil } func execute(cmd *cobra.Command, arg string) error { - err := beforeExecution(cmd, arg) - if err != nil { - return err - } + beforeExecution(cmd, arg) //nolint + var err error if plugin, ok := lo.Find(internal.CurProject().Plugins(), func(plugin internal.Plugin) bool { return plugin.Alias == arg }); ok { @@ -68,10 +65,11 @@ func execute(cmd *cobra.Command, arg string) error { } else { return fmt.Errorf(color.RedString("can not find command %s", arg)) } - if err == nil { - return afterExecution(cmd, arg) + if err != nil { + return err } - return err + afterExecution(cmd, arg) + return nil } func validBuilderArgs() []string { diff --git a/cmd/deps.go b/cmd/deps.go index 26bb195..1fe7280 100644 --- a/cmd/deps.go +++ b/cmd/deps.go @@ -53,10 +53,7 @@ func dependency() (treeprint.Tree, error) { if err != nil { return tree, fmt.Errorf(color.RedString(err.Error())) } - if _, err = exec.Command("go", "mod", "tidy").CombinedOutput(); err != nil { - return tree, fmt.Errorf(color.RedString(err.Error())) - } - + exec.Command("go", "mod", "tidy").CombinedOutput() //nolint if _, err = exec.Command("go", "build", "./...").CombinedOutput(); err != nil { return tree, fmt.Errorf(color.RedString(err.Error())) } @@ -81,10 +78,6 @@ func dependency() (treeprint.Tree, error) { } } } - - if err = scanner.Err(); err != nil { - return tree, fmt.Errorf(err.Error()) - } // parse the dependency tree cache := []string{os.Getenv("GOPATH"), "pkg", "mod", "cache", "download"} for _, dependency := range dependencies { diff --git a/internal/project.go b/internal/project.go index 8c48a27..d47b4f0 100644 --- a/internal/project.go +++ b/internal/project.go @@ -158,10 +158,7 @@ func (project *Project) Target() string { 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, err := cmd.Output() - if err != nil { - return []string{}, err - } + output, _ := cmd.Output() scanner := bufio.NewScanner(strings.NewReader(string(output))) var dirs []string for scanner.Scan() { @@ -170,9 +167,6 @@ func (project *Project) sourceFileInPkg(pkg string) ([]string, error) { dirs = append(dirs, line) } } - if err = scanner.Err(); err != nil { - return []string{}, err - } return dirs, nil }