plain.go 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2020 Docker Compose CLI authors
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package progress
  14. import (
  15. "context"
  16. "fmt"
  17. "io"
  18. "github.com/docker/compose/v2/pkg/api"
  19. )
  20. func NewPlainWriter(out io.Writer) EventProcessor {
  21. return &plainWriter{
  22. out: out,
  23. }
  24. }
  25. type plainWriter struct {
  26. out io.Writer
  27. dryRun bool
  28. }
  29. func (p *plainWriter) Start(ctx context.Context, operation string) {
  30. }
  31. func (p *plainWriter) Event(e Event) {
  32. prefix := ""
  33. if p.dryRun {
  34. prefix = api.DRYRUN_PREFIX
  35. }
  36. _, _ = fmt.Fprintln(p.out, prefix, e.ID, e.Text, e.StatusText)
  37. }
  38. func (p *plainWriter) On(events ...Event) {
  39. for _, e := range events {
  40. p.Event(e)
  41. }
  42. }
  43. func (p *plainWriter) Done(_ string, _ bool) {
  44. }