Skip to content

A command-line tool for generating and managing tables.

License

Notifications You must be signed in to change notification settings

aziontech/tablecli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tablecli

License: MIT GoDoc Go Report Card

This package provides a convenient way to generate tabular output of any data, which is useful primarily for CLI tools.

Girl in a jacket

Install Package

go get github.com/aziontech/tablecli

Example of use:

package main

import (
    table "github.com/aziontech/tablecli"
    "github.com/fatih/color"
    "strings"
)


type list struct {
    ID string 
    Name string
}

func main() {
    tbl := table.New("ID", "NAME")
    headerFmt := color.New(color.FgBlue, color.Underline).SprintfFunc()
    columnFmt := color.New(color.FgGreen).SprintfFunc()
    tbl.WithHeaderFormatter(headerFmt).WithFirstColumnFormatter(columnFmt)

    var list = []list{
        { "123123", "Jonh"},
        { "123121", "Jeff"},
    }

    for _, i := range list {
	tbl.AddRow(i.ID, i.Name)
    }

    format := strings.Repeat("%s", len(tbl.GetHeader())) + "\n"
    tbl.CalculateWidths([]string{})

    tbl.PrintHeader(format)
	for _, r := range tbl.GetRows() {
	    tbl.PrintRow(format, r)
    }
}

Output:

ID      NAME  
123123  Jonh  
123121  Jeff 

License

This project is licensed under the terms of the MIT license.

About

A command-line tool for generating and managing tables.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages