cmd

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2018 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuildDate = "dev-build"

BuildDate defines the date this build was built

View Source
var ErrUnknownAlignment = fmt.Errorf("unknown alignment")

ErrUnknownAlignment Returned when the passed in alignment character isn't a valid Alignment type.

View Source
var RootCmd = &cobra.Command{
	Use:   "csvtk",
	Short: "A brief description of your application",
	Long: `A longer description that spans multiple lines and likely contains
examples and usage of using your application. For example:

Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
}

RootCmd represents the base command when called without any subcommands

View Source
var Version = "dev-build"

Version defines the version of the tool

Functions

func ConfigTableWriter

func ConfigTableWriter(t *tw.Table, opts RenderOptions)

ConfigTableWriter takes a pointer to a Table and configures it based on the passed in opts

func Execute

func Execute()

Execute adds all child commands to the root command and sets flags appropriately. This is called by main.main(). It only needs to happen once to the rootCmd.

func FromStringArray

func FromStringArray(strs []string, out []Alignment) error

FromStringArray accepts an array of strings and attempts to convert them into an Alignment type. Any error will break the conversion and return an ErrUnknownAlignment

func NewBufWriteCloser

func NewBufWriteCloser(f *os.File, buf *bufio.Writer) io.WriteCloser

NewBufWriteCloser creates a new BufWriteCloser type using f to read from and buf to write to.

func Render

func Render(r *csv.Reader, w io.Writer, opts RenderOptions) error

Render will read from r and write to w using opts to control how the table is rendered. Will return an error if r.Read() fails.

Types

type Alignment

type Alignment string

Alignment An alignment specifies how a header, column, or footer should be aligned while rendering.

const (
	// AlignDefault will align the header, column, or footer in the default manner.
	AlignDefault Alignment = "="
	// AlignCenter will align the header, column, or footer to the center.
	AlignCenter Alignment = "-"
	// AlignLeft will align the header, column, or footer to the left.
	AlignLeft Alignment = "<"
	// AlignRight will align the header, column, or footer to the right.
	AlignRight Alignment = ">"
	// AlignEmpty only used during an error state.
	AlignEmpty Alignment = ""
)

func FromString

func FromString(s string) (Alignment, error)

FromString accepts a string and converts it into an Alignment type. If the alignment is invalid it will return an ErrUnknownAlignment

func (Alignment) ToString

func (a Alignment) ToString() string

ToString will convert the Alignment type into its associated string value.

func (Alignment) ToTableWriter

func (a Alignment) ToTableWriter() int

ToTableWriter will convert the alignment to a TableWriter format

type BufWriteCloser

type BufWriteCloser struct {
	*bufio.Writer
	// contains filtered or unexported fields
}

BufWriteCloser provides a WriteCloser for a bufio.Writer

func (*BufWriteCloser) Close

func (b *BufWriteCloser) Close() error

Close when done with the BufWriteCloser you should call Close() to clean up resources.

type RenderOptions

type RenderOptions struct {
	Align                 Alignment
	AlignColumns          []Alignment
	AlignHeader           Alignment
	AlignFooter           Alignment
	AutoFormattingHeaders bool
	AutoMergeCells        bool
	AutoWrap              bool
	Caption               string
	CenterSeparator       string
	ColumnSeparator       string
	ColWidth              int
	FirstRowAsHeader      bool
	Footer                []string
	Header                []string
	Newline               string
	Reflow                bool
	RowLine               bool
	RowSeparator          string
}

RenderOptions defines the various rendering options available

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL