vl

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2023 License: MIT Imports: 7 Imported by: 0

README

go-vl

MIT License go-vl CI go-vl report card

go-vl provides vl filter to make CUI table vertical.

Usage

For example, this is output of kubectl get pods.

$ kubectl get pods
NAME                         READY     STATUS    RESTARTS   AGE
hello-web-4017757401-ntgdb   1/1       Running   0          9s
hello-web-4017757401-pc4j9   1/1       Running   0          9s

The vl filter makes it vertical like below.

$ kubectl get pods | vl
********** 1 ********************
    NAME: hello-web-4017757401-ntgdb
   READY: 1/1
  STATUS: Running
RESTARTS: 0
     AGE: 9s
********** 2 ********************
    NAME: hello-web-4017757401-pc4j9
   READY: 1/1
  STATUS: Running
RESTARTS: 0
     AGE: 9s

--grep option works.

$ kubectl get pods | vl --grep pc4j9
********** 1 **********
    NAME: hello-web-4017757401-pc4j9
   READY: 1/1
  STATUS: Running
RESTARTS: 0
     AGE: 9s

And --ps flag to parse lines separated by only 1 space between columns.

$ ps
  PID TTY          TIME CMD
12523 pts/4    00:00:00 bash
30087 pts/4    00:00:00 ps

$ ps | vl --ps
********** 1 **********
 PID: 12523
 TTY: pts/4
TIME: 00:00:00
 CMD: bash
********** 2 **********
 PID: 30087
 TTY: pts/4
TIME: 00:00:00
 CMD: ps

Full Options

$ vl --help
Usage: some-command | vl OPTIONS
Options:
  -g, --grep stringArray   Grep condition to filter lines
  -h, --help               Show help (This message) and exit
  -l, --label string       Show only matching items of labels
      --no-pager           Output without pager
      --ps                 Parse lines separated by one space. i.e. 'ps' command
  -v, --version            Show version and build info and exit

Installation

homebrew install

If you are using Mac:

brew tap bayashi/tap
brew install bayashi/tap/go-vl
binary install

Download binary from here: https://github.com/bayashi/go-vl/releases

go install

If you have golang envvironment:

go install github.com/bayashi/go-vl/cmd/vl@latest

License

MIT License

Author

Dai Okabayashi: https://github.com/bayashi

Documentation

Overview

Example (ProcessLine)
v := &VL{
	Count: 0,
	Options: &Options{
		VtOpts: &verticaltable.VTOptions{
			HeaderFormat:  "********** %s **********",
			ShowCount:     false,
			CountFormat:   "%d. ",
			KvSeparator:   ": ",
			KeyAlignRight: true,
		},
		NoPager: true,
	},
}

v.processLine(os.Stdout, []byte("NAME                         READY     STATUS    RESTARTS   AGE"))
v.processLine(os.Stdout, []byte("hello-web-4017757401-ntgdb   1/1       Running   0          9s"))
v.processLine(os.Stdout, []byte("hello-web-4017757401-pc4j9   1/1       Running   0          9s"))
Output:

********** 1 **********
    NAME: hello-web-4017757401-ntgdb
   READY: 1/1
  STATUS: Running
RESTARTS: 0
     AGE: 9s
********** 2 **********
    NAME: hello-web-4017757401-pc4j9
   READY: 1/1
  STATUS: Running
RESTARTS: 0
     AGE: 9s
Example (ProcessLine_grep)
v := &VL{
	Count: 0,
	Options: &Options{
		VtOpts: &verticaltable.VTOptions{
			HeaderFormat:  "********** %s **********",
			ShowCount:     false,
			CountFormat:   "%d. ",
			KvSeparator:   ": ",
			KeyAlignRight: true,
		},
		NoPager: true,
		GrepRe: []*regexp.Regexp{
			regexp.MustCompile("pc4"),
			regexp.MustCompile("j9"),
		},
	},
}

v.processLine(os.Stdout, []byte("NAME                         READY     STATUS    RESTARTS   AGE"))
v.processLine(os.Stdout, []byte("hello-web-4017757401-ntgdb   1/1       Running   0          9s"))
v.processLine(os.Stdout, []byte("hello-web-4017757401-pc4j9   1/1       Running   0          9s"))
Output:

********** 1 **********
    NAME: hello-web-4017757401-pc4j9
   READY: 1/1
  STATUS: Running
RESTARTS: 0
     AGE: 9s
Example (ProcessLine_label)
v := &VL{
	Count: 0,
	Options: &Options{
		VtOpts: &verticaltable.VTOptions{
			HeaderFormat:  "********** %s **********",
			ShowCount:     false,
			CountFormat:   "%d. ",
			KvSeparator:   ": ",
			KeyAlignRight: true,
		},
		NoPager: true,
		Labels: []string{
			"READY",
			"STATUS",
		},
	},
}

v.processLine(os.Stdout, []byte("NAME                         READY     STATUS    RESTARTS   AGE"))
v.processLine(os.Stdout, []byte("hello-web-4017757401-ntgdb   1/1       Running   0          9s"))
v.processLine(os.Stdout, []byte("hello-web-4017757401-pc4j9   1/1       Running   0          9s"))
Output:

********** 1 **********
 READY: 1/1
STATUS: Running
********** 2 **********
 READY: 1/1
STATUS: Running
Example (ProcessLine_ps)
v := &VL{
	Count: 0,
	Options: &Options{
		VtOpts: &verticaltable.VTOptions{
			HeaderFormat:  "********** %s **********",
			ShowCount:     false,
			CountFormat:   "%d. ",
			KvSeparator:   ": ",
			KeyAlignRight: true,
		},
		NoPager: true,
		PS:      true,
	},
}

v.processLine(os.Stdout, []byte("USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND"))
v.processLine(os.Stdout, []byte("root         1  0.0  0.0    904   520 ?        Sl   07:06   0:00 /init"))
v.processLine(os.Stdout, []byte("root       175  0.0  0.0  34840  2200 ?        Ss   07:06   0:00 nginx: master process /usr/local/nginx/sbin/nginx"))
v.processLine(os.Stdout, []byte("user     10421  0.7  3.0 1941284 121992 pts/0  Sl+  09:32   0:56 /home/user/go/bin/gopls -mode=stdio"))
Output:

********** 1 **********
   USER: root
    PID: 1
   %CPU: 0.0
   %MEM: 0.0
    VSZ: 904
    RSS: 520
    TTY: ?
   STAT: Sl
  START: 07:06
   TIME: 0:00
COMMAND: /init
********** 2 **********
   USER: root
    PID: 175
   %CPU: 0.0
   %MEM: 0.0
    VSZ: 34840
    RSS: 2200
    TTY: ?
   STAT: Ss
  START: 07:06
   TIME: 0:00
COMMAND: nginx: master process /usr/local/nginx/sbin/nginx
********** 3 **********
   USER: user
    PID: 10421
   %CPU: 0.7
   %MEM: 3.0
    VSZ: 1941284
    RSS: 121992
    TTY: pts/0
   STAT: Sl+
  START: 09:32
   TIME: 0:56
COMMAND: /home/user/go/bin/gopls -mode=stdio

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Column

type Column struct {
	Label string
	Show  bool
}
type Header struct {
	Columns []*Column
}

type Options

type Options struct {
	GrepRe  []*regexp.Regexp
	Labels  []string
	VtOpts  *verticaltable.VTOptions
	NoPager bool
	PS      bool
}

type VL

type VL struct {
	Count    int
	Header   *Header
	Options  *Options
	Splitter *regexp.Regexp
}

func (*VL) ParseHeader

func (v *VL) ParseHeader(line []byte) *Header

func (*VL) Process

func (v *VL) Process(out io.Writer)

Directories

Path Synopsis
cmd
vl

Jump to

Keyboard shortcuts

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