(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)
| 37 | } |
| 38 | |
| 39 | func portCommand(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions) *cobra.Command { |
| 40 | opts := portOptions{ |
| 41 | ProjectOptions: p, |
| 42 | } |
| 43 | cmd := &cobra.Command{ |
| 44 | Use: "port [OPTIONS] SERVICE PRIVATE_PORT", |
| 45 | Short: "Print the public port for a port binding", |
| 46 | Args: cobra.MinimumNArgs(2), |
| 47 | PreRunE: Adapt(func(ctx context.Context, args []string) error { |
| 48 | port, err := strconv.ParseUint(args[1], 10, 16) |
| 49 | if err != nil { |
| 50 | return err |
| 51 | } |
| 52 | opts.port = uint16(port) |
| 53 | opts.protocol = strings.ToLower(opts.protocol) |
| 54 | return nil |
| 55 | }), |
| 56 | RunE: Adapt(func(ctx context.Context, args []string) error { |
| 57 | return runPort(ctx, dockerCli, backendOptions, opts, args[0]) |
| 58 | }), |
| 59 | ValidArgsFunction: completeServiceNames(dockerCli, p), |
| 60 | } |
| 61 | cmd.Flags().StringVar(&opts.protocol, "protocol", "tcp", "tcp or udp") |
| 62 | cmd.Flags().IntVar(&opts.index, "index", 0, "Index of the container if service has multiple replicas") |
| 63 | return cmd |
| 64 | } |
| 65 | |
| 66 | func runPort(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts portOptions, service string) error { |
| 67 | projectName, err := opts.toProjectName(ctx, dockerCli) |
no test coverage detected