Add --wipe flag to rm the output dir pre-generate
- As discussed in #96
This commit is contained in:
parent
ec28cb4148
commit
671e1d7ae9
3 changed files with 9 additions and 0 deletions
|
@ -333,6 +333,12 @@ func (s *State) initTags(tags []string) error {
|
|||
|
||||
// initOutFolder creates the folder that will hold the generated output.
|
||||
func (s *State) initOutFolder() error {
|
||||
if s.Config.Wipe {
|
||||
if err := os.RemoveAll(s.Config.OutFolder); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return os.MkdirAll(s.Config.OutFolder, os.ModePerm)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,6 +15,7 @@ type Config struct {
|
|||
NoTests bool
|
||||
NoHooks bool
|
||||
NoAutoTimestamps bool
|
||||
Wipe bool
|
||||
|
||||
Postgres PostgresConfig
|
||||
MySQL MySQLConfig
|
||||
|
|
2
main.go
2
main.go
|
@ -86,6 +86,7 @@ func main() {
|
|||
rootCmd.PersistentFlags().BoolP("no-auto-timestamps", "", false, "Disable automatic timestamps for created_at/updated_at")
|
||||
rootCmd.PersistentFlags().BoolP("version", "", false, "Print the version")
|
||||
rootCmd.PersistentFlags().BoolP("tinyint-as-bool", "", false, "Map MySQL tinyint(1) in Go to bool instead of int8")
|
||||
rootCmd.PersistentFlags().BoolP("wipe", "", false, "Delete the output folder (rm -rf) before generation to ensure sanity")
|
||||
|
||||
viper.SetDefault("postgres.sslmode", "require")
|
||||
viper.SetDefault("postgres.port", "5432")
|
||||
|
@ -134,6 +135,7 @@ func preRun(cmd *cobra.Command, args []string) error {
|
|||
NoTests: viper.GetBool("no-tests"),
|
||||
NoHooks: viper.GetBool("no-hooks"),
|
||||
NoAutoTimestamps: viper.GetBool("no-auto-timestamps"),
|
||||
Wipe: viper.GetBool("wipe"),
|
||||
}
|
||||
|
||||
// BUG: https://github.com/spf13/viper/issues/200
|
||||
|
|
Loading…
Reference in a new issue