mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
check pattern on startup
This commit is contained in:
4
TODO.md
4
TODO.md
@@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
- rm printYamlData() log.Fatal(), maybe return error on all printers?
|
- rm printYamlData() log.Fatal(), maybe return error on all printers?
|
||||||
|
|
||||||
- refactor parser, there's some duplicate code
|
- refactor parser, there's some duplicate code, remove pattern from parser args
|
||||||
|
|
||||||
## Features to be implemented
|
## Features to be implemented
|
||||||
|
|
||||||
@@ -14,6 +14,4 @@
|
|||||||
|
|
||||||
- add --no-headers option
|
- add --no-headers option
|
||||||
|
|
||||||
- add input parsing support for CSV including unquoting of stuff
|
|
||||||
like: `"xxx","1919 b"` etc, maybe an extra option for unquoting
|
|
||||||
|
|
||||||
|
|||||||
@@ -17,9 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||||||
package cfg
|
package cfg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/gookit/color"
|
"github.com/gookit/color"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
)
|
)
|
||||||
|
|
||||||
const DefaultSeparator string = `(\s\s+|\t)`
|
const DefaultSeparator string = `(\s\s+|\t)`
|
||||||
@@ -36,6 +38,7 @@ type Config struct {
|
|||||||
OutputMode int
|
OutputMode int
|
||||||
InvertMatch bool
|
InvertMatch bool
|
||||||
Pattern string
|
Pattern string
|
||||||
|
PatternR *regexp.Regexp
|
||||||
|
|
||||||
SortMode string
|
SortMode string
|
||||||
SortDescending bool
|
SortDescending bool
|
||||||
@@ -163,3 +166,15 @@ func (c *Config) ApplyDefaults() {
|
|||||||
c.NoNumbering = true
|
c.NoNumbering = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Config) PreparePattern() error {
|
||||||
|
PatternR, err := regexp.Compile(c.Pattern)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return errors.Unwrap(fmt.Errorf("Regexp pattern %s is invalid: %w", c.Pattern, err))
|
||||||
|
}
|
||||||
|
|
||||||
|
c.PatternR = PatternR
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -73,6 +73,11 @@ func Execute() {
|
|||||||
conf.CheckEnv()
|
conf.CheckEnv()
|
||||||
conf.PrepareModeFlags(modeflag)
|
conf.PrepareModeFlags(modeflag)
|
||||||
conf.PrepareSortFlags(sortmode)
|
conf.PrepareSortFlags(sortmode)
|
||||||
|
|
||||||
|
if err := conf.PreparePattern(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
conf.ApplyDefaults()
|
conf.ApplyDefaults()
|
||||||
|
|
||||||
// actual execution starts here
|
// actual execution starts here
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import (
|
|||||||
"bufio"
|
"bufio"
|
||||||
"encoding/csv"
|
"encoding/csv"
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"github.com/alecthomas/repr"
|
"github.com/alecthomas/repr"
|
||||||
"github.com/tlinden/tablizer/cfg"
|
"github.com/tlinden/tablizer/cfg"
|
||||||
"io"
|
"io"
|
||||||
|
|||||||
Reference in New Issue
Block a user