Skip to content

Solves the issue #7749 - #7753

Merged
mattfarina merged 4 commits into
helm:masterfrom
anshulvermapatel:helm/7749/helm_list_short_listing_format
Mar 24, 2020
Merged

mattfarina merged 4 commits into
helm:masterfrom
anshulvermapatel:helm/7749/helm_list_short_listing_format

Conversation

@anshulvermapatel

Copy link
Copy Markdown
Contributor

Resolves the issue where proper formatting was not being done if short(-q) option was used with other formatting options like json, yaml.
@mattfarina , Can you please review this.

Please do let me know if any change is required.
Thank You very much.

@helm-bot helm-bot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Mar 9, 2020
Anshul Verma added 3 commits March 10, 2020 03:44
…short(-q) option was used with other formating options like json, yaml

Signed-off-by: Anshul Verma <[email protected]>
…short(-q) option was used with other formating options like json, yaml

Signed-off-by: Anshul Verma <[email protected]>
…short(-q) option was used with other formating options like json, yaml

Signed-off-by: Anshul Verma <[email protected]>
@mattfarina mattfarina added the bug Categorizes issue or PR as related to a bug. label Mar 10, 2020
@mattfarina
mattfarina self-requested a review March 10, 2020 13:26

@mattfarina mattfarina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks for working on this. I found an issue in the code block and I think the design can use a little improvement to clean up the issue and duplicate code. See below...

Comment thread cmd/helm/list.go
Comment on lines +93 to 109
outputFlag := cmd.Flag("output")
if outputFlag.Changed {
switch outputFlag.Value.String() {
case "json":
output.EncodeJSON(out, names)
return nil
case "yaml":
output.EncodeYAML(out, names)
return nil
default:
return outfmt.Write(out, newReleaseListWriter(results))
}
}

for _, res := range results {
fmt.Fprintln(out, res.Name)
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If I use helm list --short the default value for the output is used of table. This shows a different result from the use of helm list --short --output table which is currently showing the same result as if it were not short.

I would suggest a few changes to this block...

  1. Remove the if outputFlag.Changed { block. This section can format for all the types including the default.
  2. Add a case for table (the default) and have its contents be the for loop currently listed after the if changed block.
  3. Change the default case (not a known output format) to return an error of fmt.Errorf("Unknown output format \"%s\"", outputFlag.Value.String()). This is based on what's in Helm v2.

This would make the case statement handle all short forms in all cases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If I use helm list --short the default value for the output is used of table. This shows a different result from the use of helm list --short --output table which is currently showing the same result as if it were not short.

Actually, I deployed Helm 2 and saw that there was no output format as table in helm.

$ ./helm version
Client: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"}
Server: &version.Version{SemVer:"v2.16.3", GitCommit:"1ee0254c86d4ed6887327dabed7aa7da29d7eb0d", GitTreeState:"clean"
$ ./helm list --short --output table
Error: Unknown output format "table

Hence thought that if the output is table then it should be the table, but ya you are right, if default format is table then helm list --short --output table should also be the same as the output of helm list --short.

I will make the changes as given in your 1st and 2nd point.
Regarding the 3rd point. What I think is that in the default case of the switch if we return outfmt.Write(out, newReleaseListWriter(results)) the if will throw the normal Helm 3 error message of bad format.

╭─ansverma@localhost ~/contribution/helm/7749/helm2/helm ‹helm/7749/helm_list_short_listing_format*›
╰─$ bin/helm list --short --output table
mysql
yoursql
╭─ansverma@localhost ~/contribution/helm/7749/helm2/helm ‹helm/7749/helm_list_short_listing_format*›
╰─$ bin/helm list --short --output json
["mysql","yoursql"]
╭─ansverma@localhost ~/contribution/helm/7749/helm2/helm ‹helm/7749/helm_list_short_listing_format*›
╰─$ bin/helm list --short --output yaml
- mysql
- yoursql
╭─ansverma@localhost ~/contribution/helm/7749/helm2/helm ‹helm/7749/helm_list_short_listing_format*›
╰─$ bin/helm list --short --output asdflkj
Error: invalid argument "asdflkj" for "-o, --output" flag: invalid format type

I think, the error message Error: invalid argument "asdflkj" for "-o, --output" flag: invalid format type is better than the one in Helm 2.
I am currently making the changes. Please let me know if you want to have that particular error message which you mentioned anyways, I will do that.

…short(-q) option was used with other formating options like json, yaml

Signed-off-by: Anshul Verma <[email protected]>
@anshulvermapatel

Copy link
Copy Markdown
Contributor Author

@mattfarina any update?

@anshulvermapatel

Copy link
Copy Markdown
Contributor Author

@mattfarina , Hello, Any update on this?

@bacongobbler , Can you please have a look at this?

@bacongobbler

Copy link
Copy Markdown
Member

Thank you for the ping. At this time, I do not have enough time in my work schedule to review your code. I am busy with other work. Sorry!

@anshulvermapatel

Copy link
Copy Markdown
Contributor Author

@bacongobbler , No Problem Matthew.

@mattfarina mattfarina left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

lgtm. thanks for working this out.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants