feat: 🚛 完成了 client 资源创建
This commit is contained in:
28
internal/controller/maker/command.go
Normal file
28
internal/controller/maker/command.go
Normal file
@@ -0,0 +1,28 @@
|
||||
package maker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func (m *maker) RunCommand(ctx context.Context, dir string, _cmds ...string) error {
|
||||
if len(_cmds) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, cmdStr := range _cmds {
|
||||
cmd := exec.CommandContext(ctx, "sh", "-c", cmdStr)
|
||||
|
||||
if dir != "" {
|
||||
cmd.Dir = dir
|
||||
}
|
||||
|
||||
// Execute the command
|
||||
if err := cmd.Run(); err != nil {
|
||||
return fmt.Errorf("failed to run command '%s' in directory '%s': %w", cmdStr, dir, err)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user