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:
2026-06-17 05:54:48 +02:00
parent 706284d590
commit 3113014b58
2 changed files with 28 additions and 6 deletions

View File

@@ -5,9 +5,12 @@ import (
"os"
"path/filepath"
"strings"
"time"
"github.com/adrg/xdg"
"github.com/spf13/cobra"
"sneak.berlin/go/vaultik/internal/globals"
"sneak.berlin/go/vaultik/internal/ui"
)
// RootFlags holds global flags that apply to all commands.
@@ -32,6 +35,18 @@ func NewRootCommand() *cobra.Command {
public keys and uploads to S3-compatible storage. No private keys are needed
on the source system.`,
SilenceUsage: true,
// When invoked with no subcommand, print the banner then the
// usage/help. Cobra's default behavior (without a Run) just
// prints help, which skips the banner.
Run: func(cmd *cobra.Command, args []string) {
startTime := time.Now().UTC()
short := globals.Commit
if len(short) > 12 {
short = short[:12]
}
writeStartupBanner(ui.New(os.Stdout), startTime, short)
_ = cmd.Help()
},
}
// Add global flags