@@ -46,15 +46,16 @@ var mainMenuItems = []menuItem{
4646 {"6" , "查看服务配置 (指定)" },
4747 {"7" , "进入容器 (指定)" },
4848 {"8" , "编译服务 (所有/指定)" },
49- {"9" , "清理服务 (所有/指定)" },
50- {"10" , "删除镜像 (所有/指定)" },
51- {"11" , "一键启动日志监控服务栈 (ELK/Graylog 等)" },
52- {"12" , "一键启动数据库服务栈 (MySQL/Redis/Clickhouse)" },
53- {"13" , "清理 Docker build 缓存" },
54- {"14" , "清理 Docker buildx 缓存" },
55- {"15" , "网络管理" },
56- {"16" , "卷管理" },
57- {"17" , "镜像管理" },
49+ {"9" , "强制重构 (所有/指定) - 不使用缓存" },
50+ {"10" , "清理服务 (所有/指定)" },
51+ {"11" , "删除镜像 (所有/指定)" },
52+ {"12" , "一键启动日志监控服务栈 (ELK/Graylog 等)" },
53+ {"13" , "一键启动数据库服务栈 (MySQL/Redis/Clickhouse)" },
54+ {"14" , "清理 Docker build 缓存" },
55+ {"15" , "清理 Docker buildx 缓存" },
56+ {"16" , "网络管理" },
57+ {"17" , "卷管理" },
58+ {"18" , "镜像管理" },
5859 {"100" , "修复服务 (所有/指定) - 重新构建镜像" },
5960}
6061
@@ -63,7 +64,7 @@ func (app *App) RunInteractiveCLI() error {
6364 // 初始化 readline
6465 var err error
6566 app .RLInstance , err = readline .NewEx (& readline.Config {
66- Prompt : fmt .Sprintf ("%s请选择功能 [0-17 ,100]: %s" , ColorCyan , ColorNC ),
67+ Prompt : fmt .Sprintf ("%s请选择功能 [0-18 ,100]: %s" , ColorCyan , ColorNC ),
6768 InterruptPrompt : "^C" ,
6869 EOFPrompt : "exit" ,
6970 })
@@ -331,12 +332,27 @@ func (app *App) handleCLIInput(choice string, services []*commands.Service, allS
331332 }
332333 commandObj := app .DockerCommand .NewCommandObject (commands.CommandObject {Service : s })
333334 // 先 pull 确保镜像最新,再 build。通过 grep 过滤掉没必要的警告信息。
334- fullCmd := fmt .Sprintf ("%s pull %s && %s build --no-cache %s 2>&1 | grep -v 'No services to build' || true" , commandObj .DockerCompose , s .Name , commandObj .DockerCompose , s .Name )
335+ fullCmd := fmt .Sprintf ("%s pull %s && %s build %s 2>&1 | grep -v 'No services to build' || true" , commandObj .DockerCompose , s .Name , commandObj .DockerCompose , s .Name )
335336 cmd := exec .Command ("sh" , "-c" , fullCmd )
336337 _ = app .runSubprocessWithQuitKey (cmd )
337338 return nil
338339 })
339340 case "9" :
341+ app .doServiceAction ("强制重构" , services , true , true , func (s * commands.Service ) error {
342+ if ! s .IsLocal {
343+ fmt .Printf ("%s提示: 该服务属于外部项目,在此处无法执行编译操作。%s\n " , ColorYellow , ColorNC )
344+ fmt .Printf ("\n 按回车键继续..." )
345+ app .ReadInput ("" )
346+ return nil
347+ }
348+ commandObj := app .DockerCommand .NewCommandObject (commands.CommandObject {Service : s })
349+ // 先 pull 确保镜像最新,再使用 --no-cache 强制构建。
350+ fullCmd := fmt .Sprintf ("%s pull %s && %s build --no-cache %s 2>&1 | grep -v 'No services to build' || true" , commandObj .DockerCompose , s .Name , commandObj .DockerCompose , s .Name )
351+ cmd := exec .Command ("sh" , "-c" , fullCmd )
352+ _ = app .runSubprocessWithQuitKey (cmd )
353+ return nil
354+ })
355+ case "10" :
340356 app .doServiceAction ("清理" , services , true , true , func (s * commands.Service ) error {
341357 fmt .Printf ("%s警告: 这将停止并删除服务: %s%s\n " , ColorYellow , s .Name , ColorNC )
342358 fmt .Printf ("确定要继续吗? (y/n): " )
@@ -352,7 +368,7 @@ func (app *App) handleCLIInput(choice string, services []*commands.Service, allS
352368 }
353369 return s .Remove (container.RemoveOptions {Force : true })
354370 })
355- case "10 " :
371+ case "11 " :
356372 app .doServiceAction ("删除镜像" , services , true , false , func (s * commands.Service ) error {
357373 if s .Container == nil {
358374 return fmt .Errorf ("无法获取服务 %s 的快照信息" , s .Name )
@@ -363,25 +379,25 @@ func (app *App) handleCLIInput(choice string, services []*commands.Service, allS
363379 _ = app .runSubprocessWithQuitKey (cmd )
364380 return nil
365381 })
366- case "11 " :
382+ case "12 " :
367383 stack := []string {"zookeeper" , "kafka" , "elasticsearch" , "filebeat" , "go-stash" , "jaeger" , "grafana" }
368384 app .runStackAction ("日志监控服务栈" , stack , services )
369- case "12 " :
385+ case "13 " :
370386 stack := []string {"clickhouse" , "mysql" , "redis" }
371387 app .runStackAction ("数据库服务栈" , stack , services )
372- case "13 " :
388+ case "14 " :
373389 fmt .Printf ("\n %s正在清理 Docker 构建缓存...%s\n " , ColorBlue , ColorNC )
374390 cmd := exec .Command ("docker" , "builder" , "prune" , "-f" )
375391 _ = app .runSubprocessWithQuitKey (cmd )
376- case "14 " :
392+ case "15 " :
377393 fmt .Printf ("\n %s正在清理 Docker 构建历史(含 buildx)...%s\n " , ColorBlue , ColorNC )
378394 cmd := exec .Command ("docker" , "builder" , "prune" , "-af" )
379395 _ = app .runSubprocessWithQuitKey (cmd )
380- case "15" :
381- app .runNetworkManagement ()
382396 case "16" :
383- app .runVolumeManagement ()
397+ app .runNetworkManagement ()
384398 case "17" :
399+ app .runVolumeManagement ()
400+ case "18" :
385401 app .runImageManagement ()
386402 case "100" :
387403 app .doServiceAction ("修复" , services , true , false , func (s * commands.Service ) error {
@@ -1001,8 +1017,12 @@ func (app *App) ReadInput(prompt string) string {
10011017func (app * App ) runActionFzf (serviceName string ) string {
10021018 var menuBuilder strings.Builder
10031019 for _ , item := range mainMenuItems {
1004- // 过滤掉一些不适合单服务操作的全局项 (可选)
1005- menuBuilder .WriteString (fmt .Sprintf ("%s: %s\n " , item .ID , item .Text ))
1020+ // 仅展示序号 1-10 的单服务相关操作
1021+ idNum := 0
1022+ fmt .Sscanf (item .ID , "%d" , & idNum )
1023+ if idNum >= 1 && idNum <= 11 {
1024+ menuBuilder .WriteString (fmt .Sprintf ("%s: %s\n " , item .ID , item .Text ))
1025+ }
10061026 }
10071027 menuData := strings .TrimSpace (menuBuilder .String ())
10081028 lines := strings .Split (menuData , "\n " )
@@ -1111,17 +1131,24 @@ func (app *App) executeActionOnService(actionID string, s *commands.Service, all
11111131 case "8" :
11121132 if s .IsLocal {
11131133 commandObj := app .DockerCommand .NewCommandObject (commands.CommandObject {Service : s })
1114- fullCmd := fmt .Sprintf ("%s pull %s && %s build --no-cache %s " , commandObj .DockerCompose , s .Name , commandObj .DockerCompose , s .Name )
1134+ fullCmd := fmt .Sprintf ("%s pull %s && %s build %s 2>&1 | grep -v 'No services to build' || true " , commandObj .DockerCompose , s .Name , commandObj .DockerCompose , s .Name )
11151135 cmd := exec .Command ("sh" , "-c" , fullCmd )
11161136 _ = app .runSubprocessWithQuitKey (cmd )
11171137 }
11181138 case "9" :
1139+ if s .IsLocal {
1140+ commandObj := app .DockerCommand .NewCommandObject (commands.CommandObject {Service : s })
1141+ fullCmd := fmt .Sprintf ("%s pull %s && %s build --no-cache %s 2>&1 | grep -v 'No services to build' || true" , commandObj .DockerCompose , s .Name , commandObj .DockerCompose , s .Name )
1142+ cmd := exec .Command ("sh" , "-c" , fullCmd )
1143+ _ = app .runSubprocessWithQuitKey (cmd )
1144+ }
1145+ case "10" :
11191146 fmt .Printf ("%s确定要清理服务 %s 吗? (y/n): %s" , ColorYellow , s .Name , ColorNC )
11201147 if strings .ToLower (app .ReadInput ("" )) == "y" {
11211148 _ = s .Stop ()
11221149 _ = s .Remove (container.RemoveOptions {Force : true })
11231150 }
1124- case "10 " :
1151+ case "11 " :
11251152 if s .Container != nil {
11261153 imageID := s .Container .Container .ImageID
11271154 cmd := exec .Command ("docker" , "rmi" , "-f" , imageID )
@@ -1181,7 +1208,7 @@ func (app *App) runMenuSearchFzf() string {
11811208 code , _ := fzf .Run (opts )
11821209
11831210 app .RLInstance , _ = readline .NewEx (& readline.Config {
1184- Prompt : fmt .Sprintf ("%s请选择功能 [0-17 ,100]: %s" , ColorCyan , ColorNC ),
1211+ Prompt : fmt .Sprintf ("%s请选择功能 [0-18 ,100]: %s" , ColorCyan , ColorNC ),
11851212 InterruptPrompt : "^C" ,
11861213 EOFPrompt : "exit" ,
11871214 })
@@ -1244,7 +1271,7 @@ func (app *App) runServiceSearchFzf(allServices []*commands.Service) string {
12441271 code , _ := fzf .Run (opts )
12451272
12461273 app .RLInstance , _ = readline .NewEx (& readline.Config {
1247- Prompt : fmt .Sprintf ("%s请选择功能 [0-17 ,100]: %s" , ColorCyan , ColorNC ),
1274+ Prompt : fmt .Sprintf ("%s请选择功能 [0-18 ,100]: %s" , ColorCyan , ColorNC ),
12481275 InterruptPrompt : "^C" ,
12491276 EOFPrompt : "exit" ,
12501277 })
0 commit comments