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

Function resolveHosts

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

Source from the content-addressed store, hash-verified

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