🏗️ **Major Architecture Refactoring: Separate CLI + Server → Unified Binary** **Key Changes:** ✅ **Unified Binary**: Single 'insertr' binary with subcommands (enhance, serve) ✅ **Preserved Database Architecture**: Maintained sophisticated sqlc multi-DB setup ✅ **Smart Configuration**: Viper + YAML config with CLI flag precedence ✅ **Updated Build System**: Unified justfile, Air, and npm scripts **Command Structure:** - `insertr enhance [input-dir]` - Build-time content injection - `insertr serve` - HTTP API server (dev + production modes) - `insertr --config insertr.yaml` - YAML configuration support **Architecture Benefits:** - **Shared Database Layer**: Single source of truth for content models - **Flexible Workflows**: Local DB for dev, remote API for production - **Simple Deployment**: One binary for all use cases - **Better UX**: Consistent configuration across build and runtime **Preserved Features:** - Multi-database support (SQLite + PostgreSQL) - sqlc code generation and type safety - Version control system with rollback - Professional API endpoints - Content enhancement pipeline **Development Workflow:** - `just dev` - Full-stack development (API server + demo site) - `just serve` - API server only - `just enhance` - Build-time content injection - `air` - Hot reload unified binary **Migration:** Consolidated insertr-cli/ and insertr-server/ → unified root structure
75 lines
2.0 KiB
Go
75 lines
2.0 KiB
Go
package cmd
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
var (
|
|
cfgFile string
|
|
dbPath string
|
|
apiURL string
|
|
apiKey string
|
|
siteID string
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "insertr",
|
|
Short: "Insertr - The Tailwind of CMS",
|
|
Long: `Insertr adds editing capabilities to static HTML sites by detecting
|
|
editable elements and injecting content management functionality.
|
|
|
|
The unified tool handles both build-time content injection (enhance command)
|
|
and runtime API server (serve command) for complete CMS functionality.`,
|
|
Version: "0.1.0",
|
|
}
|
|
|
|
func Execute() {
|
|
if err := rootCmd.Execute(); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func init() {
|
|
cobra.OnInitialize(initConfig)
|
|
|
|
// Global flags
|
|
rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is ./insertr.yaml)")
|
|
rootCmd.PersistentFlags().StringVar(&dbPath, "db", "./insertr.db", "database path (SQLite file or PostgreSQL connection string)")
|
|
rootCmd.PersistentFlags().StringVar(&apiURL, "api-url", "", "content API URL")
|
|
rootCmd.PersistentFlags().StringVar(&apiKey, "api-key", "", "API key for authentication")
|
|
rootCmd.PersistentFlags().StringVarP(&siteID, "site-id", "s", "demo", "site ID for content lookup")
|
|
|
|
// Bind flags to viper
|
|
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"))
|
|
|
|
rootCmd.AddCommand(enhanceCmd)
|
|
rootCmd.AddCommand(serveCmd)
|
|
}
|
|
|
|
func initConfig() {
|
|
if cfgFile != "" {
|
|
viper.SetConfigFile(cfgFile)
|
|
} else {
|
|
viper.AddConfigPath(".")
|
|
viper.SetConfigName("insertr")
|
|
viper.SetConfigType("yaml")
|
|
}
|
|
|
|
// Environment variables
|
|
viper.SetEnvPrefix("INSERTR")
|
|
viper.AutomaticEnv()
|
|
|
|
// Read config file
|
|
if err := viper.ReadInConfig(); err == nil {
|
|
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
|
|
}
|
|
}
|