From 795a95e573594a461cb57d5ac0b82a12f43a7059 Mon Sep 17 00:00:00 2001 From: Melroy van den Berg Date: Thu, 24 Apr 2025 18:29:42 +0200 Subject: [PATCH] Add version --- cmd/root.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/cmd/root.go b/cmd/root.go index 43106b2..10f6bd2 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -10,14 +10,22 @@ import ( "gitlab.melroy.org/melroy/fediresolve/resolver" ) +const Version = "1.0" + +var versionFlag bool + var rootCmd = &cobra.Command{ Use: "fediresolve [url|handle]", - Short: "Resolve and display Fediverse content", + Short: "Resolve and display Fediverse content (v" + Version + ")", Long: `Fediresolve is a CLI tool that resolves Fediverse URLs and handles. It can parse and display content from Mastodon, Mbin, Lemmy, and other Fediverse platforms. The tool supports both direct URLs to posts/comments/threads and Fediverse handles like @username@server.com.`, Run: func(cmd *cobra.Command, args []string) { + if versionFlag { + fmt.Println("fediresolve version", Version) + os.Exit(0) + } var input string if len(args) > 0 { @@ -45,6 +53,10 @@ The tool supports both direct URLs to posts/comments/threads and Fediverse handl }, } +func init() { + rootCmd.PersistentFlags().BoolVar(&versionFlag, "version", false, "Print the version number and exit") +} + // Execute adds all child commands to the root command and sets flags appropriately. func Execute() error { return rootCmd.Execute()