Skip to content

Commit b70c790

Browse files
authored
feat: Use the app name in the help menu output (#2396)
Use app title in command help menu output
1 parent a019e90 commit b70c790

35 files changed

+187
-165
lines changed

api/internal/managers/infra/install.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ const K0sComponentName = "Runtime"
3333
func AlreadyInstalledError() error {
3434
return fmt.Errorf(
3535
"\nAn installation is detected on this machine.\nTo install, you must first remove the existing installation.\nYou can do this by running the following command:\n\n sudo ./%s reset\n",
36-
runtimeconfig.BinaryName(),
36+
runtimeconfig.AppSlug(),
3737
)
3838
}
3939

api/pkg/logger/logger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func NewLogger() (*logrus.Logger, error) {
15-
fname := fmt.Sprintf("%s-%s.api.log", runtimeconfig.BinaryName(), time.Now().Format("20060102150405.000"))
15+
fname := fmt.Sprintf("%s-%s.api.log", runtimeconfig.AppSlug(), time.Now().Format("20060102150405.000"))
1616
logpath := runtimeconfig.PathToLog(fname)
1717
logfile, err := os.OpenFile(logpath, os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0400)
1818
if err != nil {

cmd/installer/cli/adminconsole.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ import (
77
"github.com/spf13/cobra"
88
)
99

10-
func AdminConsoleCmd(ctx context.Context, name string) *cobra.Command {
10+
func AdminConsoleCmd(ctx context.Context, appTitle string) *cobra.Command {
1111
cmd := &cobra.Command{
1212
Use: "admin-console",
13-
Short: fmt.Sprintf("Manage the %s Admin Console", name),
13+
Short: fmt.Sprintf("Manage the %s Admin Console", appTitle),
1414
RunE: func(cmd *cobra.Command, args []string) error {
1515
return nil
1616
},
1717
}
1818

19-
cmd.AddCommand(AdminConsoleResetPasswordCmd(ctx, name))
19+
cmd.AddCommand(AdminConsoleResetPasswordCmd(ctx, appTitle))
2020

2121
return cmd
2222
}

cmd/installer/cli/adminconsole_resetpassword.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ import (
1515
"github.com/spf13/cobra"
1616
)
1717

18-
func AdminConsoleResetPasswordCmd(ctx context.Context, name string) *cobra.Command {
18+
func AdminConsoleResetPasswordCmd(ctx context.Context, appTitle string) *cobra.Command {
1919
var rc runtimeconfig.RuntimeConfig
2020

2121
cmd := &cobra.Command{
2222
Use: "reset-password [password]",
2323
Args: cobra.MaximumNArgs(1),
24-
Short: fmt.Sprintf("Reset the %s Admin Console password. If no password is provided, you will be prompted to enter a new one.", name),
24+
Short: fmt.Sprintf("Reset the %s Admin Console password. If no password is provided, you will be prompted to enter a new one.", appTitle),
2525
PreRunE: func(cmd *cobra.Command, args []string) error {
2626
// Skip root check if dryrun mode is enabled
2727
if !dryrun.Enabled() && os.Getuid() != 0 {

cmd/installer/cli/enable_ha.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ import (
2020
)
2121

2222
// EnableHACmd is the command for enabling HA mode.
23-
func EnableHACmd(ctx context.Context, name string) *cobra.Command {
23+
func EnableHACmd(ctx context.Context, appTitle string) *cobra.Command {
2424
var rc runtimeconfig.RuntimeConfig
2525

2626
cmd := &cobra.Command{
2727
Use: "enable-ha",
28-
Short: fmt.Sprintf("Enable high availability for the %s cluster", name),
28+
Short: fmt.Sprintf("Enable high availability for the %s cluster", appTitle),
2929
PreRunE: func(cmd *cobra.Command, args []string) error {
3030
// Skip root check if dryrun mode is enabled
3131
if !dryrun.Enabled() && os.Getuid() != 0 {

cmd/installer/cli/install.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,29 +100,29 @@ type installConfig struct {
100100
var webAssetsFS fs.FS = nil
101101

102102
// InstallCmd returns a cobra command for installing the embedded cluster.
103-
func InstallCmd(ctx context.Context, name string) *cobra.Command {
103+
func InstallCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
104104
var flags InstallCmdFlags
105105

106106
ctx, cancel := context.WithCancel(ctx)
107107

108108
rc := runtimeconfig.New(nil)
109109
ki := kubernetesinstallation.New(nil)
110110

111-
short := fmt.Sprintf("Install %s", name)
111+
short := fmt.Sprintf("Install %s", appTitle)
112112
if os.Getenv("ENABLE_V3") == "1" {
113-
short = fmt.Sprintf("Install %s onto Linux or Kubernetes", name)
113+
short = fmt.Sprintf("Install %s onto Linux or Kubernetes", appTitle)
114114
}
115115

116116
cmd := &cobra.Command{
117117
Use: "install",
118118
Short: short,
119-
Example: installCmdExample(name),
119+
Example: installCmdExample(appSlug),
120120
PostRun: func(cmd *cobra.Command, args []string) {
121121
rc.Cleanup()
122122
cancel() // Cancel context when command completes
123123
},
124124
RunE: func(cmd *cobra.Command, args []string) error {
125-
if err := verifyAndPrompt(ctx, name, flags, prompts.New()); err != nil {
125+
if err := verifyAndPrompt(ctx, appSlug, flags, prompts.New()); err != nil {
126126
return err
127127
}
128128
if err := preRunInstall(cmd, &flags, rc, ki); err != nil {
@@ -137,7 +137,7 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
137137
installReporter.ReportInstallationStarted(ctx)
138138

139139
if flags.enableManagerExperience {
140-
return runManagerExperienceInstall(ctx, flags, rc, ki, installReporter)
140+
return runManagerExperienceInstall(ctx, flags, rc, ki, installReporter, appTitle)
141141
}
142142

143143
_ = rc.SetEnv()
@@ -173,7 +173,7 @@ func InstallCmd(ctx context.Context, name string) *cobra.Command {
173173
panic(err)
174174
}
175175

176-
cmd.AddCommand(InstallRunPreflightsCmd(ctx, name))
176+
cmd.AddCommand(InstallRunPreflightsCmd(ctx, appSlug))
177177

178178
return cmd
179179
}
@@ -196,12 +196,12 @@ const (
196196
`
197197
)
198198

199-
func installCmdExample(name string) string {
199+
func installCmdExample(appSlug string) string {
200200
if os.Getenv("ENABLE_V3") != "1" {
201201
return ""
202202
}
203203

204-
return fmt.Sprintf(installCmdExampleText, name, name)
204+
return fmt.Sprintf(installCmdExampleText, appSlug, appSlug)
205205
}
206206

207207
func mustAddInstallFlags(cmd *cobra.Command, flags *InstallCmdFlags) {
@@ -265,7 +265,7 @@ func newLinuxInstallFlags(flags *InstallCmdFlags) *pflag.FlagSet {
265265
// Use the app slug as default data directory only when ENABLE_V3 is set
266266
defaultDataDir := ecv1beta1.DefaultDataDir
267267
if os.Getenv("ENABLE_V3") == "1" {
268-
defaultDataDir = filepath.Join("/var/lib", runtimeconfig.BinaryName())
268+
defaultDataDir = filepath.Join("/var/lib", runtimeconfig.AppSlug())
269269
}
270270

271271
flagSet.StringVar(&flags.dataDir, "data-dir", defaultDataDir, "Path to the data directory")
@@ -570,7 +570,7 @@ func cidrConfigFromCmd(cmd *cobra.Command) (*newconfig.CIDRConfig, error) {
570570
return cidrCfg, nil
571571
}
572572

573-
func runManagerExperienceInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, ki kubernetesinstallation.Installation, installReporter *InstallReporter) (finalErr error) {
573+
func runManagerExperienceInstall(ctx context.Context, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig, ki kubernetesinstallation.Installation, installReporter *InstallReporter, appTitle string) (finalErr error) {
574574
// this is necessary because the api listens on all interfaces,
575575
// and we only know the interface to use when the user selects it in the ui
576576
ipAddresses, err := netutils.ListAllValidIPAddresses()
@@ -663,7 +663,7 @@ func runManagerExperienceInstall(ctx context.Context, flags InstallCmdFlags, rc
663663
}
664664

665665
logrus.Infof("\nVisit the %s manager to continue: %s\n",
666-
runtimeconfig.BinaryName(),
666+
appTitle,
667667
getManagerURL(flags.hostname, flags.managerPort))
668668
<-ctx.Done()
669669

@@ -813,9 +813,9 @@ func getAddonInstallOpts(flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig,
813813
return opts, nil
814814
}
815815

816-
func verifyAndPrompt(ctx context.Context, name string, flags InstallCmdFlags, prompt prompts.Prompt) error {
816+
func verifyAndPrompt(ctx context.Context, appSlug string, flags InstallCmdFlags, prompt prompts.Prompt) error {
817817
logrus.Debugf("checking if k0s is already installed")
818-
err := verifyNoInstallation(name, "reinstall")
818+
err := verifyNoInstallation(appSlug, "reinstall")
819819
if err != nil {
820820
return err
821821
}
@@ -987,7 +987,7 @@ func verifyChannelRelease(cmdName string, isAirgap bool, assumeYes bool) error {
987987
return nil
988988
}
989989

990-
func verifyNoInstallation(name string, cmdName string) error {
990+
func verifyNoInstallation(appSlug string, cmdName string) error {
991991
installed, err := k0s.IsInstalled()
992992
if err != nil {
993993
return err
@@ -996,7 +996,7 @@ func verifyNoInstallation(name string, cmdName string) error {
996996
logrus.Errorf("\nAn installation is detected on this machine.")
997997
logrus.Infof("To %s, you must first remove the existing installation.", cmdName)
998998
logrus.Infof("You can do this by running the following command:")
999-
logrus.Infof("\n sudo ./%s reset\n", name)
999+
logrus.Infof("\n sudo ./%s reset\n", appSlug)
10001000
return NewErrorNothingElseToAdd(errors.New("previous installation detected"))
10011001
}
10021002
return nil

cmd/installer/cli/install_runpreflights.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
// they contain failures. We use this to differentiate the way we provide user feedback.
2323
var ErrPreflightsHaveFail = metrics.NewErrorNoFail(fmt.Errorf("host preflight failures detected"))
2424

25-
func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
25+
func InstallRunPreflightsCmd(ctx context.Context, appSlug string) *cobra.Command {
2626
var flags InstallCmdFlags
2727

2828
rc := runtimeconfig.New(nil)
@@ -45,7 +45,7 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
4545
rc.Cleanup()
4646
},
4747
RunE: func(cmd *cobra.Command, args []string) error {
48-
if err := runInstallRunPreflights(cmd.Context(), name, flags, rc); err != nil {
48+
if err := runInstallRunPreflights(cmd.Context(), appSlug, flags, rc); err != nil {
4949
return err
5050
}
5151

@@ -62,8 +62,8 @@ func InstallRunPreflightsCmd(ctx context.Context, name string) *cobra.Command {
6262
return cmd
6363
}
6464

65-
func runInstallRunPreflights(ctx context.Context, name string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig) error {
66-
if err := verifyAndPrompt(ctx, name, flags, prompts.New()); err != nil {
65+
func runInstallRunPreflights(ctx context.Context, appSlug string, flags InstallCmdFlags, rc runtimeconfig.RuntimeConfig) error {
66+
if err := verifyAndPrompt(ctx, appSlug, flags, prompts.New()); err != nil {
6767
return err
6868
}
6969

cmd/installer/cli/join.go

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ type JoinCmdFlags struct {
5050
}
5151

5252
// JoinCmd returns a cobra command for joining a node to the cluster.
53-
func JoinCmd(ctx context.Context, name string) *cobra.Command {
53+
func JoinCmd(ctx context.Context, appSlug, appTitle string) *cobra.Command {
5454
var flags JoinCmdFlags
5555

5656
ctx, cancel := context.WithCancel(ctx)
5757
rc := runtimeconfig.New(nil)
5858

5959
cmd := &cobra.Command{
6060
Use: "join <url> <token>",
61-
Short: fmt.Sprintf("Join a node to the %s cluster", name),
61+
Short: fmt.Sprintf("Join a node to the %s cluster", appTitle),
6262
Args: cobra.ExactArgs(2),
6363
PreRunE: func(cmd *cobra.Command, args []string) error {
6464
if err := preRunJoin(&flags); err != nil {
@@ -87,7 +87,7 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
8787
joinReporter.ReportSignalAborted(ctx, sig)
8888
})
8989

90-
if err := runJoin(cmd.Context(), name, flags, rc, jcmd, args[0], joinReporter); err != nil {
90+
if err := runJoin(cmd.Context(), appSlug, flags, rc, jcmd, args[0], joinReporter); err != nil {
9191
// Check if this is an interrupt error from the terminal
9292
if errors.Is(err, terminal.InterruptErr) {
9393
joinReporter.ReportSignalAborted(ctx, syscall.SIGINT)
@@ -106,8 +106,8 @@ func JoinCmd(ctx context.Context, name string) *cobra.Command {
106106
panic(err)
107107
}
108108

109-
cmd.AddCommand(JoinRunPreflightsCmd(ctx, name))
110-
cmd.AddCommand(JoinPrintCommandCmd(ctx, name))
109+
cmd.AddCommand(JoinRunPreflightsCmd(ctx, appSlug, appTitle))
110+
cmd.AddCommand(JoinPrintCommandCmd(ctx, appTitle))
111111

112112
return cmd
113113
}
@@ -153,18 +153,18 @@ func addJoinFlags(cmd *cobra.Command, flags *JoinCmdFlags) error {
153153
return nil
154154
}
155155

156-
func runJoin(ctx context.Context, name string, flags JoinCmdFlags, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse, kotsAPIAddress string, joinReporter *JoinReporter) error {
156+
func runJoin(ctx context.Context, appSlug string, flags JoinCmdFlags, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse, kotsAPIAddress string, joinReporter *JoinReporter) error {
157157
// both controller and worker nodes will have 'worker' in the join command
158158
isWorker := !strings.Contains(jcmd.K0sJoinCommand, "controller")
159159
if !isWorker {
160160
logrus.Warn("\nDo not join another node until this node has joined successfully.")
161161
}
162162

163-
if err := runJoinVerifyAndPrompt(name, flags, rc, jcmd); err != nil {
163+
if err := runJoinVerifyAndPrompt(appSlug, flags, rc, jcmd); err != nil {
164164
return err
165165
}
166166

167-
cidrCfg, err := initializeJoin(ctx, name, rc, jcmd, kotsAPIAddress)
167+
cidrCfg, err := initializeJoin(ctx, appSlug, rc, jcmd, kotsAPIAddress)
168168
if err != nil {
169169
return fmt.Errorf("unable to initialize join: %w", err)
170170
}
@@ -180,7 +180,7 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, rc runtimecon
180180
logrus.Debugf("installing and joining cluster")
181181
loading := spinner.Start()
182182
loading.Infof("Installing node")
183-
if err := installAndJoinCluster(ctx, rc, jcmd, name, flags, isWorker); err != nil {
183+
if err := installAndJoinCluster(ctx, rc, jcmd, appSlug, flags, isWorker); err != nil {
184184
loading.ErrorClosef("Failed to install node")
185185
return err
186186
}
@@ -226,9 +226,9 @@ func runJoin(ctx context.Context, name string, flags JoinCmdFlags, rc runtimecon
226226
return nil
227227
}
228228

229-
func runJoinVerifyAndPrompt(name string, flags JoinCmdFlags, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse) error {
229+
func runJoinVerifyAndPrompt(appSlug string, flags JoinCmdFlags, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse) error {
230230
logrus.Debugf("checking if k0s is already installed")
231-
err := verifyNoInstallation(name, "join a node")
231+
err := verifyNoInstallation(appSlug, "join a node")
232232
if err != nil {
233233
return err
234234
}
@@ -284,7 +284,7 @@ func runJoinVerifyAndPrompt(name string, flags JoinCmdFlags, rc runtimeconfig.Ru
284284
return nil
285285
}
286286

287-
func initializeJoin(ctx context.Context, name string, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse, kotsAPIAddress string) (cidrCfg *newconfig.CIDRConfig, err error) {
287+
func initializeJoin(ctx context.Context, appSlug string, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse, kotsAPIAddress string) (cidrCfg *newconfig.CIDRConfig, err error) {
288288
logrus.Info("")
289289
spinner := spinner.Start()
290290
spinner.Infof("Initializing")
@@ -306,7 +306,7 @@ func initializeJoin(ctx context.Context, name string, rc runtimeconfig.RuntimeCo
306306
logrus.Debugf("unable to chmod embedded-cluster home dir: %s", err)
307307
}
308308

309-
logrus.Debugf("materializing %s binaries", name)
309+
logrus.Debugf("materializing %s binaries", appSlug)
310310
if err := materializeFilesForJoin(ctx, rc, jcmd, kotsAPIAddress); err != nil {
311311
return nil, fmt.Errorf("failed to materialize files: %w", err)
312312
}
@@ -382,13 +382,13 @@ func getJoinCIDRConfig(rc runtimeconfig.RuntimeConfig) (*newconfig.CIDRConfig, e
382382
}, nil
383383
}
384384

385-
func installAndJoinCluster(ctx context.Context, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse, name string, flags JoinCmdFlags, isWorker bool) error {
385+
func installAndJoinCluster(ctx context.Context, rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCommandResponse, appSlug string, flags JoinCmdFlags, isWorker bool) error {
386386
logrus.Debugf("saving token to disk")
387387
if err := saveTokenToDisk(jcmd.K0sToken); err != nil {
388388
return fmt.Errorf("unable to save token to disk: %w", err)
389389
}
390390

391-
logrus.Debugf("installing %s binaries", name)
391+
logrus.Debugf("installing %s binaries", appSlug)
392392
if err := installK0sBinary(rc); err != nil {
393393
return fmt.Errorf("unable to install k0s binary: %w", err)
394394
}
@@ -424,7 +424,7 @@ func installAndJoinCluster(ctx context.Context, rc runtimeconfig.RuntimeConfig,
424424
return fmt.Errorf("unable to join node to cluster: %w", err)
425425
}
426426

427-
if err := startAndWaitForK0s(name); err != nil {
427+
if err := startAndWaitForK0s(appSlug); err != nil {
428428
return err
429429
}
430430

@@ -495,8 +495,8 @@ func applyNetworkConfiguration(rc runtimeconfig.RuntimeConfig, jcmd *join.JoinCo
495495
}
496496

497497
// startAndWaitForK0s starts the k0s service and waits for the node to be ready.
498-
func startAndWaitForK0s(name string) error {
499-
logrus.Debugf("starting %s service", name)
498+
func startAndWaitForK0s(appSlug string) error {
499+
logrus.Debugf("starting %s service", appSlug)
500500
if _, err := helpers.RunCommand(runtimeconfig.K0sBinaryPath, "start"); err != nil {
501501
return fmt.Errorf("unable to start service: %w", err)
502502
}

cmd/installer/cli/join_printcommand.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ import (
1212
"github.com/spf13/cobra"
1313
)
1414

15-
func JoinPrintCommandCmd(ctx context.Context, name string) *cobra.Command {
15+
func JoinPrintCommandCmd(ctx context.Context, appTitle string) *cobra.Command {
1616
var rc runtimeconfig.RuntimeConfig
1717

1818
cmd := &cobra.Command{
1919
Use: "print-command",
20-
Short: fmt.Sprintf("Print controller join command for %s", name),
20+
Short: fmt.Sprintf("Print controller join command for %s", appTitle),
2121
PreRunE: func(cmd *cobra.Command, args []string) error {
2222
// Skip root check if dryrun mode is enabled
2323
if !dryrun.Enabled() && os.Getuid() != 0 {

0 commit comments

Comments
 (0)