mirror of
https://github.com/mikefarah/yq.git
synced 2025-01-12 19:25:37 +00:00
wip split
This commit is contained in:
parent
c2d9b98aeb
commit
3a7fd8f2c4
@ -100,22 +100,7 @@ func evaluateAll(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
var printerWriter yqlib.PrinterWriter
|
||||
|
||||
if splitFileExp == "i" {
|
||||
colorsEnabled = forceColor
|
||||
printerWriter = yqlib.NewMultiPrinterWriter(nil, format)
|
||||
|
||||
} else if splitFileExp != "" {
|
||||
colorsEnabled = forceColor
|
||||
splitExp, err := yqlib.NewExpressionParser().ParseExpression(splitFileExp)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
printerWriter = yqlib.NewMultiPrinterWriter(splitExp, format)
|
||||
} else {
|
||||
printerWriter = yqlib.NewSinglePrinterWriter(out)
|
||||
}
|
||||
printerWriter := configurePrinterWriter(format, out)
|
||||
|
||||
printer := yqlib.NewPrinter(printerWriter, format, unwrapScalar, colorsEnabled, indent, !noDocSeparators)
|
||||
|
||||
|
@ -83,6 +83,10 @@ func evaluateSequence(cmd *cobra.Command, args []string) error {
|
||||
return fmt.Errorf("Write inplace flag only applicable when giving an expression and at least one file")
|
||||
}
|
||||
|
||||
if writeInplace && splitFileExp != "" {
|
||||
return fmt.Errorf("Write inplace cannot be used with split file")
|
||||
}
|
||||
|
||||
if writeInplace {
|
||||
// only use colors if its forced
|
||||
colorsEnabled = forceColor
|
||||
@ -106,7 +110,9 @@ func evaluateSequence(cmd *cobra.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
printer := yqlib.NewPrinter(yqlib.NewSinglePrinterWriter(out), format, unwrapScalar, colorsEnabled, indent, !noDocSeparators)
|
||||
printerWriter := configurePrinterWriter(format, out)
|
||||
|
||||
printer := yqlib.NewPrinter(printerWriter, format, unwrapScalar, colorsEnabled, indent, !noDocSeparators)
|
||||
|
||||
streamEvaluator := yqlib.NewStreamEvaluator()
|
||||
|
||||
|
28
cmd/printer_utils.go
Normal file
28
cmd/printer_utils.go
Normal file
@ -0,0 +1,28 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"io"
|
||||
|
||||
"github.com/mikefarah/yq/v4/pkg/yqlib"
|
||||
)
|
||||
|
||||
func configurePrinterWriter(format yqlib.PrinterOutputFormat, out io.Writer) yqlib.PrinterWriter {
|
||||
|
||||
var printerWriter yqlib.PrinterWriter
|
||||
|
||||
if splitFileExp == "i" {
|
||||
colorsEnabled = forceColor
|
||||
printerWriter = yqlib.NewMultiPrinterWriter(nil, format)
|
||||
|
||||
} else if splitFileExp != "" {
|
||||
colorsEnabled = forceColor
|
||||
splitExp, err := yqlib.NewExpressionParser().ParseExpression(splitFileExp)
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
printerWriter = yqlib.NewMultiPrinterWriter(splitExp, format)
|
||||
} else {
|
||||
printerWriter = yqlib.NewSinglePrinterWriter(out)
|
||||
}
|
||||
return printerWriter
|
||||
}
|
Loading…
Reference in New Issue
Block a user