MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / launchCommand

Method launchCommand

internal/cli/launch.go:22–123  ·  view source on GitHub ↗

launchCommand resolves the tool/provider/model triple (interactively when stdin is a TTY and any of the three is unpinned), writes the tool's native config file, then exec's the binary.

(state *globalState)

Source from the content-addressed store, hash-verified

20// when stdin is a TTY and any of the three is unpinned), writes the
21// tool's native config file, then exec's the binary.
22func (a *App) launchCommand(state *globalState) *cobra.Command {
23 var (
24 dryRun bool
25 endpointName string
26 modelName string
27 )
28 cmd := &cobra.Command{
29 Use: "launch [TOOL] [-- ARGS...]",
30 Aliases: []string{"l"},
31 Short: "Launch interactive TUI or a specific assistant",
32 Args: cobra.ArbitraryArgs,
33 RunE: func(cmd *cobra.Command, args []string) error {
34 registry, err := tools.LoadDefault()
35 if err != nil {
36 return err
37 }
38
39 // Split the positional args: first is the optional tool
40 // name; the rest is forwarded to the tool binary.
41 var positionalTool string
42 var toolArgs []string
43 if len(args) > 0 {
44 positionalTool = args[0]
45 toolArgs = args[1:]
46 }
47
48 // Validate the positional tool name BEFORE touching
49 // the provider store so an unknown name surfaces the right
50 // error even when no providers config exists.
51 pinned := launchSelection{
52 EndpointName: endpointName,
53 Model: modelName,
54 }
55 if positionalTool != "" {
56 tool, ok := lookupTool(registry, positionalTool)
57 if !ok {
58 return fmt.Errorf("Unknown tool: %s", positionalTool)
59 }
60 pinned.Tool = tool
61 }
62
63 // When the user has not pinned anything and the output is
64 // non-TTY, preserve the long-standing behaviour of
65 // rendering the tool picker as plain text (the user is
66 // running in a script context and just wants to know what
67 // would happen). Skip providers loading entirely.
68 if pinned.Tool.Name == "" && pinned.EndpointName == "" && pinned.Model == "" && !outIsTTY(cmd.OutOrStdout()) {
69 _, _ = fmt.Fprint(cmd.OutOrStdout(), newToolMenuModel(registry.LaunchNames()).View())
70 return nil
71 }
72
73 // Load the provider store lazily — only when the wizard or
74 // auto-resolve actually needs an endpoint.
75 file, perr := makeProviderAPI(state).File(context.Background())
76 if perr != nil {
77 return perr
78 }
79

Callers 1

rootCommandMethod · 0.95

Calls 15

LoadDefaultFunction · 0.92
ResolveAPIKeyFunction · 0.92
PlanFunction · 0.92
WriteConfigFunction · 0.92
ResolveLaunchEnvFunction · 0.92
RunFunction · 0.92
lookupToolFunction · 0.85
outIsTTYFunction · 0.85
newToolMenuModelFunction · 0.85
makeProviderAPIFunction · 0.85
resolveLaunchSelectionFunction · 0.85
printDryRunFunction · 0.85

Tested by

no test coverage detected