fix: Handle missing configuration file for help command

This commit is contained in:
Arik Jones (aider)
2024-09-16 09:52:48 -05:00
parent efee186ae0
commit 21d3e8ee68
2 changed files with 22 additions and 11 deletions

View File

@@ -53,6 +53,9 @@ whose name is <project-directory-name>-rollup-<timestamp>.md.`,
func Execute(config *config.Config) error { func Execute(config *config.Config) error {
cfg = config cfg = config
if cfg == nil {
cfg = &config.Config{} // Use an empty config if none is provided
}
return rootCmd.Execute() return rootCmd.Execute()
} }

30
main.go
View File

@@ -13,21 +13,29 @@ import (
var cfg *config.Config var cfg *config.Config
func main() { 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 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) if !isHelpCommand {
scraper.SetupLogger(false) 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() // Initialize the scraper logger with default verbosity (false)
if err != nil { scraper.SetupLogger(false)
log.Fatalf("Failed to initialize Playwright: %v", err)
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 { if err := cmd.Execute(cfg); err != nil {
fmt.Println(err) fmt.Println(err)