feat: nfctl(add version)

This commit is contained in:
loveuer
2024-12-26 19:51:31 -08:00
parent ad6b4fe7b6
commit 8235631d4f
6 changed files with 46 additions and 1 deletions

View File

@ -1,6 +1,8 @@
package cmd
import (
"os"
"github.com/loveuer/nf/nft/log"
"github.com/loveuer/nf/nft/nfctl/internal/opt"
"github.com/spf13/cobra"
@ -14,6 +16,11 @@ var rootCmd = &cobra.Command{
log.SetLogLevel(log.LogLevelDebug)
}
if opt.Cfg.Version {
doVersion(cmd, args)
os.Exit(0)
}
if !opt.Cfg.DisableUpdate {
doUpdate(cmd.Context())
}
@ -29,5 +36,6 @@ var rootCmd = &cobra.Command{
func initRoot(cmds ...*cobra.Command) {
rootCmd.PersistentFlags().BoolVar(&opt.Cfg.Debug, "debug", false, "debug mode")
rootCmd.PersistentFlags().BoolVar(&opt.Cfg.DisableUpdate, "disable-update", false, "disable self update")
rootCmd.PersistentFlags().BoolVarP(&opt.Cfg.Version, "version", "v", false, "print nfctl version")
rootCmd.AddCommand(cmds...)
}

View File

@ -0,0 +1,19 @@
package cmd
import (
"fmt"
"github.com/loveuer/nf/nft/nfctl/internal/opt"
"github.com/spf13/cobra"
)
func initVersion() *cobra.Command {
return &cobra.Command{
Use: "version",
Run: doVersion,
}
}
func doVersion(cmd *cobra.Command, args []string) {
fmt.Printf("%s\nnfctl: %s\n\n", opt.Banner, opt.Version)
}

View File

@ -9,6 +9,7 @@ import (
func Init() {
initRoot(
initVersion(),
initUpdate(),
initNew(),
)