mirror of
https://github.com/bit1001/tdl.git
synced 2024-09-20 06:35:54 +08:00
feat(cmd): add version cmd
This commit is contained in:
parent
46fa6f390d
commit
c566d0d853
|
@ -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
32
cmd/version/version.go
Normal 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
5
cmd/version/version.tmpl
Normal file
|
@ -0,0 +1,5 @@
|
|||
Version: {{ .Version }}
|
||||
Commit: {{ .Commit }}
|
||||
Date: {{ .Date }}
|
||||
|
||||
{{ .GoVersion }} {{ .GOOS }}/{{ .GOARCH }}
|
31
docs/command/tdl_version.md
Normal file
31
docs/command/tdl_version.md
Normal 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
|
||||
|
Loading…
Reference in a new issue