Reuse adapter sessions during execution

This commit is contained in:
2026-10-09 01:42:03 +00:00
parent a852301801
commit a7960e5e94
6 changed files with 328 additions and 32 deletions

View File

@@ -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{}