mirror of
https://github.com/danielmiessler/Fabric.git
synced 2026-02-01 01:25:25 -05:00
- Add GitHub and Buy Me a Coffee funding configuration. - Localize setup prompts and error messages across multiple languages. - Implement helper for localized questions with static environment keys. - Update environment variable builder to handle hyphenated plugin names. - Replace hardcoded console output with localized i18n translation strings. - Expand locale files with comprehensive pattern and strategy translations. - Add new i18n keys for optional and required markers - Remove hardcoded `[required]` markers from description strings - Add custom patterns, Jina AI, YouTube, and language labels - Switch plugin descriptions to use i18n translation keys - Append markers dynamically to setup descriptions in Go code - Remove trailing newlines from plugin question prompt strings - Standardize all locale files with consistent formatting changes
68 lines
2.0 KiB
Go
68 lines
2.0 KiB
Go
package custom_patterns
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/danielmiessler/fabric/internal/i18n"
|
|
"github.com/danielmiessler/fabric/internal/plugins"
|
|
)
|
|
|
|
func NewCustomPatterns() (ret *CustomPatterns) {
|
|
label := "Custom Patterns"
|
|
ret = &CustomPatterns{}
|
|
|
|
ret.PluginBase = &plugins.PluginBase{
|
|
Name: i18n.T("custom_patterns_label"),
|
|
SetupDescription: i18n.T("custom_patterns_setup_description") + " " + i18n.T("optional_marker"),
|
|
EnvNamePrefix: plugins.BuildEnvVariablePrefix(label),
|
|
ConfigureCustom: ret.configure,
|
|
}
|
|
|
|
ret.CustomPatternsDir = ret.AddSetupQuestionWithEnvName("Directory", false,
|
|
i18n.T("custom_patterns_directory_question"))
|
|
|
|
return
|
|
}
|
|
|
|
type CustomPatterns struct {
|
|
*plugins.PluginBase
|
|
CustomPatternsDir *plugins.SetupQuestion
|
|
}
|
|
|
|
func (o *CustomPatterns) configure() error {
|
|
if o.CustomPatternsDir.Value != "" {
|
|
// Expand home directory if needed
|
|
if strings.HasPrefix(o.CustomPatternsDir.Value, "~/") {
|
|
if homeDir, err := os.UserHomeDir(); err == nil {
|
|
o.CustomPatternsDir.Value = filepath.Join(homeDir, o.CustomPatternsDir.Value[2:])
|
|
}
|
|
}
|
|
|
|
// Convert to absolute path
|
|
if absPath, err := filepath.Abs(o.CustomPatternsDir.Value); err == nil {
|
|
o.CustomPatternsDir.Value = absPath
|
|
}
|
|
|
|
// Check if directory exists, create only if it doesn't
|
|
if _, err := os.Stat(o.CustomPatternsDir.Value); os.IsNotExist(err) {
|
|
if err := os.MkdirAll(o.CustomPatternsDir.Value, 0755); err != nil {
|
|
// Log the error but don't clear the value - let it persist in env file
|
|
fmt.Printf("Warning: Could not create custom patterns directory %s: %v\n", o.CustomPatternsDir.Value, err)
|
|
}
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
// IsConfigured returns true if a custom patterns directory has been set
|
|
func (o *CustomPatterns) IsConfigured() bool {
|
|
// First configure to load values from environment variables
|
|
o.Configure()
|
|
// Check if the plugin has been configured with a directory
|
|
return o.CustomPatternsDir.Value != ""
|
|
}
|