Introduce a build-time edition hook so downstream overlays (e.g. Wukong)
can customize auth UX, config dir, static server list, visible products,
and extra root commands while keeping the default open-source behavior.
- Add pkg/edition (defaults) and pkg/editiontest contract tests; Makefile
target edition-test; CI job edition-tests.
- Root: optional RegisterExtraCommands with tool caller adapter; inject
static servers to skip market discovery when configured; deduplicate
top-level commands so overlay wins; extend hideNonDirectRuntimeCommands
with edition VisibleProducts and static commands (recovery/schema/mcp).
- Auth/config: gate login subcommand and auth login hints for embedded
editions; optional token auto-purge; edition ConfigDir override.
- version: human-readable multi-line output plus JSON with edition,
architecture, build, commit.
- Relocate internal/{config,convert,validate} to pkg/; add pkg/cli and
pkg/cmdutil (flags/time helpers).
- CI: optional notify-downstream job (GitLab trigger via secrets) on main
push; open_source_policy_test adjusted for new layout.
Secrets (repo settings): WUKONG_TRIGGER_TOKEN, WUKONG_TRIGGER_URL — optional;
if unset, downstream step is skipped.
Made-with: Cursor
83 lines
1.8 KiB
Go
83 lines
1.8 KiB
Go
package app
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"text/tabwriter"
|
|
|
|
"github.com/DingTalk-Real-AI/dingtalk-workspace-cli/pkg/edition"
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
func configureRootHelp(root *cobra.Command) {
|
|
if root == nil {
|
|
return
|
|
}
|
|
|
|
defaultHelpFunc := root.HelpFunc()
|
|
root.SetHelpFunc(func(cmd *cobra.Command, args []string) {
|
|
if cmd != root {
|
|
defaultHelpFunc(cmd, args)
|
|
return
|
|
}
|
|
renderRootHelp(root)
|
|
})
|
|
}
|
|
|
|
func renderRootHelp(root *cobra.Command) {
|
|
services := visibleMCPRootCommands(root)
|
|
w := root.OutOrStdout()
|
|
|
|
if len(services) == 0 {
|
|
_, _ = fmt.Fprintln(w, "No MCP services discovered.")
|
|
_, _ = fmt.Fprintln(w)
|
|
} else {
|
|
_, _ = fmt.Fprintln(w, "Discovered MCP Services:")
|
|
_, _ = fmt.Fprintln(w)
|
|
|
|
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
|
|
for _, service := range services {
|
|
_, _ = fmt.Fprintf(tw, " %s\t%s\n", service.Name(), strings.TrimSpace(service.Short))
|
|
}
|
|
_ = tw.Flush()
|
|
_, _ = fmt.Fprintln(w)
|
|
}
|
|
|
|
_, _ = fmt.Fprintln(w, "Usage:")
|
|
_, _ = fmt.Fprintln(w, " dws <service> [command] [flags]")
|
|
_, _ = fmt.Fprintln(w)
|
|
_, _ = fmt.Fprintln(w, `Use "dws <service> --help" for more information about a discovered MCP service.`)
|
|
}
|
|
|
|
func visibleMCPRootCommands(root *cobra.Command) []*cobra.Command {
|
|
if root == nil {
|
|
return nil
|
|
}
|
|
|
|
var allowed map[string]bool
|
|
if fn := edition.Get().VisibleProducts; fn != nil {
|
|
products := fn()
|
|
allowed = make(map[string]bool, len(products))
|
|
for _, p := range products {
|
|
allowed[p] = true
|
|
}
|
|
} else {
|
|
allowed = DirectRuntimeProductIDs()
|
|
}
|
|
if len(allowed) == 0 {
|
|
return nil
|
|
}
|
|
|
|
commands := make([]*cobra.Command, 0)
|
|
for _, cmd := range root.Commands() {
|
|
if cmd == nil || cmd.Hidden {
|
|
continue
|
|
}
|
|
if !allowed[cmd.Name()] {
|
|
continue
|
|
}
|
|
commands = append(commands, cmd)
|
|
}
|
|
return commands
|
|
}
|