Agent not work yet. Need to build Part B first
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package initcmd
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"fmt"
|
||||
"os"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
@@ -16,6 +14,7 @@ import (
|
||||
"undecided.project/monok8s/pkg/config"
|
||||
|
||||
types "undecided.project/monok8s/pkg/apis/monok8s/v1alpha1"
|
||||
mkscmd "undecided.project/monok8s/pkg/cmd"
|
||||
"undecided.project/monok8s/pkg/templates"
|
||||
)
|
||||
|
||||
@@ -65,7 +64,7 @@ Supported formats:
|
||||
}
|
||||
|
||||
if strings.TrimSpace(envFile) != "" {
|
||||
if err := loadEnvFile(envFile); err != nil {
|
||||
if err := mkscmd.LoadEnvFile(envFile); err != nil {
|
||||
return fmt.Errorf("load env file %q: %w", envFile, err)
|
||||
}
|
||||
}
|
||||
@@ -74,7 +73,7 @@ Supported formats:
|
||||
|
||||
switch {
|
||||
case strings.TrimSpace(envFile) != "":
|
||||
if err := loadEnvFile(envFile); err != nil {
|
||||
if err := mkscmd.LoadEnvFile(envFile); err != nil {
|
||||
return fmt.Errorf("load env file %q: %w", envFile, err)
|
||||
}
|
||||
vals := templates.LoadTemplateValuesFromEnv()
|
||||
@@ -133,55 +132,6 @@ Supported formats:
|
||||
return cmd
|
||||
}
|
||||
|
||||
func loadEnvFile(path string) error {
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
scanner := bufio.NewScanner(f)
|
||||
lineNum := 0
|
||||
|
||||
for scanner.Scan() {
|
||||
lineNum++
|
||||
line := strings.TrimSpace(scanner.Text())
|
||||
|
||||
if line == "" || strings.HasPrefix(line, "#") {
|
||||
continue
|
||||
}
|
||||
|
||||
key, val, ok := strings.Cut(line, "=")
|
||||
if !ok {
|
||||
return fmt.Errorf("line %d: expected KEY=VALUE", lineNum)
|
||||
}
|
||||
|
||||
key = strings.TrimSpace(key)
|
||||
val = strings.TrimSpace(val)
|
||||
|
||||
if key == "" {
|
||||
return fmt.Errorf("line %d: empty variable name", lineNum)
|
||||
}
|
||||
|
||||
// Remove matching single or double quotes around the whole value.
|
||||
if len(val) >= 2 {
|
||||
if (val[0] == '"' && val[len(val)-1] == '"') || (val[0] == '\'' && val[len(val)-1] == '\'') {
|
||||
val = val[1 : len(val)-1]
|
||||
}
|
||||
}
|
||||
|
||||
if err := os.Setenv(key, val); err != nil {
|
||||
return fmt.Errorf("line %d: set %q: %w", lineNum, key, err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := scanner.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseStepSelection(raw string, max int) (bootstrap.StepSelection, error) {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
|
||||
Reference in New Issue
Block a user