Merge fix/banner-always-shown
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.
|
// user-facing output is suppressed.
|
||||||
v.UI = ui.NewWithColor(io.Discard, false)
|
v.UI = ui.NewWithColor(io.Discard, false)
|
||||||
} else {
|
} else {
|
||||||
v.UI.Banner("%s %s by %s (commit %s, built on %s) starting up at %s.",
|
writeStartupBanner(v.UI, g.StartTime, g.ShortCommit())
|
||||||
g.Appname, g.Version, globals.Author,
|
|
||||||
g.ShortCommit(), g.CommitDate,
|
|
||||||
g.StartTime.Format(time.RFC3339))
|
|
||||||
v.UI.Banner("%s", globals.Homepage)
|
|
||||||
v.UI.Banner("")
|
|
||||||
}
|
}
|
||||||
return nil
|
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.
|
// NewApp creates a new fx application with common modules.
|
||||||
// It sets up the base modules (config, database, logging, globals) and
|
// It sets up the base modules (config, database, logging, globals) and
|
||||||
// combines them with any additional modules specified in the options.
|
// combines them with any additional modules specified in the options.
|
||||||
|
|||||||
@@ -5,9 +5,12 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/adrg/xdg"
|
"github.com/adrg/xdg"
|
||||||
"github.com/spf13/cobra"
|
"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.
|
// 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
|
public keys and uploads to S3-compatible storage. No private keys are needed
|
||||||
on the source system.`,
|
on the source system.`,
|
||||||
SilenceUsage: true,
|
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
|
// Add global flags
|
||||||
|
|||||||
Reference in New Issue
Block a user