Remove unused parser resource plumbing
This commit is contained in:
@@ -4,7 +4,6 @@ package cobra
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"strconv"
|
||||
@@ -35,8 +34,7 @@ func Prepare(root *commandmeta.Command, options commandmeta.ParseOptions) *Sessi
|
||||
session.metadata = root
|
||||
session.flagAliases = append([]commandmeta.FlagAlias(nil), options.FlagAliases...)
|
||||
session.flagAliasesForPath = options.FlagAliasesForPath
|
||||
options = normalizeOptions(options)
|
||||
session.root, session.declarations = buildTree(root, options)
|
||||
session.root, session.declarations = buildTree(root)
|
||||
return session
|
||||
}
|
||||
|
||||
@@ -289,23 +287,7 @@ func Parse(root *commandmeta.Command, argv []string, options commandmeta.ParseOp
|
||||
return Prepare(root, options).Parse(argv)
|
||||
}
|
||||
|
||||
func normalizeOptions(options commandmeta.ParseOptions) commandmeta.ParseOptions {
|
||||
if options.Context == nil {
|
||||
options.Context = context.Background()
|
||||
}
|
||||
if options.In == nil {
|
||||
options.In = strings.NewReader("")
|
||||
}
|
||||
if options.Out == nil {
|
||||
options.Out = io.Discard
|
||||
}
|
||||
if options.Err == nil {
|
||||
options.Err = io.Discard
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
func buildTree(root *commandmeta.Command, options commandmeta.ParseOptions) (*spfcobra.Command, map[*spfcobra.Command]*commandmeta.Command) {
|
||||
func buildTree(root *commandmeta.Command) (*spfcobra.Command, map[*spfcobra.Command]*commandmeta.Command) {
|
||||
nodes := make(map[*spfcobra.Command]*commandmeta.Command)
|
||||
var build func(*commandmeta.Command) *spfcobra.Command
|
||||
build = func(declaration *commandmeta.Command) *spfcobra.Command {
|
||||
@@ -321,10 +303,8 @@ func buildTree(root *commandmeta.Command, options commandmeta.ParseOptions) (*sp
|
||||
if declaration.Runnable {
|
||||
backend.Run = func(*spfcobra.Command, []string) {}
|
||||
}
|
||||
backend.SetContext(options.Context)
|
||||
backend.SetIn(options.In)
|
||||
backend.SetOut(options.Out)
|
||||
backend.SetErr(options.Err)
|
||||
backend.SetOut(io.Discard)
|
||||
backend.SetErr(io.Discard)
|
||||
backend.SetHelpFunc(func(*spfcobra.Command, []string) {})
|
||||
backend.SetFlagErrorFunc(func(_ *spfcobra.Command, err error) error { return err })
|
||||
backend.SetUsageTemplate(usageTemplate)
|
||||
|
||||
Reference in New Issue
Block a user