add subcommand version
This commit is contained in:
parent
dd1354eed1
commit
d1ad79fb9d
@ -14,7 +14,7 @@ var cfgFile string
|
|||||||
// rootCmd represents the base command when called without any subcommands
|
// rootCmd represents the base command when called without any subcommands
|
||||||
var rootCmd = &cobra.Command{
|
var rootCmd = &cobra.Command{
|
||||||
Use: "filebrowser",
|
Use: "filebrowser",
|
||||||
Version: "someversion",
|
Version: "(untracked)",
|
||||||
Short: "A stylish web-based file manager",
|
Short: "A stylish web-based file manager",
|
||||||
Long: `File Browser is static binary composed of a golang backend
|
Long: `File Browser is static binary composed of a golang backend
|
||||||
and a Vue.js frontend to create, edit, copy, move, download your files
|
and a Vue.js frontend to create, edit, copy, move, download your files
|
||||||
@ -37,6 +37,7 @@ func Execute() {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cobra.OnInitialize(initConfig)
|
cobra.OnInitialize(initConfig)
|
||||||
|
rootCmd.SetVersionTemplate("File Browser {{printf \"version %s\" .Version}}\n")
|
||||||
|
|
||||||
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.cli.yaml)")
|
rootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file (default is $HOME/.cli.yaml)")
|
||||||
|
|
||||||
|
|||||||
25
cli/cmd/version.go
Normal file
25
cli/cmd/version.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package cmd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"text/template"
|
||||||
|
"github.com/spf13/cobra"
|
||||||
|
)
|
||||||
|
|
||||||
|
var versionCmd = &cobra.Command{
|
||||||
|
Use: "version",
|
||||||
|
Short: "Print the version number of File Browser",
|
||||||
|
Long: `All software has versions. This is File Browser's`,
|
||||||
|
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)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
rootCmd.AddCommand(versionCmd)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user