refactor: store version in constants

This commit is contained in:
Stavros
2025-05-20 16:39:27 +03:00
parent 415eea6fab
commit 91e3bbc9d9
9 changed files with 122 additions and 56 deletions

View File

@@ -8,8 +8,8 @@ import (
totpCmd "tinyauth/cmd/totp"
userCmd "tinyauth/cmd/user"
"tinyauth/internal/api"
"tinyauth/internal/assets"
"tinyauth/internal/auth"
"tinyauth/internal/constants"
"tinyauth/internal/docker"
"tinyauth/internal/handlers"
"tinyauth/internal/hooks"
@@ -50,7 +50,7 @@ var rootCmd = &cobra.Command{
// Logger
log.Logger = log.Level(zerolog.Level(config.LogLevel))
log.Info().Str("version", strings.TrimSpace(assets.Version)).Msg("Starting tinyauth")
log.Info().Str("version", strings.TrimSpace(constants.Version)).Msg("Starting tinyauth")
// Users
log.Info().Msg("Parsing users")

24
cmd/version.go Normal file
View File

@@ -0,0 +1,24 @@
package cmd
import (
"fmt"
"tinyauth/internal/constants"
"github.com/spf13/cobra"
)
// Create the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of Tinyauth",
Long: `All software has versions. This is Tinyauth's`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Printf("Version: %s\n", constants.Version)
fmt.Printf("Commit Hash: %s\n", constants.CommitHash)
fmt.Printf("Build Timestamp: %s\n", constants.BuildTimestamp)
},
}
func init() {
rootCmd.AddCommand(versionCmd)
}