mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
added -v flag, replace 'help' subcommand wich -m, more tests
This commit is contained in:
46
cmd/root.go
46
cmd/root.go
@@ -18,33 +18,31 @@ package cmd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"github.com/tlinden/tablizer/lib"
|
||||
"fmt"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/tlinden/tablizer/lib"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
var helpCmd = &cobra.Command{
|
||||
Use: "help",
|
||||
Short: "Show documentation",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
man := exec.Command("less", "-")
|
||||
var ShowManual = false
|
||||
|
||||
var b bytes.Buffer
|
||||
b.Write([]byte(manpage))
|
||||
func man() {
|
||||
man := exec.Command("less", "-")
|
||||
|
||||
man.Stdout = os.Stdout
|
||||
man.Stdin = &b
|
||||
man.Stderr = os.Stderr
|
||||
var b bytes.Buffer
|
||||
b.Write([]byte(manpage))
|
||||
|
||||
err := man.Run()
|
||||
man.Stdout = os.Stdout
|
||||
man.Stdin = &b
|
||||
man.Stderr = os.Stderr
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
},
|
||||
err := man.Run()
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
@@ -57,6 +55,11 @@ var rootCmd = &cobra.Command{
|
||||
return nil
|
||||
}
|
||||
|
||||
if ShowManual {
|
||||
man()
|
||||
return nil
|
||||
}
|
||||
|
||||
err := lib.PrepareColumns()
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -81,7 +84,9 @@ func Execute() {
|
||||
func init() {
|
||||
rootCmd.PersistentFlags().BoolVarP(&lib.Debug, "debug", "d", false, "Enable debugging")
|
||||
rootCmd.PersistentFlags().BoolVarP(&lib.NoNumbering, "no-numbering", "n", false, "Disable header numbering")
|
||||
rootCmd.PersistentFlags().BoolVarP(&lib.ShowVersion, "version", "v", false, "Print program version")
|
||||
rootCmd.PersistentFlags().BoolVarP(&lib.ShowVersion, "version", "V", false, "Print program version")
|
||||
rootCmd.PersistentFlags().BoolVarP(&lib.InvertMatch, "invert-match", "v", false, "select non-matching rows")
|
||||
rootCmd.PersistentFlags().BoolVarP(&ShowManual, "man", "m", false, "Display manual page")
|
||||
rootCmd.PersistentFlags().StringVarP(&lib.Separator, "separator", "s", "", "Custom field separator")
|
||||
rootCmd.PersistentFlags().StringVarP(&lib.Columns, "columns", "c", "", "Only show the speficied columns (separated by ,)")
|
||||
|
||||
@@ -98,11 +103,4 @@ func init() {
|
||||
|
||||
// same thing but more common, takes precedence over above group
|
||||
rootCmd.PersistentFlags().StringVarP(&lib.OutputMode, "output", "o", "", "Output mode - one of: orgtbl, markdown, extended, shell, ascii(default)")
|
||||
|
||||
rootCmd.AddCommand(helpCmd)
|
||||
|
||||
rootCmd.SetHelpCommand(&cobra.Command{
|
||||
Use: "no-help",
|
||||
Hidden: true,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,8 @@ SYNOPSIS
|
||||
-c, --columns string Only show the speficied columns (separated by ,)
|
||||
-d, --debug Enable debugging
|
||||
-h, --help help for tablizer
|
||||
-v, --invert-match select non-matching rows
|
||||
-m, --man Display manual page
|
||||
-n, --no-numbering Disable header numbering
|
||||
-o, --output string Output mode - one of: orgtbl, markdown, extended, ascii(default)
|
||||
-X, --extended Enable extended output
|
||||
@@ -38,7 +40,8 @@ DESCRIPTION
|
||||
|
||||
Without any options it reads its input from "STDIN", but you can also
|
||||
specify a file as a parameter. If you want to reduce the output by some
|
||||
regular expression, just specify it as its first parameters. Hence:
|
||||
regular expression, just specify it as its first parameter. You may also
|
||||
use the -v option to exclude all rows which match the pattern. Hence:
|
||||
|
||||
# read from STDIN
|
||||
kubectl get pods | tablizer
|
||||
|
||||
Reference in New Issue
Block a user