mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-13 06:23:18 +00:00
fix: Handle missing configuration file for help command
This commit is contained in:
@@ -53,6 +53,9 @@ whose name is <project-directory-name>-rollup-<timestamp>.md.`,
|
||||
|
||||
func Execute(config *config.Config) error {
|
||||
cfg = config
|
||||
if cfg == nil {
|
||||
cfg = &config.Config{} // Use an empty config if none is provided
|
||||
}
|
||||
return rootCmd.Execute()
|
||||
}
|
||||
|
||||
|
||||
30
main.go
30
main.go
@@ -13,21 +13,29 @@ import (
|
||||
var cfg *config.Config
|
||||
|
||||
func main() {
|
||||
configPath := config.DefaultConfigPath()
|
||||
// Check if the command is "help"
|
||||
isHelpCommand := len(os.Args) > 1 && (os.Args[1] == "help" || os.Args[1] == "--help" || os.Args[1] == "-h")
|
||||
|
||||
var cfg *config.Config
|
||||
var err error
|
||||
cfg, err = config.Load(configPath)
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to load configuration: %v", err)
|
||||
}
|
||||
|
||||
// Initialize the scraper logger with default verbosity (false)
|
||||
scraper.SetupLogger(false)
|
||||
if !isHelpCommand {
|
||||
configPath := config.DefaultConfigPath()
|
||||
cfg, err = config.Load(configPath)
|
||||
if err != nil {
|
||||
log.Printf("Warning: Failed to load configuration: %v", err)
|
||||
// Continue execution without a config file
|
||||
}
|
||||
|
||||
err = scraper.InitPlaywright()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize Playwright: %v", err)
|
||||
// Initialize the scraper logger with default verbosity (false)
|
||||
scraper.SetupLogger(false)
|
||||
|
||||
err = scraper.InitPlaywright()
|
||||
if err != nil {
|
||||
log.Fatalf("Failed to initialize Playwright: %v", err)
|
||||
}
|
||||
defer scraper.ClosePlaywright()
|
||||
}
|
||||
defer scraper.ClosePlaywright()
|
||||
|
||||
if err := cmd.Execute(cfg); err != nil {
|
||||
fmt.Println(err)
|
||||
|
||||
Reference in New Issue
Block a user