github.com/GoogleContainerTools/kpt@v1.0.0-beta.50.0.20240520170205-c25345ffcbee/pkg/printer/fake/fake.go (about) 1 // Copyright 2021 The kpt Authors 2 // 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package fake 16 17 import ( 18 "context" 19 "io" 20 21 "github.com/GoogleContainerTools/kpt/internal/pkg" 22 "github.com/GoogleContainerTools/kpt/pkg/printer" 23 ) 24 25 // Printer implements the printer.Printer interface and just ignores 26 // all print calls. 27 type Printer struct { 28 outStream io.Writer 29 errStream io.Writer 30 } 31 32 func (np *Printer) PrintPackage(*pkg.Pkg, bool) {} 33 34 func (np *Printer) OptPrintf(*printer.Options, string, ...interface{}) {} 35 36 func (np *Printer) Printf(string, ...interface{}) {} 37 38 func (np *Printer) OutStream() io.Writer { return np.outStream } 39 40 func (np *Printer) ErrStream() io.Writer { return np.errStream } 41 42 // CtxWithDefaultPrinter returns a new context with the printer which has os streams 43 func CtxWithDefaultPrinter() context.Context { 44 return CtxWithPrinter(io.Discard, io.Discard) 45 } 46 47 // CtxWithPrinter returns a new context with Printer added. 48 func CtxWithPrinter(outStream, errStream io.Writer) context.Context { 49 ctx := context.Background() 50 return printer.WithContext(ctx, printer.New(outStream, errStream)) 51 }