From 1259fc1bbceaffd094f29fc13ee1e21d0e668750 Mon Sep 17 00:00:00 2001
From: Henrique Dias <hacdias@gmail.com>
Date: Fri, 15 Feb 2019 12:54:44 +0100
Subject: [PATCH] feat: remove version cmd (#675)

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
Former-commit-id: 04a60c58f20d63ca7b25731c41e144bcf0f538cc [formerly e6e179799b64779515051df53352df5e63edc259] [formerly 0689eba81ff5f7ee3ea75db37b91cef4d6d8f35c [formerly 85899acae6edc445506384a5fa2c972131cb06e6]]
Former-commit-id: 96ca0cadb94131ddd3b57f0f11ad629edf687e40 [formerly 50130c75d39e67b15a645e7f4879acf34a5d6620]
Former-commit-id: 53b8120673a82217c3625de161d4ec57a96e1470
---
 cmd/cmds.go    |  9 ++++-----
 cmd/config.go  |  9 ++++-----
 cmd/hash.go    |  9 ++++-----
 cmd/root.go    |  6 ++----
 cmd/rules.go   |  1 -
 cmd/upgrade.go |  5 ++---
 cmd/users.go   |  9 ++++-----
 cmd/version.go | 20 ++++----------------
 8 files changed, 24 insertions(+), 44 deletions(-)

diff --git a/cmd/cmds.go b/cmd/cmds.go
index 81613d02..cf951995 100644
--- a/cmd/cmds.go
+++ b/cmd/cmds.go
@@ -11,11 +11,10 @@ func init() {
 }
 
 var cmdsCmd = &cobra.Command{
-	Use:     "cmds",
-	Version: rootCmd.Version,
-	Short:   "Command runner management utility",
-	Long:    `Command runner management utility.`,
-	Args:    cobra.NoArgs,
+	Use:   "cmds",
+	Short: "Command runner management utility",
+	Long:  `Command runner management utility.`,
+	Args:  cobra.NoArgs,
 }
 
 func printEvents(m map[string][]string) {
diff --git a/cmd/config.go b/cmd/config.go
index 755b7139..db97cf10 100644
--- a/cmd/config.go
+++ b/cmd/config.go
@@ -20,11 +20,10 @@ func init() {
 }
 
 var configCmd = &cobra.Command{
-	Use:     "config",
-	Version: rootCmd.Version,
-	Short:   "Configuration management utility",
-	Long:    `Configuration management utility.`,
-	Args:    cobra.NoArgs,
+	Use:   "config",
+	Short: "Configuration management utility",
+	Long:  `Configuration management utility.`,
+	Args:  cobra.NoArgs,
 }
 
 func addConfigFlags(flags *pflag.FlagSet) {
diff --git a/cmd/hash.go b/cmd/hash.go
index b85144aa..e92203e4 100644
--- a/cmd/hash.go
+++ b/cmd/hash.go
@@ -12,11 +12,10 @@ func init() {
 }
 
 var hashCmd = &cobra.Command{
-	Use:     "hash <password>",
-	Version: rootCmd.Version,
-	Short:   "Hashes a password",
-	Long:    `Hashes a password using bcrypt algorithm.`,
-	Args:    cobra.ExactArgs(1),
+	Use:   "hash <password>",
+	Short: "Hashes a password",
+	Long:  `Hashes a password using bcrypt algorithm.`,
+	Args:  cobra.ExactArgs(1),
 	Run: func(cmd *cobra.Command, args []string) {
 		pwd, err := users.HashPwd(args[0])
 		checkErr(err)
diff --git a/cmd/root.go b/cmd/root.go
index 75b87278..37aad636 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -15,7 +15,6 @@ import (
 	"github.com/filebrowser/filebrowser/v2/settings"
 	"github.com/filebrowser/filebrowser/v2/storage"
 	"github.com/filebrowser/filebrowser/v2/users"
-	"github.com/filebrowser/filebrowser/v2/version"
 	homedir "github.com/mitchellh/go-homedir"
 	"github.com/spf13/cobra"
 	"github.com/spf13/pflag"
@@ -55,9 +54,8 @@ func addServerFlags(flags *pflag.FlagSet) {
 }
 
 var rootCmd = &cobra.Command{
-	Use:     "filebrowser",
-	Version: version.Version,
-	Short:   "A stylish web-based file browser",
+	Use:   "filebrowser",
+	Short: "A stylish web-based file browser",
 	Long: `File Browser CLI lets you create the database to use with File Browser,
 manage your users and all the configurations without acessing the
 web interface.
diff --git a/cmd/rules.go b/cmd/rules.go
index efd23f7f..b7239563 100644
--- a/cmd/rules.go
+++ b/cmd/rules.go
@@ -19,7 +19,6 @@ func init() {
 
 var rulesCmd = &cobra.Command{
 	Use:     "rules",
-	Version: rootCmd.Version,
 	Short:   "Rules management utility",
 	Long: `On each subcommand you'll have available at least two flags:
 "username" and "id". You must either set only one of them
diff --git a/cmd/upgrade.go b/cmd/upgrade.go
index d46d4fe9..18f39ca1 100644
--- a/cmd/upgrade.go
+++ b/cmd/upgrade.go
@@ -14,9 +14,8 @@ func init() {
 }
 
 var upgradeCmd = &cobra.Command{
-	Use:     "upgrade",
-	Version: rootCmd.Version,
-	Short:   "Upgrades an old configuration",
+	Use:   "upgrade",
+	Short: "Upgrades an old configuration",
 	Long: `Upgrades an old configuration. This command DOES NOT
 import share links because they are incompatible with
 this version.`,
diff --git a/cmd/users.go b/cmd/users.go
index b7ec4a8e..74c1c185 100644
--- a/cmd/users.go
+++ b/cmd/users.go
@@ -18,11 +18,10 @@ func init() {
 }
 
 var usersCmd = &cobra.Command{
-	Use:     "users",
-	Version: rootCmd.Version,
-	Short:   "Users management utility",
-	Long:    `Users management utility.`,
-	Args:    cobra.NoArgs,
+	Use:   "users",
+	Short: "Users management utility",
+	Long:  `Users management utility.`,
+	Args:  cobra.NoArgs,
 }
 
 func printUsers(users []*users.User) {
diff --git a/cmd/version.go b/cmd/version.go
index 61f5b4b4..b23b928f 100644
--- a/cmd/version.go
+++ b/cmd/version.go
@@ -1,32 +1,20 @@
 package cmd
 
 import (
-	"text/template"
+	"fmt"
 
+	"github.com/filebrowser/filebrowser/v2/version"
 	"github.com/spf13/cobra"
 )
 
 func init() {
 	rootCmd.AddCommand(versionCmd)
-	cmdsCmd.AddCommand(versionCmd)
-	configCmd.AddCommand(versionCmd)
-	hashCmd.AddCommand(versionCmd)
-	upgradeCmd.AddCommand(versionCmd)
-	rulesCmd.AddCommand(versionCmd)
-	usersCmd.AddCommand(versionCmd)
 }
 
 var versionCmd = &cobra.Command{
 	Use:   "version",
-	Short: "Print the version number of File Browser",
-	Long:  `All software has versions. This is File Browser's`,
+	Short: "Print the version number",
 	Run: func(cmd *cobra.Command, args []string) {
-		// https://github.com/spf13/cobra/issues/724
-		t := template.New("version")
-		template.Must(t.Parse(rootCmd.VersionTemplate()))
-		err := t.Execute(rootCmd.OutOrStdout(), rootCmd)
-		if err != nil {
-			rootCmd.Println(err)
-		}
+		fmt.Println("File Browser Version " + version.Version)
 	},
 }