mirror of
https://github.com/larksuite/cli.git
synced 2026-07-03 14:02:43 +08:00
Each lark-cli invocation can now carry its own app identity, so callers bound to different apps no longer compete over a single stored default profile.
42 lines
1.2 KiB
Go
42 lines
1.2 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/envvars"
|
|
"github.com/spf13/pflag"
|
|
)
|
|
|
|
// BootstrapInvocationContext extracts global invocation options before
|
|
// the real command tree is built, so provider-backed config resolution sees
|
|
// the correct profile from the start.
|
|
//
|
|
// Profile resolution: --profile flag > CliRuntimeAppID env > "" (defers to
|
|
// MultiAppConfig.CurrentApp). The env value flows through FindApp which
|
|
// matches by Name first, then by AppId — so callers can pass either form.
|
|
func BootstrapInvocationContext(args []string) (cmdutil.InvocationContext, error) {
|
|
var globals GlobalOptions
|
|
|
|
fs := pflag.NewFlagSet("bootstrap", pflag.ContinueOnError)
|
|
fs.ParseErrorsAllowlist.UnknownFlags = true
|
|
fs.SetInterspersed(true)
|
|
fs.SetOutput(io.Discard)
|
|
RegisterGlobalFlags(fs, &globals)
|
|
|
|
if err := fs.Parse(args); err != nil && !errors.Is(err, pflag.ErrHelp) {
|
|
return cmdutil.InvocationContext{}, err
|
|
}
|
|
profile := globals.Profile
|
|
if profile == "" {
|
|
profile = strings.TrimSpace(os.Getenv(envvars.CliRuntimeAppID))
|
|
}
|
|
return cmdutil.InvocationContext{Profile: profile}, nil
|
|
}
|