mirror of
https://github.com/larksuite/cli.git
synced 2026-07-08 02:00:19 +08:00
Add LARKSUITE_CLI_PROFILE env var and make BootstrapInvocationContext fall back to it when --profile is empty, so downstream credential resolution sees the correct profile. Also track whether the resolved profile came from the flag or the env fallback via a new InvocationContext.ProfileFromFlag field, needed by a later task to report the correct credential source.
41 lines
1.1 KiB
Go
41 lines
1.1 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"errors"
|
|
"io"
|
|
"os"
|
|
|
|
"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.
|
|
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
|
|
}
|
|
|
|
profileFromFlag := globals.Profile != ""
|
|
if !profileFromFlag {
|
|
globals.Profile = os.Getenv(envvars.CliProfile)
|
|
}
|
|
return cmdutil.InvocationContext{
|
|
Profile: globals.Profile,
|
|
ProfileFromFlag: profileFromFlag,
|
|
}, nil
|
|
}
|