🎨 大部分的 make 指令
This commit is contained in:
35
internal/controller/maker/check.go
Normal file
35
internal/controller/maker/check.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package maker
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
func (m *maker) DependencyCheck(ctx context.Context) error {
|
||||
// 1. test wget command
|
||||
if err := checkCommand(ctx, "wget", "--version"); err != nil {
|
||||
return fmt.Errorf("wget 命令未找到: %w", err)
|
||||
}
|
||||
|
||||
// 2. test tar command
|
||||
if err := checkCommand(ctx, "tar", "--version"); err != nil {
|
||||
return fmt.Errorf("tar 命令未找到: %w", err)
|
||||
}
|
||||
|
||||
// 3. test docker command
|
||||
if err := checkCommand(ctx, "docker", "info"); err != nil {
|
||||
return fmt.Errorf("docker 命令未找到: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// checkCommand checks if a command is available by running it with the specified args
|
||||
func checkCommand(ctx context.Context, name string, args ...string) error {
|
||||
cmd := exec.CommandContext(ctx, name, args...)
|
||||
if err := cmd.Run(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user