mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
fix #27: check if parsed headers and columns match
This commit is contained in:
@@ -29,7 +29,7 @@ import (
|
||||
)
|
||||
|
||||
const DefaultSeparator string = `(\s\s+|\t)`
|
||||
const Version string = "v1.2.1"
|
||||
const Version string = "v1.2.2"
|
||||
const MAXPARTS = 2
|
||||
|
||||
var DefaultLoadPath = os.Getenv("HOME") + "/.config/tablizer/lisp"
|
||||
|
||||
35
cmd/root.go
35
cmd/root.go
@@ -63,6 +63,14 @@ func completion(cmd *cobra.Command, mode string) error {
|
||||
}
|
||||
}
|
||||
|
||||
// we die with exit 1 if there's an error
|
||||
func wrapE(err error) {
|
||||
if err != nil {
|
||||
fmt.Println(err.Error())
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func Execute() {
|
||||
var (
|
||||
conf cfg.Config
|
||||
@@ -77,48 +85,43 @@ func Execute() {
|
||||
Use: "tablizer [regex] [file, ...]",
|
||||
Short: "[Re-]tabularize tabular data",
|
||||
Long: `Manipulate tabular output of other programs`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if ShowVersion {
|
||||
fmt.Println(cfg.Getversion())
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
if ShowManual {
|
||||
man()
|
||||
|
||||
return nil
|
||||
return
|
||||
}
|
||||
|
||||
if len(ShowCompletion) > 0 {
|
||||
return completion(cmd, ShowCompletion)
|
||||
wrapE(completion(cmd, ShowCompletion))
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Setup
|
||||
err := conf.ParseConfigfile()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrapE(conf.ParseConfigfile())
|
||||
|
||||
conf.CheckEnv()
|
||||
conf.PrepareModeFlags(modeflag)
|
||||
conf.PrepareSortFlags(sortmode)
|
||||
|
||||
if err = conf.PrepareFilters(); err != nil {
|
||||
return err
|
||||
}
|
||||
wrapE(conf.PrepareFilters())
|
||||
|
||||
conf.DetermineColormode()
|
||||
conf.ApplyDefaults()
|
||||
|
||||
// setup lisp env, load plugins etc
|
||||
err = lib.SetupLisp(&conf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
wrapE(lib.SetupLisp(&conf))
|
||||
|
||||
// actual execution starts here
|
||||
return lib.ProcessFiles(&conf, args)
|
||||
wrapE(lib.ProcessFiles(&conf, args))
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -40,6 +40,20 @@ func contains(s []int, e int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// validate the consitency of parsed data
|
||||
func ValidateConsistency(data *Tabdata) error {
|
||||
expectedfields := len(data.headers)
|
||||
|
||||
for idx, row := range data.entries {
|
||||
if len(row) != expectedfields {
|
||||
return fmt.Errorf("row %d does not contain expected %d elements, but %d",
|
||||
idx, expectedfields, len(row))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// parse columns list given with -c, modifies config.UseColumns based
|
||||
// on eventually given regex
|
||||
func PrepareColumns(conf *cfg.Config, data *Tabdata) error {
|
||||
|
||||
Reference in New Issue
Block a user