Documentation
¶
Index ¶
- Constants
- func AccessTokensToIdentities(tokens []interface{}) []string
- func AddTips(cmd *cobra.Command, tips ...string)
- func BaseSecurityHeaders() http.Header
- func ContextWithShortcut(ctx context.Context, name, executionId string) context.Context
- func DisableAuthCheck(cmd *cobra.Command)
- func ExecutionIdFromContext(ctx context.Context) (string, bool)
- func GetSupportedIdentities(cmd *cobra.Command) []string
- func GetTips(cmd *cobra.Command) []string
- func IsAuthCheckDisabled(cmd *cobra.Command) bool
- func ParseJSONMap(input, label string) (map[string]any, error)
- func ParseOptionalBody(httpMethod, data string) (interface{}, error)
- func PrintDryRun(w io.Writer, request client.RawApiRequest, config *core.CliConfig, ...) error
- func PrintIdentity(w io.Writer, as core.Identity, config *core.CliConfig, autoDetected bool)
- func SetSupportedIdentities(cmd *cobra.Command, identities []string)
- func SetTips(cmd *cobra.Command, tips []string)
- func ShortcutHeaderOpts(ctx context.Context) larkcore.RequestOptionFunc
- func ShortcutHeaders(ctx context.Context) http.Header
- func ShortcutNameFromContext(ctx context.Context) (string, bool)
- func ThemeFeishu() *huh.Theme
- func UserAgentValue() string
- type DryRunAPI
- func (d *DryRunAPI) Body(body interface{}) *DryRunAPI
- func (d *DryRunAPI) DELETE(url string) *DryRunAPI
- func (d *DryRunAPI) Desc(desc string) *DryRunAPI
- func (d *DryRunAPI) Format() string
- func (d *DryRunAPI) GET(url string) *DryRunAPI
- func (d *DryRunAPI) MarshalJSON() ([]byte, error)
- func (d *DryRunAPI) PATCH(url string) *DryRunAPI
- func (d *DryRunAPI) POST(url string) *DryRunAPI
- func (d *DryRunAPI) PUT(url string) *DryRunAPI
- func (d *DryRunAPI) Params(params map[string]interface{}) *DryRunAPI
- func (d *DryRunAPI) Set(key string, value interface{}) *DryRunAPI
- type DryRunAPICall
- type Factory
- func (f *Factory) CheckIdentity(as core.Identity, supported []string) error
- func (f *Factory) CheckStrictMode(ctx context.Context, as core.Identity) error
- func (f *Factory) NewAPIClient() (*client.APIClient, error)
- func (f *Factory) NewAPIClientWithConfig(cfg *core.CliConfig) (*client.APIClient, error)
- func (f *Factory) ResolveAs(ctx context.Context, cmd *cobra.Command, flagAs core.Identity) core.Identity
- func (f *Factory) ResolveStrictMode(ctx context.Context) core.StrictMode
- type IOStreams
- type InvocationContext
- type RetryTransport
- type SecurityHeaderTransport
- type UserAgentTransport
Constants ¶
const ( HeaderSource = "X-Cli-Source" HeaderVersion = "X-Cli-Version" HeaderShortcut = "X-Cli-Shortcut" HeaderExecutionId = "X-Cli-Execution-Id" SourceValue = "lark-cli" HeaderUserAgent = "User-Agent" )
Variables ¶
This section is empty.
Functions ¶
func AccessTokensToIdentities ¶
func AccessTokensToIdentities(tokens []interface{}) []string
AccessTokensToIdentities converts from_meta accessTokens (e.g. ["tenant", "user"]) to CLI identity names (e.g. ["bot", "user"]).
func BaseSecurityHeaders ¶
BaseSecurityHeaders returns headers that every request must carry.
func ContextWithShortcut ¶
ContextWithShortcut injects shortcut name and execution ID into the context.
func DisableAuthCheck ¶
DisableAuthCheck marks a command (and all its children) as not requiring auth.
func ExecutionIdFromContext ¶
ExecutionIdFromContext extracts the execution ID from the context.
func GetSupportedIdentities ¶ added in v1.0.5
GetSupportedIdentities returns the declared identities, or nil if not declared.
func IsAuthCheckDisabled ¶
IsAuthCheckDisabled returns true if the command or any ancestor has auth check disabled.
func ParseJSONMap ¶
ParseJSONMap parses a JSON string into a map. Returns an empty map if input is empty.
func ParseOptionalBody ¶
ParseOptionalBody parses --data JSON for methods that accept a request body. Returns (nil, nil) if the method has no body or data is empty.
func PrintDryRun ¶
func PrintDryRun(w io.Writer, request client.RawApiRequest, config *core.CliConfig, format string) error
PrintDryRun outputs a standardised dry-run summary using DryRunAPI. When format is "pretty", outputs human-readable text; otherwise JSON.
func PrintIdentity ¶
PrintIdentity outputs the current identity to stderr so callers (including AI agents) can see which identity is being used for the API call.
func SetSupportedIdentities ¶ added in v1.0.5
SetSupportedIdentities marks which identities a command supports.
func ShortcutHeaderOpts ¶
func ShortcutHeaderOpts(ctx context.Context) larkcore.RequestOptionFunc
ShortcutHeaderOpts extracts Shortcut info from the context and returns a RequestOptionFunc that injects the corresponding headers into SDK requests. Returns nil if the context has no Shortcut info.
func ShortcutHeaders ¶ added in v1.0.5
ShortcutHeaders extracts Shortcut info from the context and returns the corresponding HTTP headers. Returns nil if the context has no Shortcut info.
func ShortcutNameFromContext ¶
ShortcutNameFromContext extracts the shortcut name from the context.
func ThemeFeishu ¶
ThemeFeishu returns a huh theme with Feishu brand colors.
func UserAgentValue ¶
func UserAgentValue() string
UserAgentValue returns the User-Agent value: "lark-cli/{version}".
Types ¶
type DryRunAPI ¶
type DryRunAPI struct {
// contains filtered or unexported fields
}
DryRunAPI is the builder and result type for dry-run output. URL templates use :param placeholders; Set stores actual values; MarshalJSON and Format resolve them.
func NewDryRunAPI ¶
func NewDryRunAPI() *DryRunAPI
func (*DryRunAPI) Desc ¶
Desc sets a description on the last added call. If no calls exist yet, sets the top-level description.
func (*DryRunAPI) Format ¶
Format renders the dry-run output as plain text for AI/human consumption.
func (*DryRunAPI) MarshalJSON ¶
MarshalJSON serializes as {"description": "...", "api": [...calls with resolved URLs], ...extra}.
type DryRunAPICall ¶
type DryRunAPICall struct {
Desc string `json:"desc,omitempty"`
Method string `json:"method"`
URL string `json:"url"`
Params map[string]interface{} `json:"params,omitempty"`
Body interface{} `json:"body,omitempty"`
}
DryRunAPICall describes a single API call in dry-run output.
type Factory ¶
type Factory struct {
Config func() (*core.CliConfig, error) // lazily loads app config from Credential
HttpClient func() (*http.Client, error) // HTTP client for non-Lark API calls (with retry and security headers)
LarkClient func() (*lark.Client, error) // Lark SDK client for all Open API calls
IOStreams *IOStreams // stdin/stdout/stderr streams
Invocation InvocationContext // Immutable call context; do not mutate after Factory construction.
Keychain keychain.KeychainAccess // secret storage (real keychain in prod, mock in tests)
IdentityAutoDetected bool // set by ResolveAs when identity was auto-detected
ResolvedIdentity core.Identity // identity resolved by the last ResolveAs call
Credential *credential.CredentialProvider
}
func NewDefault ¶
func NewDefault(inv InvocationContext) *Factory
NewDefault creates a production Factory with cached closures. Initialization follows a credential-first order:
Phase 1: HttpClient (no credential dependency) Phase 2: Credential (sole data source for account info) Phase 3: Config derived from Credential Phase 4: LarkClient derived from Credential
func TestFactory ¶
func TestFactory(t *testing.T, config *core.CliConfig) (*Factory, *bytes.Buffer, *bytes.Buffer, *httpmock.Registry)
TestFactory creates a Factory for testing. Returns (factory, stdout buffer, stderr buffer, http mock registry).
func (*Factory) CheckIdentity ¶
CheckIdentity verifies the resolved identity is in the supported list. On success, sets f.ResolvedIdentity. On failure, returns an error tailored to whether the identity was explicit (--as) or auto-detected.
func (*Factory) CheckStrictMode ¶ added in v1.0.5
CheckStrictMode returns an error if strict mode is active and identity is not allowed.
func (*Factory) NewAPIClient ¶
NewAPIClient creates an APIClient using the Factory's base Config (app credentials only). For user-mode calls where the correct user profile matters, use NewAPIClientWithConfig instead.
func (*Factory) NewAPIClientWithConfig ¶
NewAPIClientWithConfig creates an APIClient with an explicit config. Use this when the caller has already resolved the correct config.
func (*Factory) ResolveAs ¶
func (f *Factory) ResolveAs(ctx context.Context, cmd *cobra.Command, flagAs core.Identity) core.Identity
ResolveAs returns the effective identity type. If the user explicitly passed --as, use that value; otherwise use the configured default. When the value is "auto" (or unset), auto-detect based on credential hints.
func (*Factory) ResolveStrictMode ¶ added in v1.0.5
func (f *Factory) ResolveStrictMode(ctx context.Context) core.StrictMode
ResolveStrictMode returns the effective strict mode by reading Account.SupportedIdentities from the credential provider chain.
type IOStreams ¶
IOStreams provides the standard input/output/error streams. Commands should use these instead of os.Stdin/Stdout/Stderr to enable testing and output capture.
type InvocationContext ¶ added in v1.0.5
type InvocationContext struct {
Profile string
}
Factory holds shared dependencies injected into every command. All function fields are lazily initialized and cached after first call. In tests, replace any field to stub out external dependencies.
type RetryTransport ¶
type RetryTransport struct {
Base http.RoundTripper
MaxRetries int
Delay time.Duration // base delay for exponential backoff; defaults to 500ms
}
RetryTransport is an http.RoundTripper that retries on 5xx responses and network errors. MaxRetries defaults to 0 (no retries).
type SecurityHeaderTransport ¶
type SecurityHeaderTransport struct {
Base http.RoundTripper
}
SecurityHeaderTransport is an http.RoundTripper that injects CLI security headers into every request. Shortcut headers are read from the request context.
type UserAgentTransport ¶
type UserAgentTransport struct {
Base http.RoundTripper
}
UserAgentTransport is an http.RoundTripper that sets the User-Agent header. Used in the SDK transport chain to override the SDK's default User-Agent.