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
80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
// Copyright (c) 2026 Lark Technologies Pte. Ltd.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package config
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"os"
|
|
"strings"
|
|
|
|
"github.com/larksuite/cli/errs"
|
|
"github.com/larksuite/cli/internal/cmdutil"
|
|
"github.com/larksuite/cli/internal/core"
|
|
"github.com/larksuite/cli/internal/output"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
// ConfigShowOptions holds all inputs for config show.
|
|
type ConfigShowOptions struct {
|
|
Factory *cmdutil.Factory
|
|
}
|
|
|
|
// NewCmdConfigShow creates the config show subcommand.
|
|
func NewCmdConfigShow(f *cmdutil.Factory, runF func(*ConfigShowOptions) error) *cobra.Command {
|
|
opts := &ConfigShowOptions{Factory: f}
|
|
|
|
cmd := &cobra.Command{
|
|
Use: "show",
|
|
Short: "Show current configuration",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
if runF != nil {
|
|
return runF(opts)
|
|
}
|
|
return configShowRun(opts)
|
|
},
|
|
}
|
|
cmdutil.SetRisk(cmd, "read")
|
|
|
|
return cmd
|
|
}
|
|
|
|
func configShowRun(opts *ConfigShowOptions) error {
|
|
f := opts.Factory
|
|
|
|
config, err := core.LoadMultiAppConfig()
|
|
if err != nil {
|
|
if errors.Is(err, os.ErrNotExist) {
|
|
return core.NotConfiguredError()
|
|
}
|
|
return errs.NewConfigError(errs.SubtypeInvalidConfig, "failed to load config: %v", err).WithCause(err)
|
|
}
|
|
if config == nil || len(config.Apps) == 0 {
|
|
return core.NotConfiguredError()
|
|
}
|
|
app := config.CurrentAppConfig(f.Invocation.Profile)
|
|
if app == nil {
|
|
return errs.NewConfigError(errs.SubtypeNotConfigured, "no active profile").WithHint("run: lark-cli profile list")
|
|
}
|
|
users := "(no logged-in users)"
|
|
if len(app.Users) > 0 {
|
|
var userStrs []string
|
|
for _, u := range app.Users {
|
|
userStrs = append(userStrs, fmt.Sprintf("%s (%s)", u.UserName, u.UserOpenId))
|
|
}
|
|
users = strings.Join(userStrs, ", ")
|
|
}
|
|
output.PrintJson(f.IOStreams.Out, map[string]interface{}{
|
|
"workspace": core.CurrentWorkspace().Display(),
|
|
"profile": app.ProfileName(),
|
|
"appId": app.AppId,
|
|
"appSecret": "****",
|
|
"brand": app.Brand,
|
|
"lang": app.Lang,
|
|
"users": users,
|
|
})
|
|
fmt.Fprintf(f.IOStreams.ErrOut, "\nConfig file path: %s\n", core.GetConfigPath())
|
|
return nil
|
|
}
|