mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-13 06:23:18 +00:00
- Wire up --config/-f flag to actually load custom config files - Move config loading to PersistentPreRunE in root.go - Simplify main.go to just call cmd.Execute() - Move Playwright init to web command's PreRunE/PostRunE - Remove unused functions from cmd/web.go (~90 lines of dead code) - Remove writeSingleFile, writeMultipleFiles, generateDefaultFilename - Remove scrapeURL, extractAndConvertContent, testExtractAndConvertContent - Remove unused mock function from web_test.go - Add OutputType validation to Config.Validate() - Only allow "single", "separate", or empty string - Add test cases for valid and invalid output types
56 lines
1.3 KiB
Go
56 lines
1.3 KiB
Go
package cmd
|
|
|
|
import (
|
|
"log"
|
|
|
|
"github.com/spf13/cobra"
|
|
"github.com/tnypxl/rollup/internal/config"
|
|
)
|
|
|
|
var (
|
|
configFile string
|
|
verbose bool
|
|
)
|
|
|
|
var rootCmd = &cobra.Command{
|
|
Use: "rollup",
|
|
Short: "Rollup is a tool for combining and processing files",
|
|
Long: `Rollup is a versatile tool that can combine and process files in various ways.
|
|
Use subcommands to perform specific operations.`,
|
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
|
// Skip config loading for generate and help commands
|
|
if cmd.Name() == "generate" || cmd.Name() == "help" {
|
|
return nil
|
|
}
|
|
|
|
// Determine config path
|
|
configPath := configFile
|
|
if configPath == "" {
|
|
configPath = "rollup.yml"
|
|
}
|
|
|
|
// Load configuration
|
|
var err error
|
|
cfg, err = config.Load(configPath)
|
|
if err != nil {
|
|
log.Printf("Warning: Failed to load configuration from %s: %v", configPath, err)
|
|
cfg = &config.Config{} // Use empty config if loading fails
|
|
}
|
|
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func Execute() error {
|
|
return rootCmd.Execute()
|
|
}
|
|
|
|
func init() {
|
|
rootCmd.PersistentFlags().StringVarP(&configFile, "config", "f", "", "Path to the config file (default: rollup.yml in the current directory)")
|
|
rootCmd.PersistentFlags().BoolVarP(&verbose, "verbose", "v", false, "Enable verbose logging")
|
|
|
|
rootCmd.AddCommand(filesCmd)
|
|
rootCmd.AddCommand(webCmd)
|
|
rootCmd.AddCommand(generateCmd)
|
|
}
|