github.com/tooploox/oya@v0.0.21-0.20230524103240-1cda1861aad6/pkg/raw/init.go (about)

     1  package raw
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  
     7  	"github.com/pkg/errors"
     8  )
     9  
    10  func InitDir(dirPath, projectName string) error {
    11  	// BUG(bilus): Use raw access.
    12  	_, found, err := LoadFromDir(dirPath, dirPath)
    13  	if err == nil && found {
    14  		return errors.Errorf("already an Oya project")
    15  	}
    16  	f, err := os.Create(fullPath(dirPath, ""))
    17  	if err != nil {
    18  		return err
    19  	}
    20  	_, err = f.WriteString(fmt.Sprintf("Project: %s\n", projectName))
    21  	if err != nil {
    22  		_ = f.Close()
    23  		return err
    24  	}
    25  	return f.Close()
    26  }