github.com/paketoio/libpak@v1.3.1/bard/formatter.go (about) 1 /* 2 * Copyright 2018-2020 the original author or authors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * https://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package bard 18 19 import ( 20 "fmt" 21 "strings" 22 23 "github.com/heroku/color" 24 ) 25 26 // Identity is the formatter for an identifiable object. 27 type IdentityFormatter struct { 28 29 // Name is the name of the identified object. 30 Name string 31 32 // Description is the description of the identified object. 33 Description string 34 } 35 36 func (i IdentityFormatter) String() string { 37 var sb strings.Builder 38 39 _, _ = sb.WriteString(color.New(color.Bold).Sprint(i.Name)) 40 41 if i.Description != "" { 42 _, _ = sb.WriteString(fmt.Sprintf(" %s", i.Description)) 43 } 44 45 return sb.String() 46 } 47 48 var launchConfigDefault = color.New(color.Italic).SprintFunc() 49 50 // LaunchConfigFormatter is the logging formatter for a user configuration and its default value. 51 type LaunchConfigFormatter struct { 52 53 // Name is the name of the launch configuration environment variable. 54 Name string 55 56 // Default is the default value of the the configuration. 57 Default string 58 } 59 60 func (l LaunchConfigFormatter) String() string { 61 return fmt.Sprintf("Set $%s to configure. Default %s.", l.Name, launchConfigDefault(l.Default)) 62 }