RootCommand returns the compose command with its child commands
(dockerCli command.Cli, backendOptions *BackendOptions)
| 426 | |
| 427 | // RootCommand returns the compose command with its child commands |
| 428 | func RootCommand(dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { //nolint:gocyclo |
| 429 | opts := ProjectOptions{} |
| 430 | var ( |
| 431 | ansi string |
| 432 | noAnsi bool |
| 433 | verbose bool |
| 434 | version bool |
| 435 | parallel int |
| 436 | dryRun bool |
| 437 | ) |
| 438 | c := &cobra.Command{ |
| 439 | Short: "Docker Compose", |
| 440 | Long: "Define and run multi-container applications with Docker", |
| 441 | Use: PluginName, |
| 442 | TraverseChildren: true, |
| 443 | // By default (no Run/RunE in parent c) for typos in subcommands, cobra displays the help of parent c but exit(0) ! |
| 444 | RunE: func(cmd *cobra.Command, args []string) error { |
| 445 | if len(args) == 0 { |
| 446 | return cmd.Help() |
| 447 | } |
| 448 | if version { |
| 449 | return versionCommand(dockerCli).Execute() |
| 450 | } |
| 451 | _ = cmd.Help() |
| 452 | return dockercli.StatusError{ |
| 453 | StatusCode: 1, |
| 454 | Status: fmt.Sprintf("unknown docker command: %q", "compose "+args[0]), |
| 455 | } |
| 456 | }, |
| 457 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 458 | parent := cmd.Root() |
| 459 | if parent != nil { |
| 460 | parentPrerun := parent.PersistentPreRunE |
| 461 | if parentPrerun != nil { |
| 462 | err := parentPrerun(cmd, args) |
| 463 | if err != nil { |
| 464 | return err |
| 465 | } |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | if verbose { |
| 470 | logrus.SetLevel(logrus.TraceLevel) |
| 471 | } |
| 472 | |
| 473 | err := setEnvWithDotEnv(opts, dockerCli) |
| 474 | if err != nil { |
| 475 | return err |
| 476 | } |
| 477 | if noAnsi { |
| 478 | if ansi != "auto" { |
| 479 | return errors.New(`cannot specify DEPRECATED "--no-ansi" and "--ansi". Please use only "--ansi"`) |
| 480 | } |
| 481 | ansi = "never" |
| 482 | fmt.Fprint(os.Stderr, "option '--no-ansi' is DEPRECATED ! Please use '--ansi' instead.\n") |
| 483 | } |
| 484 | if v, ok := os.LookupEnv("COMPOSE_ANSI"); ok && !cmd.Flags().Changed("ansi") { |
| 485 | ansi = v |
no test coverage detected