mirror of
https://github.com/larksuite/cli.git
synced 2026-09-14 18:42:53 +08:00
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, err := multi.RequireAppConfig(f.Invocation.Profile, f.Invocation.ProfileSource)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
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
|
|
}
|