github.com/TrueBlocks/trueblocks-core/src/apps/chifra@v0.0.0-20241022031540-b362680128f7/pkg/usage/usage.go (about)

     1  package usage
     2  
     3  import (
     4  	"errors"
     5  	"strconv"
     6  	"strings"
     7  )
     8  
     9  // Replace accepts a string and an arbitrary number of additional string parameters. It replaces
    10  // {N} in the string with the Nth additional string.
    11  func Replace(msg string, values ...string) string {
    12  	ret := msg
    13  	for index, val := range values {
    14  		rep := "{" + strconv.FormatInt(int64(index), 10) + "}"
    15  		ret = strings.Replace(ret, rep, val, -1)
    16  	}
    17  	return ret
    18  }
    19  
    20  // Usage returns an error version of the Replace string
    21  func Usage(msg string, values ...string) error {
    22  	return errors.New(Replace(msg, values...))
    23  }