MCPcopy
hub / github.com/docker/compose / portCommand

Function portCommand

cmd/compose/port.go:39–64  ·  view source on GitHub ↗
(p *ProjectOptions, dockerCli command.Cli, backendOptions *BackendOptions)

Source from the content-addressed store, hash-verified

37}
38
39func 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
66func runPort(ctx context.Context, dockerCli command.Cli, backendOptions *BackendOptions, opts portOptions, service string) error {
67 projectName, err := opts.toProjectName(ctx, dockerCli)

Callers 1

RootCommandFunction · 0.85

Calls 3

AdaptFunction · 0.85
runPortFunction · 0.85
completeServiceNamesFunction · 0.85

Tested by

no test coverage detected