Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
kcmvp committed Jan 28, 2024
1 parent 44f8dae commit 743b73c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 25 deletions.
18 changes: 8 additions & 10 deletions cmd/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
9 changes: 1 addition & 8 deletions cmd/deps.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()))
}
Expand All @@ -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 {
Expand Down
8 changes: 1 addition & 7 deletions internal/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}

Expand Down

0 comments on commit 743b73c

Please sign in to comment.