Skip to content
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

Add SetNoWhiteSpace and SetTablePadding options to have more kubectl like output #144

Merged
merged 6 commits into from
Nov 5, 2019

Conversation

shreddedbacon
Copy link
Contributor

@shreddedbacon shreddedbacon commented Nov 3, 2019

Description

This adds the ability to output table data much more like kubectl by removing the white space at the start of rows. It also introduces a padding option so you can choose either spaces or tab as the padding between columns

An example has been added to the README, but is posted here for visibility

A test has also been written

Example

ExampleSet KubeFormat option

data := [][]string{
    {"node1.example.com", "Ready", "compute", "1.11"},
    {"node2.example.com", "Ready", "compute", "1.11"},
    {"node3.example.com", "Ready", "compute", "1.11"},
    {"node4.example.com", "NotReady", "compute", "1.11"},
}

table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"Name", "Status", "Role", "Version"})
table.SetAutoWrapText(false)
table.SetAutoFormatHeaders(true)
table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
table.SetAlignment(tablewriter.ALIGN_LEFT)
table.SetCenterSeparator("")
table.SetColumnSeparator("")
table.SetRowSeparator("")
table.SetHeaderLine(false)
table.SetBorder(false)
table.SetTablePadding("\t") // pad with tabs
table.SetNoWhiteSpace(true)
table.AppendBulk(data) // Add Bulk Data
table.Render()
Output
NAME             	STATUS  	ROLE   	VERSION 
node1.example.com	Ready   	compute	1.11   	
node2.example.com	Ready   	compute	1.11   	
node3.example.com	Ready   	compute	1.11   	
node4.example.com	NotReady	compute	1.11   	

Closes

This PR should close #129

@shreddedbacon
Copy link
Contributor Author

@olekukonko @mattn can you please review.
All tests passed

@shreddedbacon shreddedbacon changed the title Kube format Add SetKubeFormat and SetKubePadding options to have more kubectl like output Nov 3, 2019
@woodcockjosh
Copy link

@shreddedbacon looks good. do we need to make this kubernetes specific? Can we just keep it generic with something like "table padding" option?

@shreddedbacon
Copy link
Contributor Author

I guess it doesn't have to be kube specific, but all the requests for this sort of feature were to be more kubectl like, which was also what I was after.

Happy to rename it to something else if you have an idea, these are the two options added, and they sort of need to work together. You can't really use it outside of what is in the example I posted.

table.SetKubePadding()
table.SetKubeFormat()

Ideas for renaming?

@woodcockjosh
Copy link

Yeah I also want for the same reason but this library shouldn't be concerned with specific use cases in that it has knowledge of them, rather it should implement capabilities that enable them.

I think
table.SetTablePadding("") will get us all what we need. The other formatting like left align, etc can be achieved with existing methods.

@shreddedbacon shreddedbacon changed the title Add SetKubeFormat and SetKubePadding options to have more kubectl like output Add SetNoWhiteSpace and SetTablePadding options to have more kubectl like output Nov 4, 2019
@shreddedbacon
Copy link
Contributor Author

Sweet, thanks @woodcockjosh I've made adjustments like suggested.
How does it look now?

@mattn
Copy link
Collaborator

mattn commented Nov 5, 2019

Looks good. @woodcockjosh thought?

@woodcockjosh
Copy link

Looks great!

@mattn mattn merged commit b2a28af into olekukonko:master Nov 5, 2019
@mattn
Copy link
Collaborator

mattn commented Nov 5, 2019

Thank you

@woodcockjosh
Copy link

When release?

@shreddedbacon
Copy link
Contributor Author

🎉 Awesome, thank you!

@mattn
Copy link
Collaborator

mattn commented Nov 6, 2019

I'll tag soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[How] No left padding on row start
3 participants