Files
larksuite__cli/internal/flagalias/error_attribution.go
liangshuo-1 2a1613484a feat: add framework flag aliases and unified IM pagination (#2146)
* feat: add framework flag aliases and unified IM pagination

Introduce declarative exact-name flag aliases at the shortcut framework boundary while keeping semantic compatibility domain-owned. Add a shared, format-aware IM pagination pipeline with consistent flags, metadata, safety bounds, resumable cursors, and request throttling.

* fix: align alias attribution and pagination contracts

* fix: align alias contracts and documentation

* test: remove environment-dependent contact bot e2e

* test: restore contact bot e2e

* docs: reduce IM pagination guidance noise

---------

Co-authored-by: liangshuo-1 <266696938+liangshuo-1@users.noreply.github.com>
2026-08-03 19:20:40 +08:00

45 lines
1.4 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package flagalias
import (
"errors"
"github.com/spf13/pflag"
)
// InvalidValueAttribution identifies the canonical flag and the long-form
// spelling that supplied a value which pflag could not convert. Names do not
// include leading dashes.
type InvalidValueAttribution struct {
Canonical string
Source string
}
// InvalidValueAttributionOf resolves a typed pflag conversion error for a flag
// managed by Bind. Ordinary pflags return ok=false so installing aliases does
// not broaden the root error contract for unrelated commands.
//
// pflag's InvalidValueError does not report whether a canonical flag with a
// shorthand was supplied as -x or --long. That ambiguous case also returns
// ok=false; an alias spelling remains unambiguous because Bind records it
// before value conversion.
func InvalidValueAttributionOf(err error) (InvalidValueAttribution, bool) {
var invalidValue *pflag.InvalidValueError
if !errors.As(err, &invalidValue) || invalidValue == nil {
return InvalidValueAttribution{}, false
}
flag := invalidValue.GetFlag()
if flag == nil || len(Aliases(flag)) == 0 {
return InvalidValueAttribution{}, false
}
canonical := flag.Name
source := Source(flag)
if source == "" || (source == canonical && flag.Shorthand != "") {
return InvalidValueAttribution{}, false
}
return InvalidValueAttribution{Canonical: canonical, Source: source}, true
}