FindDockerCmd checks if the cli is related to docker or not, it also returns if it is a docker compose file ExtractCommandFromArgs parses os.Args to find the value of -c or --command flag. Returns empty string if not found.
(args []string)
| 549 | // ExtractCommandFromArgs parses os.Args to find the value of -c or --command flag. |
| 550 | // Returns empty string if not found. |
| 551 | func ExtractCommandFromArgs(args []string) string { |
| 552 | for i := 0; i < len(args); i++ { |
| 553 | arg := args[i] |
| 554 | |
| 555 | // Check for -c or --command |
| 556 | if arg == "-c" || arg == "--command" { |
| 557 | // Next argument is the command value |
| 558 | if i+1 < len(args) { |
| 559 | return args[i+1] |
| 560 | } |
| 561 | return "" |
| 562 | } |
| 563 | |
| 564 | // Check for -c=value or --command=value format |
| 565 | if len(arg) > 3 && arg[:3] == "-c=" { |
| 566 | return arg[3:] |
| 567 | } |
| 568 | if len(arg) > 10 && arg[:10] == "--command=" { |
| 569 | return arg[10:] |
| 570 | } |
| 571 | } |
| 572 | return "" |
| 573 | } |
| 574 | |
| 575 | // FindDockerCmd checks if the cli is related to docker or not, it also returns if it is a docker compose file |
| 576 | func FindDockerCmd(cmd string) CmdType { |
no outgoing calls
no test coverage detected