mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
added shell mode output
This commit is contained in:
4
TODO
4
TODO
@@ -1,5 +1 @@
|
|||||||
Add a mode like FreeBSD stat(1):
|
|
||||||
|
|
||||||
stat -s dead.letter
|
|
||||||
st_dev=170671546954750497 st_ino=159667 st_mode=0100644 st_nlink=1 st_uid=1001 st_gid=1001 st_rdev=18446744073709551615 st_size=573 st_atime=1661994007 st_mtime=1661961878 st_ctime=1661961878 st_birthtime=1658394900 st_blksize=4096 st_blocks=3 st_flags=2048
|
|
||||||
|
|
||||||
|
|||||||
@@ -65,11 +65,13 @@ func init() {
|
|||||||
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagExtended, "extended", "X", false, "Enable extended output")
|
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagExtended, "extended", "X", false, "Enable extended output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagMarkdown, "markdown", "M", false, "Enable markdown table output")
|
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagMarkdown, "markdown", "M", false, "Enable markdown table output")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagOrgtable, "orgtbl", "O", false, "Enable org-mode table output")
|
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagOrgtable, "orgtbl", "O", false, "Enable org-mode table output")
|
||||||
rootCmd.MarkFlagsMutuallyExclusive("extended", "markdown", "orgtbl")
|
rootCmd.PersistentFlags().BoolVarP(&lib.OutflagShell, "shell", "S", false, "Enable shell mode output")
|
||||||
|
rootCmd.MarkFlagsMutuallyExclusive("extended", "markdown", "orgtbl", "shell")
|
||||||
rootCmd.Flags().MarkHidden("extended")
|
rootCmd.Flags().MarkHidden("extended")
|
||||||
rootCmd.Flags().MarkHidden("orgtbl")
|
rootCmd.Flags().MarkHidden("orgtbl")
|
||||||
rootCmd.Flags().MarkHidden("markdown")
|
rootCmd.Flags().MarkHidden("markdown")
|
||||||
|
rootCmd.Flags().MarkHidden("shell")
|
||||||
|
|
||||||
// same thing but more common, takes precedence over above group
|
// same thing but more common, takes precedence over above group
|
||||||
rootCmd.PersistentFlags().StringVarP(&lib.OutputMode, "output", "o", "", "Output mode - one of: orgtbl, markdown, extended, ascii(default)")
|
rootCmd.PersistentFlags().StringVarP(&lib.OutputMode, "output", "o", "", "Output mode - one of: orgtbl, markdown, extended, shell, ascii(default)")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,8 @@ var Separator string
|
|||||||
var OutflagExtended bool
|
var OutflagExtended bool
|
||||||
var OutflagMarkdown bool
|
var OutflagMarkdown bool
|
||||||
var OutflagOrgtable bool
|
var OutflagOrgtable bool
|
||||||
|
var OutflagShell bool
|
||||||
var OutputMode string
|
var OutputMode string
|
||||||
|
|
||||||
var Version = "v1.0.2"
|
var Version = "v1.0.3"
|
||||||
var validOutputmodes = "(orgtbl|markdown|extended|ascii)"
|
var validOutputmodes = "(orgtbl|markdown|extended|ascii)"
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ func PrepareModeFlags() error {
|
|||||||
OutputMode = "markdown"
|
OutputMode = "markdown"
|
||||||
case OutflagOrgtable:
|
case OutflagOrgtable:
|
||||||
OutputMode = "orgtbl"
|
OutputMode = "orgtbl"
|
||||||
|
case OutflagShell:
|
||||||
|
OutputMode = "shell"
|
||||||
|
NoNumbering = true
|
||||||
default:
|
default:
|
||||||
OutputMode = "ascii"
|
OutputMode = "ascii"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,20 +27,22 @@ import (
|
|||||||
|
|
||||||
func printData(data *Tabdata) {
|
func printData(data *Tabdata) {
|
||||||
// prepare headers: add numbers to headers
|
// prepare headers: add numbers to headers
|
||||||
if !NoNumbering {
|
numberedHeaders := []string{}
|
||||||
numberedHeaders := []string{}
|
for i, head := range data.headers {
|
||||||
for i, head := range data.headers {
|
if len(Columns) > 0 {
|
||||||
if len(Columns) > 0 {
|
// -c specified
|
||||||
// -c specified
|
if !contains(UseColumns, i+1) {
|
||||||
if !contains(UseColumns, i+1) {
|
// ignore this one
|
||||||
// ignore this one
|
continue
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if NoNumbering {
|
||||||
|
numberedHeaders = append(numberedHeaders, head)
|
||||||
|
} else {
|
||||||
numberedHeaders = append(numberedHeaders, fmt.Sprintf("%s(%d)", head, i+1))
|
numberedHeaders = append(numberedHeaders, fmt.Sprintf("%s(%d)", head, i+1))
|
||||||
}
|
}
|
||||||
data.headers = numberedHeaders
|
|
||||||
}
|
}
|
||||||
|
data.headers = numberedHeaders
|
||||||
|
|
||||||
// prepare data
|
// prepare data
|
||||||
if len(Columns) > 0 {
|
if len(Columns) > 0 {
|
||||||
@@ -69,6 +71,8 @@ func printData(data *Tabdata) {
|
|||||||
printOrgmodeData(data)
|
printOrgmodeData(data)
|
||||||
case "markdown":
|
case "markdown":
|
||||||
printMarkdownData(data)
|
printMarkdownData(data)
|
||||||
|
case "shell":
|
||||||
|
printShellData(data)
|
||||||
default:
|
default:
|
||||||
printAsciiData(data)
|
printAsciiData(data)
|
||||||
}
|
}
|
||||||
@@ -177,3 +181,26 @@ func printExtendedData(data *Tabdata) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Shell output, ready to be eval'd. Just like FreeBSD stat(1)
|
||||||
|
*/
|
||||||
|
func printShellData(data *Tabdata) {
|
||||||
|
if len(data.entries) > 0 {
|
||||||
|
var idx int
|
||||||
|
for _, entry := range data.entries {
|
||||||
|
idx = 0
|
||||||
|
for i, value := range entry {
|
||||||
|
if len(Columns) > 0 {
|
||||||
|
if !contains(UseColumns, i+1) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("%s=\"%s\" ", data.headers[idx], value)
|
||||||
|
idx++
|
||||||
|
}
|
||||||
|
fmt.Println()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
15
tablizer.pod
15
tablizer.pod
@@ -74,7 +74,7 @@ The numbering can be suppressed by using the B<-n> option.
|
|||||||
Finally the B<-d> option enables debugging output which is mostly
|
Finally the B<-d> option enables debugging output which is mostly
|
||||||
usefull for the developer.
|
usefull for the developer.
|
||||||
|
|
||||||
?head2 OUTPUT MODES
|
=head2 OUTPUT MODES
|
||||||
|
|
||||||
There might be cases when the tabular output of a program is way too
|
There might be cases when the tabular output of a program is way too
|
||||||
large for your current terminal but you still need to see every
|
large for your current terminal but you still need to see every
|
||||||
@@ -83,7 +83,7 @@ usefull which enables I<extended mode>. In this mode, each row will be
|
|||||||
printed vertically, header left, value right, aligned by the field
|
printed vertically, header left, value right, aligned by the field
|
||||||
widths. Here's an example:
|
widths. Here's an example:
|
||||||
|
|
||||||
kubectl get pods | ./tablizer -X
|
kubectl get pods | ./tablizer -o extended
|
||||||
NAME: repldepl-7bcd8d5b64-7zq4l
|
NAME: repldepl-7bcd8d5b64-7zq4l
|
||||||
READY: 1/1
|
READY: 1/1
|
||||||
STATUS: Running
|
STATUS: Running
|
||||||
@@ -93,6 +93,17 @@ widths. Here's an example:
|
|||||||
You can of course still use a regex to reduce the number of rows
|
You can of course still use a regex to reduce the number of rows
|
||||||
displayed.
|
displayed.
|
||||||
|
|
||||||
|
The option B<-o shell> can be used if the output has to be processed
|
||||||
|
by the shell, it prints variable assignments for each cell, one line
|
||||||
|
per row:
|
||||||
|
|
||||||
|
kubectl get pods | ./tablizer -o extended ./tablizer -o shell
|
||||||
|
NAME="repldepl-7bcd8d5b64-7zq4l" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
NAME="repldepl-7bcd8d5b64-m48n8" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
NAME="repldepl-7bcd8d5b64-q2bf4" READY="1/1" STATUS="Running" RESTARTS="9 (47m ago)" AGE="4d23h"
|
||||||
|
|
||||||
|
You can use this in an eval loop.
|
||||||
|
|
||||||
Beside normal ascii mode (the default) and extended mode there are
|
Beside normal ascii mode (the default) and extended mode there are
|
||||||
more output modes available: B<orgtbl> which prints an Emacs org-mode
|
more output modes available: B<orgtbl> which prints an Emacs org-mode
|
||||||
table and B<markdown> which prints a Markdown table.
|
table and B<markdown> which prints a Markdown table.
|
||||||
|
|||||||
Reference in New Issue
Block a user