mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-04 18:01:17 +08:00
Fix taskfile in templates. Sanitize the project name
This commit is contained in:
parent
eefeadc018
commit
ae38d1e020
@ -3,6 +3,7 @@ package commands
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
"github.com/wailsapp/wails/v3/internal/flags"
|
"github.com/wailsapp/wails/v3/internal/flags"
|
||||||
"github.com/wailsapp/wails/v3/internal/templates"
|
"github.com/wailsapp/wails/v3/internal/templates"
|
||||||
@ -23,6 +24,8 @@ func Init(options *flags.Init) error {
|
|||||||
return fmt.Errorf("please use the -n flag to specify a project name")
|
return fmt.Errorf("please use the -n flag to specify a project name")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
options.ProjectName = sanitizeFileName(options.ProjectName)
|
||||||
|
|
||||||
if !templates.ValidTemplateName(options.TemplateName) {
|
if !templates.ValidTemplateName(options.TemplateName) {
|
||||||
return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", options.TemplateName)
|
return fmt.Errorf("invalid template name: %s. Use -l flag to list valid templates", options.TemplateName)
|
||||||
}
|
}
|
||||||
@ -54,3 +57,12 @@ func printTemplates() error {
|
|||||||
pterm.Println()
|
pterm.Println()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func sanitizeFileName(fileName string) string {
|
||||||
|
// Regular expression to match non-allowed characters in file names
|
||||||
|
// You can adjust this based on the specific requirements of your file system
|
||||||
|
reg := regexp.MustCompile(`[^a-zA-Z0-9_.-]`)
|
||||||
|
|
||||||
|
// Replace matched characters with an underscore or any other safe character
|
||||||
|
return reg.ReplaceAllString(fileName, "_")
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user