feat(cmd): add version cmd

This commit is contained in:
iyear 2022-09-01 15:18:33 +08:00
parent 46fa6f390d
commit c566d0d853
4 changed files with 70 additions and 1 deletions

View file

@ -3,6 +3,7 @@ package cmd
import (
"github.com/fatih/color"
"github.com/iyear/tdl/cmd/login"
"github.com/iyear/tdl/cmd/version"
"github.com/iyear/tdl/pkg/consts"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
@ -19,7 +20,7 @@ var cmd = &cobra.Command{
}
func init() {
cmd.AddCommand(login.Cmd)
cmd.AddCommand(version.Cmd, login.Cmd)
cmd.PersistentFlags().String("proxy", "", "")
cmd.PersistentFlags().StringP("ns", "n", "", "namespace")

32
cmd/version/version.go Normal file
View file

@ -0,0 +1,32 @@
package version
import (
"bytes"
_ "embed"
"github.com/fatih/color"
"github.com/iyear/tdl/global"
"github.com/spf13/cobra"
"runtime"
"text/template"
)
//go:embed version.tmpl
var version string
var Cmd = &cobra.Command{
Use: "version",
Short: "Check the version info",
Example: "tdl version",
Run: func(cmd *cobra.Command, args []string) {
buf := &bytes.Buffer{}
_ = template.Must(template.New("version").Parse(version)).Execute(buf, map[string]interface{}{
"Version": global.Version,
"Commit": global.Commit,
"Date": global.CommitDate,
"GoVersion": runtime.Version(),
"GOOS": runtime.GOOS,
"GOARCH": runtime.GOARCH,
})
color.Blue(buf.String())
},
}

5
cmd/version/version.tmpl Normal file
View file

@ -0,0 +1,5 @@
Version: {{ .Version }}
Commit: {{ .Commit }}
Date: {{ .Date }}
{{ .GoVersion }} {{ .GOOS }}/{{ .GOARCH }}

View file

@ -0,0 +1,31 @@
## tdl version
Check the version info
```
tdl version [flags]
```
### Examples
```
tdl version
```
### Options
```
-h, --help help for version
```
### Options inherited from parent commands
```
-n, --ns string namespace
--proxy string
```
### SEE ALSO
* [tdl](tdl.md) - Telegram downloader, but not only a downloader