44 lines
900 B
Go
44 lines
900 B
Go
package cli
|
|
|
|
import (
|
|
"bufio"
|
|
"os"
|
|
"recipe-manager/services/logger"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
var (
|
|
log_inst = logger.GetInstance()
|
|
disable_cli = false
|
|
debug = logger.GetDbgState()
|
|
)
|
|
|
|
func CommandLineListener() {
|
|
debug = logger.GetDbgState()
|
|
reader := bufio.NewReader(os.Stdin)
|
|
for !disable_cli {
|
|
input, _ := reader.ReadString('\n')
|
|
input = strings.TrimSpace(input)
|
|
|
|
switch input {
|
|
case "debug":
|
|
logger.EnableDebug(!logger.GetDbgState())
|
|
debug = logger.GetDbgState()
|
|
// log_inst.Info("Debug mode enable from cli", zap.Bool("enable", logger.GetDbgState()))
|
|
case "ctl":
|
|
if debug {
|
|
log_inst.Debug("CMD > ", zap.String("CMD", input))
|
|
}
|
|
default:
|
|
if debug {
|
|
// log_inst.Debug("CMD > ", zap.String("CMD", input))
|
|
|
|
// Add functions here!
|
|
} else {
|
|
log_inst.Error("INVALID CMD or CMD DISABLED", zap.String("CMD", input))
|
|
}
|
|
}
|
|
}
|
|
}
|