♻️ Export Config

This commit is contained in:
Dan Jones 2025-03-10 14:52:50 -05:00
commit 7bd5503613
6 changed files with 56 additions and 38 deletions

View file

@ -2,56 +2,41 @@ package nomino
import "strings"
type config struct {
original string
prefix string
suffix string
extension string
generator Generator
}
func defaultConf() config {
return config{
extension: ".txt",
generator: uuidGen,
}
}
// Option is an option for nomino
type Option func(c *config)
// Option sets configuration parameters for Config.
type Option func(c *Config)
// WithOriginal sets the original filename.
// This will be included in the generated name after the generated string and before the suffix.
func WithOriginal(o string) Option {
return func(c *config) {
return func(c *Config) {
c.original = "_" + o
}
}
// WithPrefix sets a prefix for the generated name.
func WithPrefix(p string) Option {
return func(c *config) {
return func(c *Config) {
c.prefix = p + "_"
}
}
// WithSuffix sets a suffix for the generated name. It will be included in the base name before the suffix.
func WithSuffix(s string) Option {
return func(c *config) {
return func(c *Config) {
c.suffix = "_" + s
}
}
// WithoutExtension sets no extension for the generated filename. By default, it will be txt
func WithoutExtension() Option {
return func(c *config) {
return func(c *Config) {
c.extension = ""
}
}
// WithExtension sets the extension for the generated filename.
func WithExtension(ext string) Option {
return func(c *config) {
return func(c *Config) {
c.extension = "." + strings.TrimPrefix(ext, ".")
}
}