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()
} }

12
main.go
View File

@@ -13,11 +13,18 @@ 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
if !isHelpCommand {
configPath := config.DefaultConfigPath()
cfg, err = config.Load(configPath) cfg, err = config.Load(configPath)
if err != nil { if err != nil {
log.Fatalf("Failed to load configuration: %v", err) log.Printf("Warning: Failed to load configuration: %v", err)
// Continue execution without a config file
} }
// Initialize the scraper logger with default verbosity (false) // Initialize the scraper logger with default verbosity (false)
@@ -28,6 +35,7 @@ func main() {
log.Fatalf("Failed to initialize Playwright: %v", err) 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)