Print banner when vaultik is invoked with no subcommand
Cobra's default 'no subcommand → print help' path bypasses fx, so the startup banner never ran for bare 'vaultik'. Add a Run handler on the root command that prints the banner and then calls Help. Extracted the banner-printing logic into writeStartupBanner() so both this path and the fx setupGlobals hook share one implementation.
This commit is contained in:
@@ -46,18 +46,25 @@ func setupGlobals(lc fx.Lifecycle, g *globals.Globals, v *vaultik.Vaultik, opts
|
||||
// user-facing output is suppressed.
|
||||
v.UI = ui.NewWithColor(io.Discard, false)
|
||||
} else {
|
||||
v.UI.Banner("%s %s by %s (commit %s, built on %s) starting up at %s.",
|
||||
g.Appname, g.Version, globals.Author,
|
||||
g.ShortCommit(), g.CommitDate,
|
||||
g.StartTime.Format(time.RFC3339))
|
||||
v.UI.Banner("%s", globals.Homepage)
|
||||
v.UI.Banner("")
|
||||
writeStartupBanner(v.UI, g.StartTime, g.ShortCommit())
|
||||
}
|
||||
return nil
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// writeStartupBanner prints the two-line application banner followed by a
|
||||
// blank line. Used both from the fx hook (for subcommand invocations) and
|
||||
// from the root cobra Run handler (for `vaultik` with no subcommand).
|
||||
func writeStartupBanner(w *ui.Writer, startTime time.Time, shortCommit string) {
|
||||
w.Banner("%s %s by %s (commit %s, built on %s) starting up at %s.",
|
||||
globals.Appname, globals.Version, globals.Author,
|
||||
shortCommit, globals.CommitDate,
|
||||
startTime.Format(time.RFC3339))
|
||||
w.Banner("%s", globals.Homepage)
|
||||
w.Banner("")
|
||||
}
|
||||
|
||||
// NewApp creates a new fx application with common modules.
|
||||
// It sets up the base modules (config, database, logging, globals) and
|
||||
// combines them with any additional modules specified in the options.
|
||||
|
||||
Reference in New Issue
Block a user