mirror of
https://github.com/opbnq-q/nto-cli.git
synced 2025-12-06 18:00:33 +07:00
gracefull shutdown for unresolvable errors
This commit is contained in:
@@ -1,45 +1,45 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
func FindFrontendPath() string {
|
||||
currentPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
currentPath, err := os.Getwd()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
var dirs []string
|
||||
for currentPath != filepath.VolumeName(currentPath)+string(os.PathSeparator) {
|
||||
dir, file := filepath.Split(currentPath)
|
||||
if file != "" {
|
||||
dirs = append([]string{file}, dirs...)
|
||||
}
|
||||
currentPath = filepath.Clean(dir)
|
||||
}
|
||||
var dirs []string
|
||||
for currentPath != filepath.VolumeName(currentPath)+string(os.PathSeparator) {
|
||||
dir, file := filepath.Split(currentPath)
|
||||
if file != "" {
|
||||
dirs = append([]string{file}, dirs...)
|
||||
}
|
||||
currentPath = filepath.Clean(dir)
|
||||
}
|
||||
|
||||
if len(dirs) < 2 || filepath.Join(dirs[len(dirs)-2], dirs[len(dirs)-1]) != filepath.Join("frontend", "src") {
|
||||
panic(errors.New("You're not in frontend/src"))
|
||||
}
|
||||
if len(dirs) < 2 || filepath.Join(dirs[len(dirs)-2], dirs[len(dirs)-1]) != filepath.Join("frontend", "src") {
|
||||
log.Fatalf("Run this program in frontend/ directory")
|
||||
}
|
||||
|
||||
var path string
|
||||
for i, dir := range dirs {
|
||||
if dir == "frontend" {
|
||||
break
|
||||
}
|
||||
if i > 0 {
|
||||
path = filepath.Join(path, dir)
|
||||
} else {
|
||||
path = dir
|
||||
}
|
||||
}
|
||||
var path string
|
||||
for i, dir := range dirs {
|
||||
if dir == "frontend" {
|
||||
break
|
||||
}
|
||||
if i > 0 {
|
||||
path = filepath.Join(path, dir)
|
||||
} else {
|
||||
path = dir
|
||||
}
|
||||
}
|
||||
|
||||
if filepath.VolumeName(path) == "" {
|
||||
path = filepath.Join(string(os.PathSeparator), path)
|
||||
}
|
||||
if filepath.VolumeName(path) == "" {
|
||||
path = filepath.Join(string(os.PathSeparator), path)
|
||||
}
|
||||
|
||||
return path
|
||||
}
|
||||
return path
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user