mirror of
https://codeberg.org/scip/tablizer.git
synced 2025-12-17 04:30:56 +01:00
refactored output printer, now using tablewriter
This commit is contained in:
@@ -18,8 +18,10 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
package lib
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
@@ -38,7 +40,7 @@ func contains(s []int, e int) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func prepareColumns() {
|
||||
func PrepareColumns() {
|
||||
if len(Columns) > 0 {
|
||||
for _, use := range strings.Split(Columns, ",") {
|
||||
usenum, err := strconv.Atoi(use)
|
||||
@@ -49,3 +51,32 @@ func prepareColumns() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func PrepareModeFlags() error {
|
||||
if len(OutputMode) == 0 {
|
||||
switch {
|
||||
case OutflagExtended:
|
||||
OutputMode = "extended"
|
||||
case OutflagMarkdown:
|
||||
OutputMode = "markdown"
|
||||
case OutflagOrgtable:
|
||||
OutputMode = "orgtbl"
|
||||
default:
|
||||
OutputMode = "ascii"
|
||||
}
|
||||
} else {
|
||||
r, err := regexp.Compile(validOutputmodes)
|
||||
|
||||
if err != nil {
|
||||
return errors.New("Failed to validate output mode spec!")
|
||||
}
|
||||
|
||||
match := r.MatchString(OutputMode)
|
||||
|
||||
if !match {
|
||||
return errors.New("Invalid output mode!")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user