Files
coder/coderd/util/strings/strings.go
Cian Johnston 1e349f0d50 feat(cli): allow specifying name of provisioner daemon (#11077)
- Adds a --name argument to provisionerd start
- Plumbs through name to integrated and external provisioners
- Defaults to hostname if not specified for external, hostname-N for integrated
- Adds cliutil.Hostname
2023-12-07 16:59:13 +00:00

31 lines
511 B
Go

package strings
import (
"fmt"
"strings"
)
// JoinWithConjunction joins a slice of strings with commas except for the last
// two which are joined with "and".
func JoinWithConjunction(s []string) string {
last := len(s) - 1
if last == 0 {
return s[last]
}
return fmt.Sprintf("%s and %s",
strings.Join(s[:last], ", "),
s[last],
)
}
// Truncate returns the first n characters of s.
func Truncate(s string, n int) string {
if n < 1 {
return ""
}
if len(s) <= n {
return s
}
return s[:n]
}