2021-12-29 12:00:51 +00:00
|
|
|
package project
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"runtime"
|
|
|
|
"strings"
|
|
|
|
|
2021-12-29 21:44:28 +00:00
|
|
|
"git.martyn.berlin/martyn/directories/base"
|
2021-12-29 12:00:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var projectNameShort string
|
|
|
|
var projectNameReverse string
|
|
|
|
var projectNameOrg string
|
|
|
|
var projectNameProject string
|
|
|
|
|
|
|
|
// setProjectName sets the project name up and has the following components:
|
|
|
|
// short: a short name for the project, all lowercased
|
|
|
|
// reverse: a java-like reverse-domain-name style
|
|
|
|
// organisation: the name of the organisation which this project is under
|
|
|
|
// project: the "normal" project name
|
|
|
|
// example :
|
|
|
|
// setProjectName("notepad++","org.notepad-plus-plus.notepad-plus-plus","Don Ho","Notepad++")
|
|
|
|
// This is used for basing folder structures on.
|
|
|
|
func SetProjectName(short, reverse, organisation, project string) error {
|
|
|
|
projectNameShort = short
|
|
|
|
projectNameReverse = reverse
|
|
|
|
projectNameOrg = organisation
|
|
|
|
projectNameProject = project
|
|
|
|
if len(projectNameShort) < 1 || len(projectNameReverse) < 1 ||
|
|
|
|
len(projectNameProject) < 1 || len(projectNameProject) < 1 {
|
|
|
|
return errors.New("to use the directories/project package, you must call project.SetProjectName() with all four arguments set")
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func projectPath() string {
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
return strings.ToLower(strings.ReplaceAll(projectNameShort, " ", "-"))
|
|
|
|
case "windows":
|
|
|
|
return projectNameOrg + "\\" + projectNameProject
|
|
|
|
case "darwin":
|
|
|
|
return projectNameReverse
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
|
|
|
func Cache() (string, error) {
|
|
|
|
if len(projectNameShort) < 1 || len(projectNameReverse) < 1 ||
|
|
|
|
len(projectNameProject) < 1 || len(projectNameProject) < 1 {
|
|
|
|
return "", errors.New("to use the directories/project package, you must call project.SetProjectName() with all four arguments set")
|
|
|
|
}
|
|
|
|
c, e := base.Cache()
|
|
|
|
if e != nil {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
case "windows":
|
|
|
|
return c + "\\" + projectPath() + "\\cache", nil
|
|
|
|
case "darwin":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Cache()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Config() (string, error) {
|
|
|
|
if len(projectNameShort) < 1 || len(projectNameReverse) < 1 ||
|
|
|
|
len(projectNameProject) < 1 || len(projectNameProject) < 1 {
|
|
|
|
return "", errors.New("to use the directories/project package, you must call project.SetProjectName() with all four arguments set")
|
|
|
|
}
|
|
|
|
c, e := base.Config()
|
|
|
|
if e != nil {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
case "windows":
|
|
|
|
return c + "\\" + projectPath() + "\\config", nil
|
|
|
|
case "darwin":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Config()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func Data() (string, error) {
|
|
|
|
if len(projectNameShort) < 1 || len(projectNameReverse) < 1 ||
|
|
|
|
len(projectNameProject) < 1 || len(projectNameProject) < 1 {
|
|
|
|
return "", errors.New("to use the directories/project package, you must call project.SetProjectName() with all four arguments set")
|
|
|
|
}
|
|
|
|
c, e := base.Data()
|
|
|
|
if e != nil {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
case "windows":
|
|
|
|
return c + "\\" + projectPath() + "\\data", nil
|
|
|
|
case "darwin":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Data()")
|
|
|
|
}
|
|
|
|
|
|
|
|
func DataLocal() (string, error) {
|
|
|
|
if len(projectNameShort) < 1 || len(projectNameReverse) < 1 ||
|
|
|
|
len(projectNameProject) < 1 || len(projectNameProject) < 1 {
|
|
|
|
return "", errors.New("to use the directories/project package, you must call project.SetProjectName() with all four arguments set")
|
|
|
|
}
|
|
|
|
c, e := base.DataLocal()
|
|
|
|
if e != nil {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
case "windows":
|
|
|
|
return c + "\\" + projectPath() + "\\data", nil
|
|
|
|
case "darwin":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for DataLocal()")
|
|
|
|
}
|
|
|
|
func Preferences() (string, error) {
|
|
|
|
if len(projectNameShort) < 1 || len(projectNameReverse) < 1 ||
|
|
|
|
len(projectNameProject) < 1 || len(projectNameProject) < 1 {
|
|
|
|
return "", errors.New("to use the directories/project package, you must call project.SetProjectName() with all four arguments set")
|
|
|
|
}
|
|
|
|
c, e := base.Preferences()
|
|
|
|
if e != nil {
|
|
|
|
return "", e
|
|
|
|
}
|
|
|
|
switch runtime.GOOS {
|
|
|
|
case "linux":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
case "windows":
|
|
|
|
return c + "\\" + projectPath() + "\\config", nil
|
|
|
|
case "darwin":
|
|
|
|
return c + "/" + projectPath(), nil
|
|
|
|
}
|
|
|
|
return "", errors.New("could not determine location for Preferences()")
|
|
|
|
}
|