Skip to content

Commit

Permalink
cmd/start: Simplify writeTemplatedMessage
Browse files Browse the repository at this point in the history
Instead of a single method with multiple "if podman {}" checks, and 2
codepaths which don't much in common, this uses 2 separate methods, one
for podman, the other for OpenShift.
  • Loading branch information
cfergeau authored and praveenkumar committed Nov 30, 2021
1 parent b7ce4fa commit dcdea5c
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions cmd/crc/cmd/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,30 +259,42 @@ type templateVariables struct {
}

func writeTemplatedMessage(writer io.Writer, s *startResult) error {
parsed, err := template.New("template").Parse(startTemplateForPodman)
if err != nil {
return err
}
// This should be replaced with the config preset once
// we start using preset as part of config.
if s.ClusterConfig.ClusterCACert != "" {
parsed, err = template.New("template").Parse(startTemplateForOpenshift)
if err != nil {
return err
}
return writeOpenShiftTemplatedMessage(writer, s)
}

return writePodmanTemplatedMessage(writer, s)
}

func writeOpenShiftTemplatedMessage(writer io.Writer, s *startResult) error {
parsed, err := template.New("template").Parse(startTemplateForOpenshift)
if err != nil {
return err
}
userShell, err := shell.GetShell("")
if err != nil {
userShell = ""
}

if s.ClusterConfig.ClusterCACert != "" {
return parsed.Execute(writer, &templateVariables{
ClusterConfig: s.ClusterConfig,
EvalCommandLine: shell.GenerateUsageHint(userShell, "crc oc-env"),
CommandLinePrefix: commandLinePrefix(userShell),
})
return parsed.Execute(writer, &templateVariables{
ClusterConfig: s.ClusterConfig,
EvalCommandLine: shell.GenerateUsageHint(userShell, "crc oc-env"),
CommandLinePrefix: commandLinePrefix(userShell),
})
}

func writePodmanTemplatedMessage(writer io.Writer, s *startResult) error {
parsed, err := template.New("template").Parse(startTemplateForPodman)
if err != nil {
return err
}
userShell, err := shell.GetShell("")
if err != nil {
userShell = ""
}

return parsed.Execute(writer, &templateVariables{
EvalCommandLine: shell.GenerateUsageHint(userShell, "crc podman-env"),
CommandLinePrefix: commandLinePrefix(userShell),
Expand Down

0 comments on commit dcdea5c

Please sign in to comment.