| 33 | } |
| 34 | |
| 35 | func versionCommand(dockerCli command.Cli) *cobra.Command { |
| 36 | opts := versionOptions{} |
| 37 | cmd := &cobra.Command{ |
| 38 | Use: "version [OPTIONS]", |
| 39 | Short: "Show the Docker Compose version information", |
| 40 | Args: cobra.NoArgs, |
| 41 | RunE: func(cmd *cobra.Command, _ []string) error { |
| 42 | runVersion(opts, dockerCli) |
| 43 | return nil |
| 44 | }, |
| 45 | PersistentPreRunE: func(cmd *cobra.Command, args []string) error { |
| 46 | // overwrite parent PersistentPreRunE to avoid trying to load |
| 47 | // compose file on version command if COMPOSE_FILE is set |
| 48 | return nil |
| 49 | }, |
| 50 | } |
| 51 | // define flags for backward compatibility with com.docker.cli |
| 52 | flags := cmd.Flags() |
| 53 | flags.StringVarP(&opts.format, "format", "f", "", "Format the output. Values: [pretty | json]. (Default: pretty)") |
| 54 | flags.BoolVar(&opts.short, "short", false, "Shows only Compose's version number") |
| 55 | |
| 56 | return cmd |
| 57 | } |
| 58 | |
| 59 | func runVersion(opts versionOptions, dockerCli command.Cli) { |
| 60 | if opts.short { |