Add basic interactive overwrite strategy

Available options:

- Do not copy
- Overwrite dest
- Copy source as dest.dist
This commit is contained in:
2020-05-23 11:56:44 +02:00
parent 6aaa82efa4
commit 0fa845b3ff
9 changed files with 154 additions and 20 deletions

View File

@ -1,7 +1,7 @@
package command
import (
"log"
"fmt"
"net/url"
"os"
@ -32,6 +32,12 @@ func fromCommand() *cli.Command {
Usage: "The scaffold manifest `FILE`",
Value: "scaffold.yml",
},
&cli.StringSliceFlag{
Name: "ignore",
Aliases: []string{"i"},
Usage: "Ignore files matching pattern",
Value: cli.NewStringSlice(".git", ".git/**", "./.git/**/*"),
},
},
Action: fromAction,
}
@ -78,13 +84,13 @@ func fromAction(c *cli.Context) error {
return errors.Wrapf(err, "could not read manifest '%s'", manifestPath)
}
log.Println("Could not find scaffold manifest.")
fmt.Println("Could not find scaffold manifest.")
}
if manifestFile != nil {
defer manifestFile.Close()
log.Println("Loading template scaffold manifest...")
fmt.Println("Loading scaffold manifest.")
manifest, err := template.Load(manifestFile)
if err != nil {
@ -95,6 +101,7 @@ func fromAction(c *cli.Context) error {
return errors.Wrapf(err, "could not validate manifest '%s'", manifestPath)
}
fmt.Println("Prompting for templates variables.")
if err := template.Prompt(manifest, templateData); err != nil {
return errors.Wrap(err, "could not prompt for template data")
}
@ -102,9 +109,22 @@ func fromAction(c *cli.Context) error {
directory := c.String("directory")
return template.CopyDir(vfs, ".", directory, &template.Option{
TemplateData: templateData,
TemplateExt: ".gotpl",
IgnorePatterns: []string{manifestPath},
ignore := c.StringSlice("ignore")
ignore = append(ignore, manifestPath)
fmt.Println("Generating project tree.")
err = template.CopyDir(vfs, ".", directory, &template.Option{
TemplateData: templateData,
TemplateExt: ".gotpl",
IgnorePatterns: ignore,
PreferredStrategy: template.Undefined,
})
if err != nil {
return err
}
fmt.Println("Done.")
return nil
}