Files
kairos-agent/pkg/machine/bootcmdline.go
Eng Zer Jun c080dc6220 art: Move from io/ioutil to io and os packages (#470)
refactor: move from io/ioutil to io and os packages

The io/ioutil package has been deprecated as of Go 1.16 [1]. This commit
replaces the existing io/ioutil functions with their new definitions in
io and os packages.

[1]: https://golang.org/doc/go1.16#ioutil
Signed-off-by: Eng Zer Jun <engzerjun@gmail.com>
2022-11-22 01:11:03 +08:00

41 lines
695 B
Go

package machine
import (
"os"
"strings"
"github.com/google/shlex"
"github.com/kairos-io/kairos/sdk/unstructured"
)
func DotToYAML(file string) ([]byte, error) {
if file == "" {
file = "/proc/cmdline"
}
dat, err := os.ReadFile(file)
if err != nil {
return []byte{}, err
}
v := stringToMap(string(dat))
return unstructured.ToYAML(v)
}
func stringToMap(s string) map[string]interface{} {
v := map[string]interface{}{}
splitted, _ := shlex.Split(s)
for _, item := range splitted {
parts := strings.SplitN(item, "=", 2)
value := "true"
if len(parts) > 1 {
value = strings.Trim(parts[1], `"`)
}
key := strings.Trim(parts[0], `"`)
v[key] = value
}
return v
}