WE DID IT! The first actual command to be ported. Code is still a mess in terms of UX but its a milestone!
This commit is contained in:
49
config/env.go
Normal file
49
config/env.go
Normal file
@ -0,0 +1,49 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os/user"
|
||||
|
||||
"github.com/joho/godotenv"
|
||||
)
|
||||
|
||||
// TODO: envvar
|
||||
const ABRA_DIR = ".abra"
|
||||
|
||||
var ABRA_SERVER_FOLDER = fmt.Sprintf("/%s/%s", ABRA_DIR, "servers")
|
||||
|
||||
func getHomeDir() string {
|
||||
// Future: Windows support?
|
||||
user, err := user.Current()
|
||||
if err != nil {
|
||||
log.Fatalf(err.Error())
|
||||
}
|
||||
return user.HomeDir
|
||||
}
|
||||
|
||||
func ReadServerNames() []string {
|
||||
var serverNames []string
|
||||
files, err := ioutil.ReadDir(getHomeDir() + ABRA_SERVER_FOLDER)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
for _, file := range files {
|
||||
// Check if file is directory or symlink to one
|
||||
if file.IsDir() || file.Mode()&fs.ModeSymlink != 0 {
|
||||
serverNames = append(serverNames, file.Name())
|
||||
}
|
||||
}
|
||||
return serverNames
|
||||
}
|
||||
|
||||
func ReadEnv(filePath string) map[string]string {
|
||||
var envFile map[string]string
|
||||
envFile, err := godotenv.Read(filePath)
|
||||
if err != nil {
|
||||
panic(err) // TODO: Better logging
|
||||
}
|
||||
return envFile
|
||||
}
|
Reference in New Issue
Block a user