Repository: docker/compose
File: cmd/compose/publish.go (Go)

Code before:

type publishOptions struct {
	*ProjectOptions
	resolveImageDigests bool
	ociVersion          string
	withEnvironment     bool
	force               bool
}

func publishCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
	opts := publishOptions{
		ProjectOptions: p,
	}
	cmd := &cobra.Command{
		Use:   "publish [OPTIONS] REPOSITORY[:TAG]",
		Short: "Publish compose application",
		RunE: Adapt(func(ctx context.Context, args []string) error {
			return runPublish(ctx, dockerCli, backend, opts, args[0])
		}),
		Args: cobra.ExactArgs(1),
	}
	flags := cmd.Flags()
	flags.BoolVar(&opts.resolveImageDigests, "resolve-image-digests", false, "Pin image tags to digests")
	flags.StringVar(&opts.ociVersion, "oci-version", "", "OCI image/artifact specification version (automatically determined by default)")
	flags.BoolVar(&opts.withEnvironment, "with-env", false, "Include environment variables in the published OCI artifact")
	flags.BoolVarP(&opts.force, "force", "f", false, "Force publish without asking for confirmation")

	return cmd
}

func runPublish(ctx context.Context, dockerCli command.Cli, backend api.Service, opts publishOptions, repository string) error {
	project, _, err := opts.ToProject(ctx, dockerCli, nil)
	if err != nil {
		return err
	}

	return backend.Publish(ctx, project, repository, api.PublishOptions{
		ResolveImageDigests: opts.resolveImageDigests,
		OCIVersion:          api.OCIVersion(opts.ociVersion),
		WithEnvironment:     opts.withEnvironment,
		Force:               opts.force,
	})
}


Review comment (suggestion):
I'd suggest to use `-y` to align with https://github.com/docker/compose/blob/main/cmd/compose/create.go#L84

Code after:

type publishOptions struct {
	*ProjectOptions
	resolveImageDigests bool
	ociVersion          string
	withEnvironment     bool
	assumeYes           bool
}

func publishCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service) *cobra.Command {
	opts := publishOptions{
		ProjectOptions: p,
	}
	cmd := &cobra.Command{
		Use:   "publish [OPTIONS] REPOSITORY[:TAG]",
		Short: "Publish compose application",
		RunE: Adapt(func(ctx context.Context, args []string) error {
			return runPublish(ctx, dockerCli, backend, opts, args[0])
		}),
		Args: cobra.ExactArgs(1),
	}
	flags := cmd.Flags()
	flags.BoolVar(&opts.resolveImageDigests, "resolve-image-digests", false, "Pin image tags to digests")
	flags.StringVar(&opts.ociVersion, "oci-version", "", "OCI image/artifact specification version (automatically determined by default)")
	flags.BoolVar(&opts.withEnvironment, "with-env", false, "Include environment variables in the published OCI artifact")
	flags.BoolVarP(&opts.assumeYes, "y", "y", false, `Assume "yes" as answer to all prompts`)

	return cmd
}

func runPublish(ctx context.Context, dockerCli command.Cli, backend api.Service, opts publishOptions, repository string) error {
	project, _, err := opts.ToProject(ctx, dockerCli, nil)
	if err != nil {
		return err
	}

	return backend.Publish(ctx, project, repository, api.PublishOptions{
		ResolveImageDigests: opts.resolveImageDigests,
		OCIVersion:          api.OCIVersion(opts.ociVersion),
		WithEnvironment:     opts.withEnvironment,
		AssumeYes:           opts.assumeYes,
	})
}