Skip to content

Commit

Permalink
feat: allow specifying cache folder
Browse files Browse the repository at this point in the history
  • Loading branch information
marcotuna committed Jul 24, 2023
1 parent 841c3ca commit ffee0de
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/wp-go-static/commands/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ var RootCmd = &cobra.Command{
func init() {
// Define command-line flags
RootCmd.PersistentFlags().String("dir", "dump", "directory to save downloaded files")
RootCmd.PersistentFlags().String("url", "https://wp-just-expertise.mstudio.work", "URL to scrape")
RootCmd.PersistentFlags().String("url", "", "URL to scrape")
RootCmd.PersistentFlags().String("cache", "", "Cache directory")

// Bind command-line flags to Viper
viper.BindPFlag("dir", RootCmd.PersistentFlags().Lookup("dir"))
viper.BindPFlag("url", RootCmd.PersistentFlags().Lookup("url"))
viper.BindPFlag("cache", RootCmd.PersistentFlags().Lookup("cache"))

// Execute root command
if err := RootCmd.Execute(); err != nil {
Expand All @@ -46,10 +48,13 @@ func init() {
func rootCmdF(command *cobra.Command, args []string) error {
commandDir, _ := command.Flags().GetString("dir")
commandURL, _ := command.Flags().GetString("url")
cacheDir, _ := command.Flags().GetString("cache")

c := colly.NewCollector(
colly.CacheDir(".cache"),
)
c := colly.NewCollector()

if cacheDir != "" {
c.CacheDir = cacheDir
}

// Ignore SSL errors
c.WithTransport(&http.Transport{
Expand Down

0 comments on commit ffee0de

Please sign in to comment.