From a6ebf0062a85dc69a17fcc958618dcb25dd831eb Mon Sep 17 00:00:00 2001 From: "Arik Jones (aider)" Date: Sat, 14 Sep 2024 20:41:23 -0500 Subject: [PATCH] fix: Add --verbose flag to web subcommand --- cmd/root.go | 6 ++---- cmd/web.go | 5 +++++ main.go | 8 +------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index abfa390..14db5b7 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -28,7 +28,7 @@ var rootCmd = &cobra.Command{ Long: `Rollup is a tool that writes the contents of all files (with target custom file types provided) in a given project, current path or a custom path, to a single timestamped markdown file whose name is -rollup-.md.`, - RunE: func(cmd *cobra.Command, args []string) error { + PersistentPreRunE: func(cmd *cobra.Command, args []string) error { if configFile == "" { defaultConfig := config.DefaultConfigPath() if config.FileExists(defaultConfig) { @@ -47,10 +47,8 @@ whose name is -rollup-.md.`, }, } -func Execute(config *config.Config, scraperConfig scraper.Config) error { +func Execute(config *config.Config) error { cfg = config - scraper.SetupLogger(verbose) - scraperConfig.Verbose = verbose return rootCmd.Execute() } diff --git a/cmd/web.go b/cmd/web.go index 323585c..4cb70f7 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -31,6 +31,8 @@ var webCmd = &cobra.Command{ RunE: runWeb, } +var scraperConfig scraper.Config + func init() { rootCmd.AddCommand(webCmd) webCmd.Flags().StringSliceVarP(&urls, "urls", "u", []string{}, "URLs of the webpages to scrape (comma-separated)") @@ -40,6 +42,9 @@ func init() { webCmd.Flags().StringSliceVar(&excludeSelectors, "exclude", []string{}, "CSS selectors to exclude from the extracted content (comma-separated)") } +func runWeb(cmd *cobra.Command, args []string) error { + scraperConfig.Verbose = verbose + func runWeb(cmd *cobra.Command, args []string) error { // Use config if available, otherwise use command-line flags var urlConfigs []scraper.URLConfig diff --git a/main.go b/main.go index 7c7b07c..cdd9cce 100644 --- a/main.go +++ b/main.go @@ -29,13 +29,7 @@ func main() { } defer scraper.ClosePlaywright() - scraperConfig := scraper.Config{ - URLs: []scraper.URLConfig{{URL: cfg.Scrape.URLs[0].URL}}, - OutputType: cfg.Scrape.OutputType, - Verbose: false, // Set default verbosity - } - - if err := cmd.Execute(cfg, scraperConfig); err != nil { + if err := cmd.Execute(cfg); err != nil { fmt.Println(err) os.Exit(1) }