Skip to content

Commit 2508e8a

Browse files
authored
fix: default to debian/12 when no OS option present (#68)
1 parent 91b010b commit 2508e8a

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

cli/cmd/global.go

-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,5 @@ type cmdGlobal struct {
1515

1616
ret int
1717

18-
flagHelp bool
1918
flagHelpAll bool
20-
21-
flagLogDebug bool
22-
flagLogVerbose bool
23-
flagQuiet bool
24-
flagVersion bool
2519
}

cli/cmd/launch.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
182182
}
183183
}
184184
}
185-
185+
launchSettings.Image = "images:" + application.InstallMethods[0].Resources.Image()
186+
log.Info("Selected image", "image", launchSettings.Image)
186187
if advanced {
187188

188189
// select install method
@@ -195,8 +196,8 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
195196
huh.NewSelect[int]().
196197
Title("Choose OS Option").
197198
Options(
198-
huh.NewOption(application.InstallMethods[0].Resources.OS, 0),
199-
huh.NewOption(application.InstallMethods[1].Resources.OS, 1),
199+
huh.NewOption(application.InstallMethods[0].Resources.GetOS(), 0),
200+
huh.NewOption(application.InstallMethods[1].Resources.GetOS(), 1),
200201
).
201202
Value(&installMethod),
202203
),
@@ -486,10 +487,10 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
486487
extraConfigs["environment.APPLICATION"] = application.Name
487488

488489
// OS Type
489-
extraConfigs["environment.PCT_OSTYPE"] = application.InstallMethods[launchSettings.InstallMethod].Resources.OS
490+
extraConfigs["environment.PCT_OSTYPE"] = application.InstallMethods[launchSettings.InstallMethod].Resources.GetOS()
490491

491492
// OS Version
492-
extraConfigs["environment.PCT_OSVERSION"] = application.InstallMethods[launchSettings.InstallMethod].Resources.Version
493+
extraConfigs["environment.PCT_OSVERSION"] = application.InstallMethods[launchSettings.InstallMethod].Resources.GetVersion()
493494

494495
// tz
495496
extraConfigs["environment.tz"] = "Etc/UTC"
@@ -501,7 +502,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
501502
// Disable ipv6
502503
extraConfigs["environment.DISABLEIPV6"] = "yes" // todo: make this a form option
503504

504-
if disableSecureBoot(application.InstallMethods[launchSettings.InstallMethod].Resources.OS) {
505+
if disableSecureBoot(application.InstallMethods[launchSettings.InstallMethod].Resources.GetOS()) {
505506
launchSettings.VMSecureBoot = false
506507
}
507508

@@ -516,7 +517,7 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
516517
}
517518

518519
var funcScript []byte
519-
if application.InstallMethods[launchSettings.InstallMethod].Resources.OS == "alpine" {
520+
if application.InstallMethods[launchSettings.InstallMethod].Resources.GetOS() == "alpine" {
520521
funcScript, err = downloadRaw(repository, "misc", "alpine-install.func")
521522
if err != nil {
522523
fmt.Println("download error:", err)
@@ -533,6 +534,8 @@ func (c *cmdLaunch) launch(app string, instanceName string) error {
533534
//extraConfigs["environment.FUNCTIONS_FILE_PATH"] = string(funcScript)
534535

535536
extraConfigs["environment.FUNCTIONS_FILE_PATH"] = "/install.func"
537+
log.Info("Preparing image", "image", launchSettings.Image)
538+
536539
createInstance := func() {
537540
// create the instance
538541
err := c.global.client.Launch(launchSettings.Image, launchSettings.Name, launchSettings.Profiles, extraConfigs, deviceOverrides, launchSettings.Network, launchSettings.VM, false)

cli/cmd/types.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,31 @@ type Resources struct {
4545
}
4646

4747
func (r Resources) GetOS() string {
48+
if r.OS == "" {
49+
return "debian"
50+
}
4851
return strings.ToLower(r.OS)
4952
}
5053
func (r Resources) GetVersion() string {
54+
if r.Version == "" {
55+
return "12"
56+
}
5157
return strings.ToLower(r.Version)
5258
}
5359
func (r Resources) Image() string {
54-
return strings.ToLower(r.OS) + "/" + strings.ToLower(r.Version)
60+
var os string
61+
var version string
62+
if r.OS == "" {
63+
os = "debian"
64+
} else {
65+
os = strings.ToLower(r.OS)
66+
}
67+
if r.Version == "" {
68+
version = "12"
69+
} else {
70+
version = strings.ToLower(r.Version)
71+
}
72+
return strings.ToLower(os) + "/" + strings.ToLower(version)
5573
}
5674

5775
type InstallMethods struct {

0 commit comments

Comments
 (0)