MCPcopy Create free account
hub / github.com/cli/cli / resolveHosts

Function resolveHosts

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

Source from the content-addressed store, hash-verified

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