load from config file

This commit is contained in:
Aidan 2020-07-03 02:02:12 -07:00
parent 0d7eb4139b
commit f98cd75160
No known key found for this signature in database
GPG key ID: 327711E983899316
2 changed files with 93 additions and 17 deletions

View file

@ -18,21 +18,26 @@
package main
import (
"os"
"fmt"
"strconv"
"github.com/chzyer/readline"
"gitlab.com/whom/shs/ast"
"gitlab.com/whom/shs/log"
"gitlab.com/whom/shs/stdlib"
"gitlab.com/whom/shs/config"
)
const (
def_prompt string = "λ "
)
func setLogLvl() {
loglvl := os.Getenv("SH_LOGGING")
func setLogLvl(vars ast.VarTable) {
var loglvl string
loglvl_t := ast.GetVar("SH_LOGGING", vars)
if loglvl_t != nil {
loglvl = loglvl_t.Value()
}
if loglvl != "" {
llvl, err := strconv.ParseInt(loglvl, 10, 8)
if err != nil {
@ -46,23 +51,28 @@ func setLogLvl() {
}
func main() {
debug := os.Getenv("SH_DEBUG_MODE")
hist := os.Getenv("SH_HIST_FILE")
prompt := os.Getenv("SHS_SH_PROMPT")
var prompt string
var debug string
var hist string
var vars ast.VarTable
var funcs ast.FuncTable
funcs = stdlib.GenFuncTable()
vars = &map[string]*ast.Token{}
ast.InitVarTable(vars)
ast.SyncTablesWithOSEnviron = true
ast.ExecWhenFuncUndef = true
var err error
vars, funcs := config.InitFromConfig(".shsrc")
debug_t := ast.GetVar("SH_DEBUG_MODE", vars)
if debug_t != nil {
debug = debug_t.Value()
}
if prompt == "" {
hist_t := ast.GetVar("SH_HIST_FILE", vars)
if hist_t != nil {
hist = hist_t.Value()
}
prompt_t := ast.GetVar("SHS_SH_PROMPT", vars)
if prompt_t != nil {
prompt = prompt_t.Value()
} else {
prompt = def_prompt
}
@ -79,7 +89,7 @@ func main() {
}
for {
setLogLvl()
setLogLvl(vars)
text, err := rl.Readline()
if err != nil {
log.Log(log.ERR, "couldnt read user input: " + err.Error(), "repl")