1 // Copyright 2023 The Sigstore 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 package ui 15 16 import ( 17 "context" 18 "fmt" 19 ) 20 21 func (w *Env) infof(msg string, a ...any) { 22 msg = fmt.Sprintf(msg, a...) 23 fmt.Fprintln(w.Stderr, msg) 24 } 25 26 // Infof logs an informational message. It works like fmt.Printf, except that it 27 // always has a trailing newline. 28 func Infof(ctx context.Context, msg string, a ...any) { 29 getEnv(ctx).infof(msg, a...) 30 } 31 32 func (w *Env) warnf(msg string, a ...any) { 33 msg = fmt.Sprintf(msg, a...) 34 fmt.Fprintf(w.Stderr, "WARNING: %s\n", msg) 35 } 36 37 // Warnf logs a warning message (prefixed by "WARNING:"). It works like 38 // fmt.Printf, except that it always has a trailing newline. 39 func Warnf(ctx context.Context, msg string, a ...any) { 40 getEnv(ctx).warnf(msg, a...) 41 } 42