Skip to content

Commit

Permalink
Refactor: reduce nesting and return error
Browse files Browse the repository at this point in the history
Signed-off-by: Anders F Björklund <[email protected]>
  • Loading branch information
afbjorklund committed Aug 30, 2024
1 parent 726f61d commit 771592f
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions pkg/cidata/cidata.go
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ func GenerateISO9660(instDir, name string, y *limayaml.LimaYAML, udpDNSLocalPort
args.CACerts.Trusted = append(args.CACerts.Trusted, cert)
}

args.BootCmds = getBootCmds(y.Provision)
args.BootCmds, err = getBootCmds(y.Provision)
if err != nil {
return err
}

for _, f := range y.Provision {
if f.Mode == limayaml.ProvisionModeDependency && *f.SkipDefaultDependencyResolution {
Expand Down Expand Up @@ -405,21 +408,22 @@ func getCert(content string) Cert {
return Cert{Lines: lines}
}

func getBootCmds(p []limayaml.Provision) []BootCmds {
func getBootCmds(p []limayaml.Provision) ([]BootCmds, error) {
var bootCmds []BootCmds
for _, f := range p {
if f.Mode == limayaml.ProvisionModeBoot {
lines := []string{}
for _, line := range strings.Split(f.Script, "\n") {
if line == "" {
continue
}
lines = append(lines, strings.TrimSpace(line))
if f.Mode != limayaml.ProvisionModeBoot {
continue
}
lines := []string{}
for _, line := range strings.Split(f.Script, "\n") {
if line == "" {
continue
}
bootCmds = append(bootCmds, BootCmds{Lines: lines})
lines = append(lines, strings.TrimSpace(line))
}
bootCmds = append(bootCmds, BootCmds{Lines: lines})
}
return bootCmds
return bootCmds, nil
}

func diskDeviceNameFromOrder(order int) string {
Expand Down

0 comments on commit 771592f

Please sign in to comment.