mirror of
https://github.com/mark3labs/kit.git
synced 2026-06-14 03:30:26 +00:00
consolidate
This commit is contained in:
@@ -84,6 +84,12 @@ func initConfig() {
|
||||
// Use config file from the flag
|
||||
viper.SetConfigFile(configFile)
|
||||
} else {
|
||||
// Ensure a config file exists (create default if none found)
|
||||
if err := config.EnsureConfigExists(); err != nil {
|
||||
// If we can't create config, continue silently (non-fatal)
|
||||
fmt.Fprintf(os.Stderr, "Warning: Could not create default config file: %v\n", err)
|
||||
}
|
||||
|
||||
// Find home directory
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
|
||||
@@ -68,7 +68,6 @@ This will replace ${directory} with "/tmp" and ${name} with "John" in the script
|
||||
}
|
||||
|
||||
func init() {
|
||||
cobra.OnInitialize(initConfig)
|
||||
rootCmd.AddCommand(scriptCmd)
|
||||
|
||||
// Add the same flags as the root command, but they will override script settings
|
||||
|
||||
@@ -154,6 +154,31 @@ func LoadSystemPrompt(input string) (string, error) {
|
||||
return input, nil
|
||||
}
|
||||
|
||||
// EnsureConfigExists checks if a config file exists and creates a default one if not
|
||||
func EnsureConfigExists() error {
|
||||
homeDir, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error getting home directory: %v", err)
|
||||
}
|
||||
|
||||
// Check for existing config files (new format first, then legacy)
|
||||
configNames := []string{".mcphost", ".mcp"}
|
||||
configTypes := []string{"yaml", "json"}
|
||||
|
||||
for _, configName := range configNames {
|
||||
for _, configType := range configTypes {
|
||||
configPath := filepath.Join(homeDir, configName+"."+configType)
|
||||
if _, err := os.Stat(configPath); err == nil {
|
||||
// Config file exists, no need to create
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No config file found, create default
|
||||
return createDefaultConfig(homeDir)
|
||||
}
|
||||
|
||||
// createDefaultConfig creates a default .mcphost.yml file in the user's home directory
|
||||
func createDefaultConfig(homeDir string) error {
|
||||
configPath := filepath.Join(homeDir, ".mcphost.yml")
|
||||
|
||||
Reference in New Issue
Block a user