mirror of
https://github.com/docker/compose.git
synced 2026-11-18 14:13:49 +00:00
The fenced Go blocks in docs/sdk.md become real code under docs/examples/sdk, built by the ordinary module build: API drift now breaks compilation. A unit test pins the markdown to the compiled files byte-for-byte (first block = main.go from its package clause down, second block = customService's body), so wording drift breaks the test instead of silently rotting the docs. Epic #14074, section G. Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
44 lines
1.5 KiB
Go
44 lines
1.5 KiB
Go
/*
|
|
Copyright 2020 Docker Compose CLI authors
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
|
|
"github.com/docker/cli/cli/command"
|
|
|
|
"github.com/docker/compose/v5/pkg/api"
|
|
"github.com/docker/compose/v5/pkg/compose"
|
|
)
|
|
|
|
// customService demonstrates the options accepted by NewComposeService: the
|
|
// second fenced Go block of docs/sdk.md is this function's body, verbatim
|
|
// (pinned by sdk_md_test.go).
|
|
func customService(dockerCLI command.Cli) (api.Compose, error) {
|
|
// Create a custom output buffer to capture logs
|
|
var outputBuffer bytes.Buffer
|
|
|
|
// Create a compose service with custom options
|
|
service, err := compose.NewComposeService(dockerCLI,
|
|
compose.WithOutputStream(&outputBuffer), // Redirect output to custom writer
|
|
compose.WithErrorStream(os.Stderr), // Use stderr for errors
|
|
compose.WithMaxConcurrency(4), // Limit concurrent operations
|
|
compose.WithPrompt(compose.AlwaysOkPrompt()), // Auto-confirm all prompts
|
|
)
|
|
return service, err
|
|
}
|