From 18028c096cfb2f91427fe9c277fd4bf818b3ec1b Mon Sep 17 00:00:00 2001 From: laureanray Date: Thu, 17 Aug 2023 04:07:35 +0800 Subject: [PATCH] add version subcmd --- cmd/root.go | 14 +++++++++++++- main.go | 4 +++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/cmd/root.go b/cmd/root.go index ce495a2..7244949 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -1,11 +1,14 @@ package cmd import ( + "fmt" "os" "github.com/spf13/cobra" ) +var version string + var rootCmd = &cobra.Command{ Use: "clibgen", Short: "Library Genesis command line / terminal client", @@ -14,6 +17,15 @@ Clibgen is a CLI application to search and download epubs, pdfs, from library ge Useful if you are lazy to open up a browser to download e-books/resources.`, } +var versionCmd = &cobra.Command{ + Use: "version", + Short: "Print the version number of Hugo", + Long: `All software has versions. This is Hugo's`, + Run: func(cmd *cobra.Command, args []string) { + fmt.Println(version) + }, +} + func Execute() { err := rootCmd.Execute() if err != nil { @@ -22,5 +34,5 @@ func Execute() { } func init() { - rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") + rootCmd.AddCommand(versionCmd) } diff --git a/main.go b/main.go index 3f71bf5..a98920f 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main -import "github.com/laureanray/clibgen/cmd" +import ( + "github.com/laureanray/clibgen/cmd" +) func main() { cmd.Execute()