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
58 lines
1.6 KiB
Go
58 lines
1.6 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package config
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/larksuite/cli/errs"
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// NewCmdConfigDefaultAs creates the "config default-as" subcommand.
|
|
func NewCmdConfigDefaultAs(f *cmdutil.Factory) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "default-as [user|bot|auto]",
|
|
Short: "View or set default identity type",
|
|
Long: "Without arguments, shows the current default identity. Pass user, bot, or auto to set a new default.",
|
|
Args: cobra.MaximumNArgs(1),
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
multi, err := core.LoadOrNotConfigured()
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
app := multi.CurrentAppConfig(f.Invocation.Profile)
|
|
if app == nil {
|
|
return core.NoActiveProfileError()
|
|
}
|
|
|
|
if len(args) == 0 {
|
|
current := app.DefaultAs
|
|
if current == "" {
|
|
current = "auto"
|
|
}
|
|
fmt.Fprintf(f.IOStreams.Out, "default-as: %s\n", current)
|
|
return nil
|
|
}
|
|
|
|
value := args[0]
|
|
if value != "user" && value != "bot" && value != "auto" {
|
|
return errs.NewValidationError(errs.SubtypeInvalidArgument, "invalid identity type %q, valid values: user | bot | auto", value)
|
|
}
|
|
|
|
app.DefaultAs = core.Identity(value)
|
|
if err := core.SaveMultiAppConfig(multi); err != nil {
|
|
return errs.NewInternalError(errs.SubtypeStorage, "failed to save config: %v", err).WithCause(err)
|
|
}
|
|
fmt.Fprintf(f.IOStreams.ErrOut, "Default identity set to: %s\n", value)
|
|
return nil
|
|
},
|
|
}
|
|
cmdutil.SetRisk(cmd, "write")
|
|
return cmd
|
|
}
|