mirror of
https://github.com/tnypxl/rollup.git
synced 2025-12-15 15:03:17 +00:00
fix: Add --verbose flag to web subcommand
This commit is contained in:
@@ -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)
|
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
|
in a given project, current path or a custom path, to a single timestamped markdown file
|
||||||
whose name is <project-directory-name>-rollup-<timestamp>.md.`,
|
whose name is <project-directory-name>-rollup-<timestamp>.md.`,
|
||||||
RunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if configFile == "" {
|
if configFile == "" {
|
||||||
defaultConfig := config.DefaultConfigPath()
|
defaultConfig := config.DefaultConfigPath()
|
||||||
if config.FileExists(defaultConfig) {
|
if config.FileExists(defaultConfig) {
|
||||||
@@ -47,10 +47,8 @@ whose name is <project-directory-name>-rollup-<timestamp>.md.`,
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
func Execute(config *config.Config, scraperConfig scraper.Config) error {
|
func Execute(config *config.Config) error {
|
||||||
cfg = config
|
cfg = config
|
||||||
scraper.SetupLogger(verbose)
|
|
||||||
scraperConfig.Verbose = verbose
|
|
||||||
return rootCmd.Execute()
|
return rootCmd.Execute()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ var webCmd = &cobra.Command{
|
|||||||
RunE: runWeb,
|
RunE: runWeb,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var scraperConfig scraper.Config
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
rootCmd.AddCommand(webCmd)
|
rootCmd.AddCommand(webCmd)
|
||||||
webCmd.Flags().StringSliceVarP(&urls, "urls", "u", []string{}, "URLs of the webpages to scrape (comma-separated)")
|
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)")
|
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 {
|
func runWeb(cmd *cobra.Command, args []string) error {
|
||||||
// Use config if available, otherwise use command-line flags
|
// Use config if available, otherwise use command-line flags
|
||||||
var urlConfigs []scraper.URLConfig
|
var urlConfigs []scraper.URLConfig
|
||||||
|
|||||||
8
main.go
8
main.go
@@ -29,13 +29,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
defer scraper.ClosePlaywright()
|
defer scraper.ClosePlaywright()
|
||||||
|
|
||||||
scraperConfig := scraper.Config{
|
if err := cmd.Execute(cfg); err != nil {
|
||||||
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 {
|
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user