config: unify configuration with multi-site support
- Remove mock_content setting (working database loop makes it unnecessary) - Change server.dev_mode to global dev_mode setting for consistency - Update CLI to use cli.site_id and cli.output for scoped configuration - Implement database client for CLI enhance command (complete static site loop) - Update justfile to use INSERTR_DATABASE_PATH environment variable - Enable multi-site architecture: server is site-agnostic, CLI is site-specific - Unified insertr.yaml now supports both server and CLI with minimal config
This commit is contained in:
@@ -9,6 +9,7 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"github.com/insertr/insertr/internal/content"
|
||||
"github.com/insertr/insertr/internal/db"
|
||||
)
|
||||
|
||||
var enhanceCmd = &cobra.Command{
|
||||
@@ -22,17 +23,14 @@ process that transforms static HTML into an editable CMS.`,
|
||||
}
|
||||
|
||||
var (
|
||||
outputDir string
|
||||
mockContent bool
|
||||
outputDir string
|
||||
)
|
||||
|
||||
func init() {
|
||||
enhanceCmd.Flags().StringVarP(&outputDir, "output", "o", "./dist", "Output directory for enhanced files")
|
||||
enhanceCmd.Flags().BoolVar(&mockContent, "mock", true, "Use mock content for development")
|
||||
|
||||
// Bind flags to viper
|
||||
viper.BindPFlag("build.output", enhanceCmd.Flags().Lookup("output"))
|
||||
viper.BindPFlag("mock_content", enhanceCmd.Flags().Lookup("mock"))
|
||||
viper.BindPFlag("cli.output", enhanceCmd.Flags().Lookup("output"))
|
||||
}
|
||||
|
||||
func runEnhance(cmd *cobra.Command, args []string) {
|
||||
@@ -47,21 +45,24 @@ func runEnhance(cmd *cobra.Command, args []string) {
|
||||
dbPath := viper.GetString("database.path")
|
||||
apiURL := viper.GetString("api.url")
|
||||
apiKey := viper.GetString("api.key")
|
||||
siteID := viper.GetString("site_id")
|
||||
mockContent := viper.GetBool("mock_content")
|
||||
siteID := viper.GetString("cli.site_id")
|
||||
outputDir := viper.GetString("cli.output")
|
||||
|
||||
// Create content client
|
||||
var client content.ContentClient
|
||||
if mockContent || (apiURL == "" && dbPath == "") {
|
||||
fmt.Printf("🧪 Using mock content for development\n")
|
||||
client = content.NewMockClient()
|
||||
} else if apiURL != "" {
|
||||
if apiURL != "" {
|
||||
fmt.Printf("🌐 Using content API: %s\n", apiURL)
|
||||
client = content.NewHTTPClient(apiURL, apiKey)
|
||||
} else {
|
||||
} else if dbPath != "" {
|
||||
fmt.Printf("🗄️ Using database: %s\n", dbPath)
|
||||
// TODO: Implement database client for direct DB access
|
||||
fmt.Printf("⚠️ Direct database access not yet implemented, using mock content\n")
|
||||
database, err := db.NewDatabase(dbPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize database: %v", err)
|
||||
}
|
||||
defer database.Close()
|
||||
client = content.NewDatabaseClient(database)
|
||||
} else {
|
||||
fmt.Printf("🧪 No database or API configured, using mock content\n")
|
||||
client = content.NewMockClient()
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ func init() {
|
||||
viper.BindPFlag("database.path", rootCmd.PersistentFlags().Lookup("db"))
|
||||
viper.BindPFlag("api.url", rootCmd.PersistentFlags().Lookup("api-url"))
|
||||
viper.BindPFlag("api.key", rootCmd.PersistentFlags().Lookup("api-key"))
|
||||
viper.BindPFlag("site_id", rootCmd.PersistentFlags().Lookup("site-id"))
|
||||
viper.BindPFlag("cli.site_id", rootCmd.PersistentFlags().Lookup("site-id"))
|
||||
|
||||
rootCmd.AddCommand(enhanceCmd)
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
|
||||
@@ -35,14 +35,14 @@ func init() {
|
||||
|
||||
// Bind flags to viper
|
||||
viper.BindPFlag("server.port", serveCmd.Flags().Lookup("port"))
|
||||
viper.BindPFlag("server.dev_mode", serveCmd.Flags().Lookup("dev-mode"))
|
||||
viper.BindPFlag("dev_mode", serveCmd.Flags().Lookup("dev-mode"))
|
||||
}
|
||||
|
||||
func runServe(cmd *cobra.Command, args []string) {
|
||||
// Get configuration values
|
||||
port := viper.GetInt("server.port")
|
||||
dbPath := viper.GetString("database.path")
|
||||
devMode := viper.GetBool("server.dev_mode")
|
||||
devMode := viper.GetBool("dev_mode")
|
||||
|
||||
// Initialize database
|
||||
database, err := db.NewDatabase(dbPath)
|
||||
|
||||
Reference in New Issue
Block a user