MCPcopy
hub / github.com/cli/cli / resolveHosts

Function resolveHosts

pkg/cmd/skills/install/install.go:909–962  ·  view source on GitHub ↗
(opts *InstallOptions, canPrompt bool)

Source from the content-addressed store, hash-verified

907}
908
909func resolveHosts(opts *InstallOptions, canPrompt bool) ([]*registry.AgentHost, error) {
910 if opts.Agent != "" {
911 h, err := registry.FindByID(opts.Agent)
912 if err != nil {
913 return nil, err
914 }
915 return []*registry.AgentHost{h}, nil
916 }
917
918 // --dir fixes the destination in resolveInstallDir regardless of the agent host,
919 // which then only affects post-install hint output; the default is a safe placeholder.
920 if opts.Dir != "" {
921 h, err := registry.FindByID(registry.DefaultAgentID)
922 if err != nil {
923 return nil, err
924 }
925 return []*registry.AgentHost{h}, nil
926 }
927
928 if !canPrompt {
929 h, err := registry.FindByID(registry.DefaultAgentID)
930 if err != nil {
931 return nil, err
932 }
933 return []*registry.AgentHost{h}, nil
934 }
935
936 fmt.Fprintln(opts.IO.ErrOut)
937 labels := make([]string, len(registry.Agents))
938 defaultLabel := ""
939 for i, h := range registry.Agents {
940 labels[i] = h.Name
941 if h.ID == registry.DefaultAgentID {
942 defaultLabel = labels[i]
943 }
944 }
945 if defaultLabel == "" {
946 defaultLabel = labels[0]
947 }
948 indices, err := opts.Prompter.MultiSelect("Select target agent(s):", []string{defaultLabel}, labels)
949 if err != nil {
950 return nil, err
951 }
952
953 if len(indices) == 0 {
954 return nil, fmt.Errorf("must select at least one target agent")
955 }
956
957 selected := make([]*registry.AgentHost, len(indices))
958 for i, idx := range indices {
959 selected[i] = &registry.Agents[idx]
960 }
961 return selected, nil
962}
963
964func resolveScope(opts *InstallOptions, canPrompt bool) (registry.Scope, error) {
965 if opts.Dir != "" {

Callers 2

installRunFunction · 0.85
runLocalInstallFunction · 0.85

Calls 3

FindByIDFunction · 0.92
MultiSelectMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected