MCPcopy
hub / github.com/keploy/keploy / FindDockerCmd

Function FindDockerCmd

utils/utils.go:576–607  ·  view source on GitHub ↗

FindDockerCmd checks if the cli is related to docker or not, it also returns if it is a docker compose file

(cmd string)

Source from the content-addressed store, hash-verified

574
575// FindDockerCmd checks if the cli is related to docker or not, it also returns if it is a docker compose file
576func FindDockerCmd(cmd string) CmdType {
577 if cmd == "" {
578 return Empty
579 }
580 // Convert command to lowercase for case-insensitive comparison
581 cmdLower := strings.TrimSpace(strings.ToLower(cmd))
582
583 // Define patterns for Docker and Docker Compose
584 dockerRunPatterns := []string{"docker run", "sudo docker run", "docker container run", "sudo docker container run"}
585 dockerStartPatterns := []string{"docker start", "sudo docker start", "docker container start", "sudo docker container start"}
586 dockerComposePatterns := []string{"docker-compose", "sudo docker-compose", "docker compose", "sudo docker compose"}
587
588 // Check for Docker Compose command patterns and file extensions
589 for _, pattern := range dockerComposePatterns {
590 if strings.HasPrefix(cmdLower, pattern) {
591 return DockerCompose
592 }
593 }
594 // Check for Docker start command patterns
595 for _, pattern := range dockerStartPatterns {
596 if strings.HasPrefix(cmdLower, pattern) {
597 return DockerStart
598 }
599 }
600 // Check for Docker run command patterns
601 for _, pattern := range dockerRunPatterns {
602 if strings.HasPrefix(cmdLower, pattern) {
603 return DockerRun
604 }
605 }
606 return Native
607}
608
609type CmdType string
610

Callers 5

NewAppFunction · 0.92
runMethod · 0.92
ValidateFlagsMethod · 0.92
ExecuteCommandFunction · 0.85
ShouldReexecWithSudoFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected