mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-16 20:20:57 +01:00
check pattern on startup
This commit is contained in:
@@ -17,9 +17,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package cfg
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/gookit/color"
|
||||
"os"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
const DefaultSeparator string = `(\s\s+|\t)`
|
||||
@@ -36,6 +38,7 @@ type Config struct {
|
||||
OutputMode int
|
||||
InvertMatch bool
|
||||
Pattern string
|
||||
PatternR *regexp.Regexp
|
||||
|
||||
SortMode string
|
||||
SortDescending bool
|
||||
@@ -163,3 +166,15 @@ func (c *Config) ApplyDefaults() {
|
||||
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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user