Skip to content

Commit

Permalink
✨ not allow to init the project in a directory that is not cleaned
Browse files Browse the repository at this point in the history
  • Loading branch information
Camila Macedo committed Oct 22, 2020
1 parent 36124ae commit af99c12
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pkg/plugin/v3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v3

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -111,6 +112,22 @@ func (p *initPlugin) Validate() error {
}
}

// It is expected that the directory to scaffold the project will be empty
// The only file that is allows is the go.mod since the user might run
// go mod init before use the plugin it for not be required inform
// the go module via the repo --flag
files, err := ioutil.ReadDir(".")
if err != nil {
return err
}

for _, file := range files {
if file.Name() != "go.mod" && file.Name() != ".gitignore" {
return fmt.Errorf("this directory has files already. " +
"Only the go.mod and .gitigore are allowed before the init.")
}
}

// Check if the project name is a valid k8s namespace (DNS 1123 label).
if p.config.ProjectName == "" {
dir, err := os.Getwd()
Expand Down

0 comments on commit af99c12

Please sign in to comment.