Reuse adapter sessions during execution
This commit is contained in:
@@ -69,6 +69,7 @@ type ParseOptions struct {
|
||||
|
||||
// Session owns one mutable backend tree for a single command invocation.
|
||||
type Session struct {
|
||||
metadata *Command
|
||||
root *spfcobra.Command
|
||||
declarations map[*spfcobra.Command]*Command
|
||||
}
|
||||
@@ -79,11 +80,20 @@ func Prepare(root *Command, options ParseOptions) *Session {
|
||||
if root == nil {
|
||||
return session
|
||||
}
|
||||
session.metadata = root
|
||||
options = normalizeOptions(options)
|
||||
session.root, session.declarations = buildTree(root, options)
|
||||
return session
|
||||
}
|
||||
|
||||
// Metadata returns the neutral tree used to prepare this session.
|
||||
func (session *Session) Metadata() *Command {
|
||||
if session == nil {
|
||||
return nil
|
||||
}
|
||||
return session.metadata
|
||||
}
|
||||
|
||||
// Parse routes leading command words and parses flags on this session's tree.
|
||||
func (session *Session) Parse(argv []string) Result {
|
||||
result := Result{}
|
||||
|
||||
Reference in New Issue
Block a user