Skip to content
This repository has been archived by the owner on May 6, 2022. It is now read-only.

Make the last col of get-classes and get-plans wider so we're at least 80 cols #2226

Merged
merged 2 commits into from
Aug 1, 2018

Conversation

duglin
Copy link
Contributor

@duglin duglin commented Jul 23, 2018

Signed-off-by: Doug Davis dug@us.ibm.com

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 23, 2018
@@ -32,16 +32,29 @@ func getClassStatusText(status v1beta1.ClusterServiceClassStatus) string {

func writeClassListTable(w io.Writer, classes []v1beta1.ClusterServiceClass) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like there's a table writing library we ought to be using.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there is and we're using it. It just doesn't support this feature

@duglin duglin force-pushed the widerSvcat branch 2 times, most recently from 8fc428f to 9e70431 Compare July 23, 2018 16:28
@duglin
Copy link
Contributor Author

duglin commented Jul 24, 2018

ping @carolynvs @jberkhahn

@duglin duglin force-pushed the widerSvcat branch 2 times, most recently from 5223376 to 32e637c Compare July 24, 2018 15:18
Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

I'm not terribly excited about this as a solution for the description column being too narrow. A couple things that I'd prefer to see:

  • Modify NewListTable() so that all tables follow this formatting, instead of having to do it one-off for each table.
  • Provide a function that helps to compute the appropriate size for the last column.
  • Understand what this will look like for tables that don't have long last columns. Maybe show an example of this for a broker that doesn't do long descriptions and another that does? Just so we can see what the final result will look like for different use cases.

@duglin
Copy link
Contributor Author

duglin commented Jul 24, 2018

I thought about how to do some of that stuff. The problem is that if we try to do it "the right way" it'll involve major changes - like creating a proxy structure for each table to track the width of each column as things are appended and calling the proxy for all table ops instead of the real TableWriter. I can take a stab at that but be prepared for a much larger PR with far more impactful changes. I tried to keep things to a minimum with this.

@jberkhahn
Copy link
Contributor

I'm not so sure about implementing it that way. Who says every single table we write is going to want an extra large last column? How do we know the last column is always going to be the large one? I think implementing it specifically for the output types that actually need large columns seems fine.

@duglin
Copy link
Contributor Author

duglin commented Jul 24, 2018

If I did the "right (generic) solution" I was going to make it so that people could tell us which column is the variable/wide one. However, before I head down that path and create a much bigger PR I'd like agreement that we really want the bigger PR and not this more focused one. I'll let you two decide - I can go either way.

@carolynvs
Copy link
Contributor

carolynvs commented Jul 24, 2018

NewListTable is intended to be used for the output of svcat get commands, which is why I suggested it. Not all tables are impacted.

Mostly my objection is that I wouldn't want to ever modify/maintain the code added as it looks right now. It's confusing and I'm hoping that there is a middle ground where at the every least the output functions that want to opt in can do so in a way is consistent and doesn't overwhelm the Write* functions with the logic just to format the width...

Honestly I would rather leave it as-is than what's in here. 🤷‍♀️

@duglin
Copy link
Contributor Author

duglin commented Jul 24, 2018

This new output: https://github.com/kubernetes-incubator/service-catalog/pull/2226/files#diff-345f1d72c94dd1c75d5bf43421aa41e2L1 shows why I really want something like this. The old format made us looks silly.

@jberkhahn
Copy link
Contributor

Ah, ok. I think the best solution then would be to write some function that figures this out in a generic manner, and then call out to it from writeClassListTable and writePlanListTable

@MHBauer
Copy link
Contributor

MHBauer commented Jul 24, 2018

I don't see anything convincing in #2226 (comment) . Looks fine to me both before and after. I like the consistency of after and the compactness of before

This needs a test and example with some long lines.

…t 80 cols

Signed-off-by: Doug Davis <dug@us.ibm.com>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jul 24, 2018
Copy link
Contributor

@MHBauer MHBauer left a comment

Choose a reason for hiding this comment

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

typos

const DEFAULT_PAGE_WIDTH = 80

// ListTable is a proxy for tablewriter.Table so we can support variable a
// width column that tries to full up extract space.
Copy link
Contributor

Choose a reason for hiding this comment

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

full -> fill
extract -> exact
I think

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yup fixed

@duglin duglin force-pushed the widerSvcat branch 3 times, most recently from cd1940b to 193c22e Compare July 25, 2018 01:41
@duglin
Copy link
Contributor Author

duglin commented Jul 25, 2018

@carolynvs see if you like this version better. If so, I'll squash to kill-off the first variant.

Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

This is exactly what I was hoping for! Just one small change, I think that we can cut down on those middleman methods.

t.SetHeader([]string{
"Name",
"Namespace",
"Description",
})
t.SetVariableColumn(3)
Copy link
Contributor

Choose a reason for hiding this comment

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

❤️ Thanks, this is exactly what I was hoping for!

@@ -22,12 +22,124 @@ import (
"github.com/olekukonko/tablewriter"
)

// DefaultPageWidth is the page (screen) width to use when we need to twiddle
Copy link
Contributor

Choose a reason for hiding this comment

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

I am pro "twiddling" 👍

// value of our special column first, call SetColMinWidth and then add the
// headers/rows.
type ListTable struct {
table *tablewriter.Table
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make table an embedded field field instead of a named field, i.e. change this line to *tablewriter.Table without the name, then you don't need to implement the passthrough functions, like SetBorder.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

thought about that, but I'm not sure how to do super.Append() when I have my own Append() because I need to override it.

@duglin duglin force-pushed the widerSvcat branch 2 times, most recently from 53becd4 to c22d950 Compare July 26, 2018 00:22
@carolynvs
Copy link
Contributor

@duglin I pushed a commit to your branch that shows what I was suggesting.

@@ -37,26 +37,19 @@ const DefaultPageWidth = 80
// value of our special column first, call SetColMinWidth and then add the
// headers/rows.
type ListTable struct {
table *tablewriter.Table
*tablewriter.Table
Copy link
Contributor Author

@duglin duglin Jul 26, 2018

Choose a reason for hiding this comment

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

Interesting, I forgot you could ref it by "Table" later on like that. This is why I still feel like such a newbie w.r.t. golang - thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Using embedded fields to satisfy an interface is a really nice feature! 👍

Sorry about pushing to your fork! Next time I send a gist or patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries, just a "you dunce, just refer it to by Table" would have gotten the point across ;-)

Copy link
Contributor

@carolynvs carolynvs left a comment

Choose a reason for hiding this comment

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

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Jul 26, 2018
@jeremyrickard
Copy link
Contributor

Looks like you fixed Morgan's comment, LGTM.

@@ -22,12 +22,118 @@ import (
"github.com/olekukonko/tablewriter"
)

// DefaultPageWidth is the page (screen) width to use when we need to twiddle
// the width of some table columns for better viewing. For now assume its only
Copy link
Contributor

Choose a reason for hiding this comment

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

its -> it's

lt.Table.SetHeader(keys)
}

// Append will look at each column in the row to see if its longer than any
Copy link
Contributor

Choose a reason for hiding this comment

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

its -> it's
or
it is

@k8s-ci-robot k8s-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2018

// If this column doesn't push us past the page width then just
// set it to the max cell width so Render() doesn't chop it on us.
// Otherwise, chop it so we don't go page the page width.
Copy link
Contributor

Choose a reason for hiding this comment

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

past the page width

Signed-off-by: Doug Davis <dug@us.ibm.com>
@MHBauer
Copy link
Contributor

MHBauer commented Aug 1, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 1, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: MHBauer

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 1, 2018
@MHBauer MHBauer dismissed their stale review August 1, 2018 18:49

typos addressed

@k8s-ci-robot k8s-ci-robot merged commit ac6df03 into kubernetes-retired:master Aug 1, 2018
@duglin duglin deleted the widerSvcat branch August 2, 2018 20:08
@MHBauer MHBauer mentioned this pull request Aug 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm Indicates that a PR is ready to be merged. LGTM1 LGTM2 size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants