Files
bap-room-packager/util.go
T
2026-04-16 00:13:24 -05:00

38 lines
657 B
Go

package main
import (
"errors"
"fmt"
"io/fs"
"os"
"path"
"strings"
"github.com/charmbracelet/lipgloss"
)
func Exists(p ...string) (bool, error) {
_, err := os.Stat(path.Join(p...))
if err == nil {
return true, nil
}
if errors.Is(err, fs.ErrNotExist) {
return false, nil
}
return false, err
}
func SplitExt(filename string) (string, string) {
ext := strings.ToUpper(path.Ext(filename))
name := strings.ToUpper(filename[:len(filename)-len(ext)])
if len(ext) > 0 {
ext = ext[1:]
}
return name, ext
}
func Renderf(style lipgloss.Style, format string, v ...any) string {
str := fmt.Sprintf(format, v...)
return style.Render(str)
}