Files
wehub-resource-sync bf9395e022
CI / license-header (push) Has been skipped
CI / e2e-dry-run (push) Has been skipped
CI / fast-gate (push) Failing after 0s
Test PR Label Logic / test-pr-labels (push) Failing after 1s
Skill Format Check / check-format (push) Failing after 2s
CI / security (push) Failing after 5s
CI / unit-test (push) Has been skipped
CI / lint (push) Has been skipped
CI / script-test (push) Has been skipped
CI / deterministic-gate (push) Has been skipped
CI / coverage (push) Has been skipped
CI / results (push) Has been cancelled
CI / deadcode (push) Has been cancelled
CI / e2e-live (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:22:54 +08:00

53 lines
1.7 KiB
Go

// Copyright (c) 2026 Lark Technologies Pte. Ltd.
// SPDX-License-Identifier: MIT
package calendar
import (
"strings"
"time"
"github.com/larksuite/cli/errs"
"github.com/larksuite/cli/shortcuts/common"
"github.com/spf13/cobra"
)
const (
PrimaryCalendarIDStr = "primary"
)
// resolveStartEnd returns (startInput, endInput) from flags with defaults.
// --start defaults to today's date, --end defaults to start date (will be resolved to end-of-day by caller).
func resolveStartEnd(runtime *common.RuntimeContext) (string, string) {
startInput := runtime.Str("start")
if startInput == "" {
startInput = time.Now().Format("2006-01-02")
}
endInput := runtime.Str("end")
if endInput == "" {
endInput = startInput
}
return startInput, endInput
}
func hasExplicitBotFlag(cmd *cobra.Command) bool {
if cmd == nil {
return false
}
flag := cmd.Flag("as")
return flag != nil && flag.Changed && flag.Value != nil && strings.TrimSpace(flag.Value.String()) == "bot"
}
func rejectCalendarAutoBotFallback(runtime *common.RuntimeContext) error {
if runtime == nil || !runtime.IsBot() || hasExplicitBotFlag(runtime.Cmd) {
return nil
}
if runtime.Factory == nil || !runtime.Factory.IdentityAutoDetected {
return nil
}
msg := "calendar commands require a valid user login by default; when no valid user login state is available, auto identity falls back to bot and may operate on the bot calendar instead of your own. Run `lark-cli auth login --domain calendar` for your calendar, or rerun with `--as bot` if bot identity is intentional."
hint := "restore user login: `lark-cli auth login --domain calendar`\nintentional bot usage: rerun with `--as bot`"
return errs.NewAuthenticationError(errs.SubtypeTokenMissing, "%s", msg).WithHint("%s", hint)
}