-P / --skip-parent
This commit is contained in:
@@ -33,19 +33,6 @@ func New() *Parser {
|
||||
return &Parser{}
|
||||
}
|
||||
|
||||
// NewFromFile creates a new [Parser] then calls [Parser.MergeFileLayers] with
|
||||
// the supplied path to merge in the file and its parent layers.
|
||||
func NewFromFile(path string) (*Parser, error) {
|
||||
p := New()
|
||||
|
||||
err := p.MergeFileLayers(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return p, nil
|
||||
}
|
||||
|
||||
// SetDebug enables or disables debug log output to stderr.
|
||||
func (p *Parser) SetDebug(debug bool) {
|
||||
p.debug = debug
|
||||
|
||||
+13
-6
@@ -11,6 +11,7 @@ import (
|
||||
type options struct {
|
||||
OutputPath *string `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format"`
|
||||
SkipParent bool `short:"P" long:"skip-parent" description:"skip loading parent templates"`
|
||||
Verbose bool `short:"v" long:"verbose" description:"enable verbose logging"`
|
||||
|
||||
Positional struct {
|
||||
@@ -35,14 +36,20 @@ func main() {
|
||||
}
|
||||
|
||||
for _, path := range opts.Positional.InputPaths {
|
||||
fileP, err := bkl.NewFromFile(path)
|
||||
fileP := bkl.New()
|
||||
|
||||
if opts.SkipParent {
|
||||
err = fileP.MergeFile(path)
|
||||
} else {
|
||||
err = fileP.MergeFileLayers(path)
|
||||
}
|
||||
if err != nil {
|
||||
fatal("%s", err)
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
err = p.MergeParser(fileP)
|
||||
if err != nil {
|
||||
fatal("%s", err)
|
||||
fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,11 +65,11 @@ func main() {
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
fatal("%s", err)
|
||||
fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func fatal(format string, v ...any) {
|
||||
fmt.Fprintf(os.Stderr, format+"\n", v...)
|
||||
func fatal(err error) {
|
||||
fmt.Fprintf(os.Stderr, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
+8
-1
@@ -380,13 +380,20 @@ $ <cmd>bkl</cmd> <focus><string>c.d.yaml</string></focus> # a.yaml + a.b.yaml
|
||||
|
||||
<p>Inheritance is determined using filenames by default. After stripping the extension, the remaining filename is split on <inlineFocus>.</inlineFocus> and treated as an inheritance hierarchy (e.g. <inlineFocus>a.b.c.yaml</inlineFocus> inherits from <inlineFocus>a.b.<ext></inlineFocus> inherits from <inlineFocus>a.<ext></inlineFocus>). Parent templates may have any supported file extension.</p>
|
||||
|
||||
<label>Set Parent</label>
|
||||
<label>Set Parent In File</label>
|
||||
<code class="labeled"><focus><key>$parent</key>: <string>a.b</string></focus> # inherits from a.b.<ext>, from a.<ext></code>
|
||||
|
||||
<vSpace></vSpace>
|
||||
|
||||
<p><inlineFocus>$parent</inlineFocus> can only be used in the document root. bkl will still check for all supported endings of a manually-specified parent file, and will still evaluate template layers of the parent in the normal order.</p>
|
||||
|
||||
<label>Set Parent In CLI</label>
|
||||
<code>$ <cmd>bkl</cmd> <focus>-P <string>a.b.yaml</string> <string>c.d.yaml</string></focus> # a.b.yaml + c.d.yaml</code>
|
||||
|
||||
<vSpace></vSpace>
|
||||
|
||||
<p>The <inlineFocus>-P</inlineFocus> flag (or <inlineFocus>--skip-parent</inlineFocus>) tells bkl to not load parent templates using filenames or <inlineFocus>$parent</inlineFocus>. Layer order can then be specified with just commandline argument order.</p>
|
||||
|
||||
<vSpace></vSpace>
|
||||
<vSpace></vSpace>
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
bkl -v -f yaml a.b.yaml
|
||||
bkl -f yaml a.b.yaml
|
||||
|
||||
@@ -1 +1 @@
|
||||
bkl -v -f yaml a.b.yaml
|
||||
bkl -f yaml a.b.yaml
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
a: 1
|
||||
@@ -0,0 +1 @@
|
||||
b: 2
|
||||
@@ -0,0 +1 @@
|
||||
bkl -P -f yaml a.b.yaml c.yaml
|
||||
@@ -0,0 +1,2 @@
|
||||
a: 1
|
||||
b: 2
|
||||
Reference in New Issue
Block a user