1
0
mirror of https://github.com/danog/gojekyll.git synced 2024-11-30 07:48:58 +01:00

Separate build DryRun from Verbose

This commit is contained in:
Oliver Steele 2017-06-18 16:55:52 -04:00
parent 628103b9b1
commit 69f9912025
2 changed files with 17 additions and 5 deletions

View File

@ -12,11 +12,15 @@ import (
type BuildOptions struct {
DryRun bool
UseHardLinks bool
Verbose bool
}
// Clean the destination. Remove files that aren't in keep_files, and resulting empty diretories.
func (s *Site) Clean(options BuildOptions) error {
removeFiles := func(name string, info os.FileInfo, err error) error {
if options.Verbose {
fmt.Println("rm", name)
}
switch {
case err != nil && os.IsNotExist(err):
return nil
@ -27,15 +31,17 @@ func (s *Site) Clean(options BuildOptions) error {
case s.KeepFile(name):
return nil
case options.DryRun:
fmt.Println("rm", name)
return nil
default:
return os.Remove(name)
}
return nil
}
if err := filepath.Walk(s.Destination, removeFiles); err != nil {
return err
}
if options.DryRun {
return nil
}
return helpers.RemoveEmptyDirectories(s.Destination)
}
@ -61,14 +67,17 @@ func (s *Site) WritePage(page Page, options BuildOptions) error {
if !page.Static() && filepath.Ext(to) == "" {
to = filepath.Join(to, "/index.html")
}
if options.Verbose {
fmt.Println("create", to, "from", page.Source())
}
if options.DryRun {
return nil
}
// nolint: gas
if err := os.MkdirAll(filepath.Dir(to), 0755); err != nil {
return err
}
switch {
case options.DryRun:
fmt.Println("create", to, "from", page.Source())
return nil
case page.Static() && options.UseHardLinks:
return os.Link(from, to)
case page.Static():

View File

@ -21,6 +21,9 @@ var commandStartTime = time.Now()
func buildCommand(c *cli.Context, site *gojekyll.Site) error {
printPathSetting("Destination:", site.Destination)
printSetting("Generating...", "")
if buildOptions.DryRun {
buildOptions.Verbose = true
}
count, err := site.Build(buildOptions)
if err != nil {
return err