feat(cli): add --output={text,json} to version cmd (#7010)

* feat(cliui): add TextFormat
* feat(cli): add --format={text,json} to version cmd
This commit is contained in:
Cian Johnston
2023-04-05 13:16:05 +01:00
committed by GitHub
parent 9c4ccd76a0
commit 00d468b964
7 changed files with 192 additions and 33 deletions
+1 -31
View File
@@ -82,7 +82,7 @@ func (r *RootCmd) Core() []*clibase.Cmd {
r.templates(),
r.users(),
r.tokens(),
r.version(),
r.version(defaultVersionInfo),
// Workspace Commands
r.configSSH(),
@@ -370,36 +370,6 @@ func LoggerFromContext(ctx context.Context) (slog.Logger, bool) {
return l, ok
}
// version prints the coder version
func (*RootCmd) version() *clibase.Cmd {
return &clibase.Cmd{
Use: "version",
Short: "Show coder version",
Handler: func(inv *clibase.Invocation) error {
var str strings.Builder
_, _ = str.WriteString("Coder ")
if buildinfo.IsAGPL() {
_, _ = str.WriteString("(AGPL) ")
}
_, _ = str.WriteString(buildinfo.Version())
buildTime, valid := buildinfo.Time()
if valid {
_, _ = str.WriteString(" " + buildTime.Format(time.UnixDate))
}
_, _ = str.WriteString("\r\n" + buildinfo.ExternalURL() + "\r\n\r\n")
if buildinfo.IsSlim() {
_, _ = str.WriteString(fmt.Sprintf("Slim build of Coder, does not support the %s subcommand.\n", cliui.Styles.Code.Render("server")))
} else {
_, _ = str.WriteString(fmt.Sprintf("Full build of Coder, supports the %s subcommand.\n", cliui.Styles.Code.Render("server")))
}
_, _ = fmt.Fprint(inv.Stdout, str.String())
return nil
},
}
}
func isTest() bool {
return flag.Lookup("test.v") != nil
}