feat: abra server ls
All checks were successful
continuous-integration/drone/push Build is passing

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:
2021-07-18 04:21:26 +01:00
parent e13948f37e
commit 38f610bdec
5 changed files with 239 additions and 15 deletions

49
config/env.go Normal file
View 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
}