addContextFromFile merges the context from a file into the context to send to the console.
(toSend map[string][]string, filePath string)
| 75 | |
| 76 | // addContextFromFile merges the context from a file into the context to send to the console. |
| 77 | func addContextFromFile(toSend map[string][]string, filePath string) error { |
| 78 | log.Tracef("loading console context from %s", filePath) |
| 79 | |
| 80 | content, err := os.ReadFile(filePath) |
| 81 | if err != nil { |
| 82 | return err |
| 83 | } |
| 84 | |
| 85 | newContext := make(map[string][]string, 0) |
| 86 | |
| 87 | err = yaml.Unmarshal(content, newContext) |
| 88 | if err != nil { |
| 89 | return fmt.Errorf("%s: %w", filePath, err) |
| 90 | } |
| 91 | |
| 92 | err = mergeContext(toSend, newContext) |
| 93 | if err != nil && !errors.Is(err, ErrNoContextData) { |
| 94 | // having an empty console/context.yaml is not an error |
| 95 | return err |
| 96 | } |
| 97 | |
| 98 | return nil |
| 99 | } |
| 100 | |
| 101 | // LoadConsoleContext loads the context from the hub (if provided) and the file console_context_path. |
| 102 | func LoadConsoleContext(c *csconfig.Config, hub *cwhub.Hub) error { |
no test coverage detected
searching dependent graphs…