@@ -53,7 +53,6 @@ func init() {
53
53
func Root () * cobra.Command {
54
54
cmd := & cobra.Command {
55
55
Use : "coder" ,
56
- Version : buildinfo .Version (),
57
56
SilenceErrors : true ,
58
57
SilenceUsage : true ,
59
58
Long : `Coder — A tool for provisioning self-hosted development environments.
@@ -90,10 +89,10 @@ func Root() *cobra.Command {
90
89
users (),
91
90
portForward (),
92
91
workspaceAgent (),
92
+ versionCmd (),
93
93
)
94
94
95
95
cmd .SetUsageTemplate (usageTemplate ())
96
- cmd .SetVersionTemplate (versionTemplate ())
97
96
98
97
cmd .PersistentFlags ().String (varURL , "" , "Specify the URL to your deployment." )
99
98
cmd .PersistentFlags ().String (varToken , "" , "Specify an authentication token." )
@@ -110,6 +109,27 @@ func Root() *cobra.Command {
110
109
return cmd
111
110
}
112
111
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
+
113
133
// createClient returns a new client from the command context.
114
134
// It reads from global configuration files if flags are not set.
115
135
func createClient (cmd * cobra.Command ) (* codersdk.Client , error ) {
@@ -286,17 +306,6 @@ Use "{{.CommandPath}} [command] --help" for more information about a command.
286
306
{{end}}`
287
307
}
288
308
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
-
300
309
// FormatCobraError colorizes and adds "--help" docs to cobra commands.
301
310
func FormatCobraError (err error , cmd * cobra.Command ) string {
302
311
helpErrMsg := fmt .Sprintf ("Run '%s --help' for usage." , cmd .CommandPath ())
0 commit comments