Set up flags properly for completions
This commit is contained in:
@@ -10,13 +10,13 @@ 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"`
|
||||
OutputPath *flags.Filename `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format" choice:"json" choice:"json-pretty" choice:"toml" choice:"yaml"`
|
||||
SkipParent bool `short:"P" long:"skip-parent" description:"skip loading parent templates"`
|
||||
Verbose bool `short:"v" long:"verbose" description:"enable verbose logging"`
|
||||
|
||||
Positional struct {
|
||||
InputPaths []string `positional-arg-name:"inputPath" required:"1" description:"input file path"`
|
||||
InputPaths []flags.Filename `positional-arg-name:"inputPath" required:"1" description:"input file path"`
|
||||
} `positional-args:"yes"`
|
||||
}
|
||||
|
||||
@@ -68,7 +68,7 @@ Related tools:
|
||||
fileP.SetDebug(true)
|
||||
}
|
||||
|
||||
realPath, f, err := bkl.FileMatch(path)
|
||||
realPath, f, err := bkl.FileMatch(string(path))
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
@@ -96,7 +96,7 @@ Related tools:
|
||||
if opts.OutputPath == nil {
|
||||
err = p.OutputToWriter(os.Stdout, format)
|
||||
} else {
|
||||
err = p.OutputToFile(*opts.OutputPath, format)
|
||||
err = p.OutputToFile(string(*opts.OutputPath), format)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
|
||||
@@ -29,10 +29,11 @@ func main() {
|
||||
|
||||
if cmd == "bkl" {
|
||||
// Run as bklb, not via symlink
|
||||
//nolint:goerr113,revive,stylecheck
|
||||
fatal(fmt.Errorf(`Usage:
|
||||
ln -s $(which bklb) toolb # bklb will run 'tool'
|
||||
|
||||
See https://bkl.gopatchy.io/#bklb for detailed documentation.`)) //nolint:goerr113
|
||||
See https://bkl.gopatchy.io/#bklb for detailed documentation.`))
|
||||
}
|
||||
|
||||
cmdPath, err := exec.LookPath(cmd)
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
)
|
||||
|
||||
type options struct {
|
||||
OutputPath *string `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format"`
|
||||
OutputPath *flags.Filename `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format" choice:"json" choice:"json-pretty" choice:"toml" choice:"yaml"`
|
||||
|
||||
Positional struct {
|
||||
BasePath string `positional-arg-name:"basePath" required:"true" description:"base layer file path"`
|
||||
TargetPath string `positional-arg-name:"targetPath" required:"true" description:"target output file path"`
|
||||
BasePath flags.Filename `positional-arg-name:"basePath" required:"true" description:"base layer file path"`
|
||||
TargetPath flags.Filename `positional-arg-name:"targetPath" required:"true" description:"target output file path"`
|
||||
} `positional-args:"yes"`
|
||||
}
|
||||
|
||||
@@ -52,13 +52,13 @@ See https://bkl.gopatchy.io/#bkld for detailed documentation.`
|
||||
}
|
||||
|
||||
if format == "" && opts.OutputPath != nil {
|
||||
format = strings.TrimPrefix(filepath.Ext(*opts.OutputPath), ".")
|
||||
format = strings.TrimPrefix(filepath.Ext(string(*opts.OutputPath)), ".")
|
||||
}
|
||||
|
||||
bs := []*bkl.Parser{}
|
||||
numDocs := 0
|
||||
|
||||
for _, path := range []string{opts.Positional.BasePath, opts.Positional.TargetPath} {
|
||||
for _, path := range []string{string(opts.Positional.BasePath), string(opts.Positional.TargetPath)} {
|
||||
realPath, f, err := bkl.FileMatch(path)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
@@ -131,7 +131,7 @@ See https://bkl.gopatchy.io/#bkld for detailed documentation.`
|
||||
fh := os.Stdout
|
||||
|
||||
if opts.OutputPath != nil {
|
||||
fh, err = os.OpenFile(*opts.OutputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
fh, err = os.OpenFile(string(*opts.OutputPath), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type options struct {
|
||||
OutputPath *string `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format"`
|
||||
OutputPath *flags.Filename `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format" choice:"json" choice:"json-pretty" choice:"toml" choice:"yaml"`
|
||||
|
||||
Positional struct {
|
||||
InputPaths []string `positional-arg-name:"targetPath" required:"2" description:"target output file path"`
|
||||
InputPaths []flags.Filename `positional-arg-name:"targetPath" required:"2" description:"target output file path"`
|
||||
} `positional-args:"yes"`
|
||||
}
|
||||
|
||||
@@ -51,13 +51,13 @@ See https://bkl.gopatchy.io/#bkli for detailed documentation.`
|
||||
}
|
||||
|
||||
if format == "" && opts.OutputPath != nil {
|
||||
format = strings.TrimPrefix(filepath.Ext(*opts.OutputPath), ".")
|
||||
format = strings.TrimPrefix(filepath.Ext(string(*opts.OutputPath)), ".")
|
||||
}
|
||||
|
||||
var docs []any
|
||||
|
||||
for p, path := range opts.Positional.InputPaths {
|
||||
realPath, f, err := bkl.FileMatch(path)
|
||||
realPath, f, err := bkl.FileMatch(string(path))
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
@@ -108,7 +108,7 @@ See https://bkl.gopatchy.io/#bkli for detailed documentation.`
|
||||
fh := os.Stdout
|
||||
|
||||
if opts.OutputPath != nil {
|
||||
fh, err = os.OpenFile(*opts.OutputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
fh, err = os.OpenFile(string(*opts.OutputPath), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
@@ -12,11 +12,11 @@ import (
|
||||
)
|
||||
|
||||
type options struct {
|
||||
OutputPath *string `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format"`
|
||||
OutputPath *flags.Filename `short:"o" long:"output" description:"output file path"`
|
||||
OutputFormat *string `short:"f" long:"format" description:"output format" choice:"json" choice:"json-pretty" choice:"toml" choice:"yaml"`
|
||||
|
||||
Positional struct {
|
||||
InputPath string `positional-arg-name:"layerPath" required:"true" description:"lower layer file path"`
|
||||
InputPath flags.Filename `positional-arg-name:"layerPath" required:"true" description:"lower layer file path"`
|
||||
} `positional-args:"yes"`
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ See https://bkl.gopatchy.io/#bklr for detailed documentation.`
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
realPath, format, err := bkl.FileMatch(opts.Positional.InputPath)
|
||||
realPath, format, err := bkl.FileMatch(string(opts.Positional.InputPath))
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ See https://bkl.gopatchy.io/#bklr for detailed documentation.`
|
||||
}
|
||||
|
||||
if opts.OutputPath != nil {
|
||||
format = strings.TrimPrefix(filepath.Ext(*opts.OutputPath), ".")
|
||||
format = strings.TrimPrefix(filepath.Ext(string(*opts.OutputPath)), ".")
|
||||
}
|
||||
|
||||
if opts.OutputFormat != nil {
|
||||
@@ -93,7 +93,7 @@ See https://bkl.gopatchy.io/#bklr for detailed documentation.`
|
||||
fh := os.Stdout
|
||||
|
||||
if opts.OutputPath != nil {
|
||||
fh, err = os.OpenFile(*opts.OutputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
fh, err = os.OpenFile(string(*opts.OutputPath), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if err != nil {
|
||||
fatal(err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user