@@ -53,7 +53,6 @@ func init() {
5353func Root () * cobra.Command {
5454 cmd := & cobra.Command {
5555 Use : "coder" ,
56- Version : buildinfo .Version (),
5756 SilenceErrors : true ,
5857 SilenceUsage : true ,
5958 Long : `Coder — A tool for provisioning self-hosted development environments.
@@ -90,10 +89,10 @@ func Root() *cobra.Command {
9089 users (),
9190 portForward (),
9291 workspaceAgent (),
92+ versionCmd (),
9393 )
9494
9595 cmd .SetUsageTemplate (usageTemplate ())
96- cmd .SetVersionTemplate (versionTemplate ())
9796
9897 cmd .PersistentFlags ().String (varURL , "" , "Specify the URL to your deployment." )
9998 cmd .PersistentFlags ().String (varToken , "" , "Specify an authentication token." )
@@ -110,6 +109,27 @@ func Root() *cobra.Command {
110109 return cmd
111110}
112111
112+ // versionCmd prints the coder version
113+ func versionCmd () * cobra.Command {
114+ return & cobra.Command {
115+ Use : "version" ,
116+ Short : "Show coder version" ,
117+ Example : "coder version" ,
118+ RunE : func (cmd * cobra.Command , args []string ) error {
119+ var str strings.Builder
120+ _ , _ = str .WriteString (fmt .Sprintf ("Coder %s" , buildinfo .Version ()))
121+ buildTime , valid := buildinfo .Time ()
122+ if valid {
123+ _ , _ = str .WriteString (" " + buildTime .Format (time .UnixDate ))
124+ }
125+ _ , _ = str .WriteString ("\r \n " + buildinfo .ExternalURL () + "\r \n " )
126+
127+ _ , _ = fmt .Fprint (cmd .OutOrStdout (), str .String ())
128+ return nil
129+ },
130+ }
131+ }
132+
113133// createClient returns a new client from the command context.
114134// It reads from global configuration files if flags are not set.
115135func createClient (cmd * cobra.Command ) (* codersdk.Client , error ) {
@@ -286,17 +306,6 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.
286306{{end}}`
287307}
288308
289- func versionTemplate () string {
290- template := `Coder {{printf "%s" .Version}}`
291- buildTime , valid := buildinfo .Time ()
292- if valid {
293- template += " " + buildTime .Format (time .UnixDate )
294- }
295- template += "\r \n " + buildinfo .ExternalURL ()
296- template += "\r \n "
297- return template
298- }
299-
300309// FormatCobraError colorizes and adds "--help" docs to cobra commands.
301310func FormatCobraError (err error , cmd * cobra.Command ) string {
302311 helpErrMsg := fmt .Sprintf ("Run '%s --help' for usage." , cmd .CommandPath ())
0 commit comments