@@ -18,7 +18,7 @@ type app struct {
1818 shouldPersist bool
1919}
2020
21- func NewRootCmd () * cobra.Command {
21+ func NewRootCmd (version string ) * cobra.Command {
2222 cfg , err := config .Load ()
2323 if err != nil {
2424 panic (err )
@@ -34,8 +34,9 @@ func NewRootCmd() *cobra.Command {
3434 shouldPersist : ! envOverride ,
3535 }
3636 root := & cobra.Command {
37- Use : "ticktick" ,
38- Short : "TickTick command line client" ,
37+ Use : "ticktick" ,
38+ Short : "TickTick command line client" ,
39+ Version : version ,
3940 PersistentPreRunE : func (cmd * cobra.Command , args []string ) error {
4041 return nil
4142 },
@@ -46,8 +47,16 @@ func NewRootCmd() *cobra.Command {
4647 return config .Save (a .cfg )
4748 },
4849 }
50+ root .SetVersionTemplate ("{{.Version}}\n " )
4951 root .PersistentFlags ().BoolVar (& a .jsonMode , "json" , false , "Output JSON" )
5052
53+ root .AddCommand (& cobra.Command {
54+ Use : "version" ,
55+ Short : "Print version" ,
56+ RunE : func (cmd * cobra.Command , args []string ) error {
57+ return a .print (version )
58+ },
59+ })
5160 root .AddCommand (a .newAuthCmd ())
5261 root .AddCommand (a .newProjectsCmd ())
5362 root .AddCommand (a .newTasksCmd ())
0 commit comments