(cmd *cobra.Command, state *globalState)
| 39 | var errEndpointsHandled = errors.New("cli: --endpoints handled") |
| 40 | |
| 41 | func handleEndpointsShortCircuit(cmd *cobra.Command, state *globalState) error { |
| 42 | if state.endpoints == "" { |
| 43 | return nil |
| 44 | } |
| 45 | file, err := makeProviderAPI(state).File(context.Background()) |
| 46 | if err != nil { |
| 47 | return err |
| 48 | } |
| 49 | out := cmd.OutOrStdout() |
| 50 | target := state.endpoints |
| 51 | if target == "all" { |
| 52 | printEndpointTable(out, file) |
| 53 | return errEndpointsHandled |
| 54 | } |
| 55 | matches := map[string]providers.Endpoint{} |
| 56 | for _, name := range file.SortedNames() { |
| 57 | ep := file.Endpoints[name] |
| 58 | if ep.SupportsClient(target) { |
| 59 | matches[name] = ep |
| 60 | } |
| 61 | } |
| 62 | if len(matches) == 0 { |
| 63 | return fmt.Errorf("No endpoints support client: %s", target) |
| 64 | } |
| 65 | subset := providers.File{Common: file.Common, Endpoints: matches} |
| 66 | printEndpointTable(out, subset) |
| 67 | return errEndpointsHandled |
| 68 | } |
| 69 | |
| 70 | func printEndpointTable(out interface{ Write(p []byte) (int, error) }, file providers.File) { |
| 71 | fmt.Fprintf(out, "Endpoints: %d\n", len(file.Endpoints)) |
no test coverage detected