Log messages are lower-case event names with their details as key/value
attributes ("error" for errors), in place of formatted strings.
Loggable package take a WithLogger option as part of their "New*" call,
defaulting to slog.Default(). Each tags its lines with its `component`.
Some debug loggers print directly rather than using slog when in
terminal logging mode.
38 lines
951 B
Go
38 lines
951 B
Go
package version
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"git.avsdev.uk/Go/job-search/internal/version"
|
|
)
|
|
|
|
// NewCommand returns the "version" command.
|
|
func NewCommand() *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print version information",
|
|
SilenceUsage: true,
|
|
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
|
slog.Debug("command persistent pre-run", "command", "version")
|
|
},
|
|
PersistentPostRun: func(cmd *cobra.Command, args []string) {
|
|
slog.Debug("command persistent post-run", "command", "version")
|
|
},
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
slog.Debug("command run", "command", "version")
|
|
|
|
fmt.Printf("JobSearch - %s\n", version.Version)
|
|
if version.BuildTime != "unknown" {
|
|
fmt.Printf("Built: %s\n", version.BuildTime)
|
|
}
|
|
if version.GitCommit != "unknown" {
|
|
fmt.Printf("Commit: %s\n", version.GitCommit)
|
|
}
|
|
},
|
|
}
|
|
return cmd
|
|
}
|