diff --git a/app/client.go b/app/client.go index 0a959d3ac72e826a7e6472993f192c5a5709fc85..639ac7b766aa36f0ae63c5055f208ec622d19929 100644 --- a/app/client.go +++ b/app/client.go @@ -1,7 +1,12 @@ package main import ( + "fmt" + "gopkg.in/yaml.v3" + command_line "node/command-line" . "node/types" + "node/utilities" + "os" ) /* @@ -12,5 +17,33 @@ import ( */ func main() { + argsLen := len(os.Args) + isThereEnoughArgs := argsLen <= 1 + if isThereEnoughArgs { + fmt.Println("First argument should be the path of the config file '--path=<config.yaml>'") + os.Exit(1) + } + + // init configuration + args := os.Args[1:] + fmt.Println("Program started with arguments", args) + fmt.Println("config file path is ", args[0][7:]) + + buf, err := os.ReadFile(args[0][7:]) + if err != nil { + fmt.Println("Error while reading the config file", err) + fmt.Println("Exiting...") + os.Exit(1) + } + + var clientConfig Config + err = yaml.Unmarshal(buf, &clientConfig) + if err != nil { + os.Exit(1) + } + + utilities.PrintConfig(clientConfig) + + command_line.ClientUserInputLoop(clientConfig, true) }