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 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 SetTips(cmd *cobra.Command, tips []string)
- func ShortcutHeaderOpts(ctx context.Context) larkcore.RequestOptionFunc
- 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) NewAPIClient() (*client.APIClient, error)
- func (f *Factory) NewAPIClientWithConfig(cfg *core.CliConfig) (*client.APIClient, error)
- func (f *Factory) ResolveAs(cmd *cobra.Command, flagAs core.Identity) core.Identity
- func (f *Factory) ResolveConfig(as core.Identity) (*core.CliConfig, error)
- type IOStreams
- 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 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 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 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 (credentials, brand, defaultAs)
AuthConfig func() (*core.CliConfig, error) // like Config but also requires a logged-in user
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
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
}
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.
func NewDefault ¶
func NewDefault() *Factory
NewDefault creates a production Factory with cached closures.
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) 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 user profile (e.g. via AuthConfig for user-mode commands).
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 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.