Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 5, 2023
Merged

Conversation

johnstcn
Copy link
Member

@johnstcn johnstcn commented Apr 5, 2023

$ build/coder-slim_$(./scripts/version.sh)_linux_amd64 version --output=text
Coder v0.21.3-devel+b099e5c58 Wed Apr  5 12:03:29 UTC 2023
https://github.com/coder/coder/commit/b099e5c58c9f8dbb2fbbded3d559da7923cab3f8

Slim build of Coder, does not support the  server  subcommand.
$ build/coder-slim_$(./scripts/version.sh)_linux_amd64 version --output=json
{
  "version": "v0.21.3-devel+b099e5c58",
  "build_time": "2023-04-05T12:03:29Z",
  "external_url": "https://github.com/coder/coder/commit/b099e5c58c9f8dbb2fbbded3d559da7923cab3f8",
  "slim": true,
  "agpl": false
}

@johnstcn johnstcn self-assigned this Apr 5, 2023
@johnstcn johnstcn marked this pull request as ready for review April 5, 2023 10:57
@johnstcn johnstcn requested review from mafredri and mtojek April 5, 2023 10:57
Copy link
Member

@mtojek mtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit-picks can be ignored

err := inv.WithContext(ctx).Run()
require.NoError(t, err)
actual := buf.String()
actual = strings.Replace(actual, "\r\n", "\n", -1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: ReplaceAll?

cli/version.go Outdated
// version prints the coder version
func (*RootCmd) version() *clibase.Cmd {
handleHuman := func(inv *clibase.Invocation) error {
var str strings.Builder
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do you need a string builder if there is no way to break execution in the middle of processing?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, but this is just the previous code I copy-pasta'ed.

@mafredri
Copy link
Member

mafredri commented Apr 5, 2023

Hmm, should we call the flag output/format to align with table formatter and potentially support other formats in the future?

@johnstcn
Copy link
Member Author

johnstcn commented Apr 5, 2023

Hmm, should we call the flag output/format to align with table formatter and potentially support other formats in the future?

Good point, we should have a consistent naming (although the current format is decidedly un-tabular)

@mafredri
Copy link
Member

mafredri commented Apr 5, 2023

Good point, we should have a consistent naming (although the current format is decidedly un-tabular)

Yeah, using a clibase enum with only json seems sufficient here, only allowing -{o,-output} json (or maybe json and text, default being text). But users being able to rely on the --output flag seems like a good idea.

@johnstcn
Copy link
Member Author

johnstcn commented Apr 5, 2023

Good point, we should have a consistent naming (although the current format is decidedly un-tabular)

Yeah, using a clibase enum with only json seems sufficient here, only allowing -{o,-output} json (or maybe json and text, default being text). But users being able to rely on the --output flag seems like a good idea.

Turns out I needed to add a textFormat option to cli/cliui which wasn't too bad. It also forced me to somewhat abstract where we get the version info from, which isn't a bad thing. I haven't figured out how to plumb random version info into the unit tests yet, but that's a good follow-on PR.

@johnstcn johnstcn changed the title feat(cli): add --json output to version cmd feat(cli): add --output={text,json} to version cmd Apr 5, 2023
@johnstcn johnstcn merged commit 00d468b into main Apr 5, 2023
@johnstcn johnstcn deleted the cj/version-json branch April 5, 2023 12:16
@github-actions github-actions bot locked and limited conversation to collaborators Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants