Unify session-aware CLI parsing and add session-id compatibility
This commit is contained in:
@@ -41,3 +41,21 @@ func applyParsedSessionIDArg(command string, fs *flag.FlagSet, sessionID *string
|
||||
return fmt.Errorf("%s: unexpected positional arguments", command)
|
||||
}
|
||||
}
|
||||
|
||||
func resolveParsedSessionID(command, positionalSessionID string, fs *flag.FlagSet, sessionID *string) error {
|
||||
if strings.TrimSpace(positionalSessionID) == "" {
|
||||
return applyParsedSessionIDArg(command, fs, sessionID)
|
||||
}
|
||||
if fs.NArg() != 0 {
|
||||
return fmt.Errorf("%s: unexpected positional arguments", command)
|
||||
}
|
||||
return applyPositionalSessionID(command, positionalSessionID, sessionID)
|
||||
}
|
||||
|
||||
func parseSessionAwareFlags(command string, fs *flag.FlagSet, args []string, sessionID *string) error {
|
||||
positionalSessionID, args := pullLeadingSessionID(args)
|
||||
if err := fs.Parse(args); err != nil {
|
||||
return fmt.Errorf("%s: invalid flags: %w", command, err)
|
||||
}
|
||||
return resolveParsedSessionID(command, positionalSessionID, fs, sessionID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user