| 132 | } |
| 133 | |
| 134 | func Generate(ctx context.Context, dir, filename string, o *Options) (map[string]string, error) { |
| 135 | e := o.Env |
| 136 | stderr := o.Stderr |
| 137 | |
| 138 | configPath, conf, err := o.ReadConfig(dir, filename) |
| 139 | if err != nil { |
| 140 | return nil, err |
| 141 | } |
| 142 | |
| 143 | base := filepath.Base(configPath) |
| 144 | if err := config.Validate(conf); err != nil { |
| 145 | fmt.Fprintf(stderr, "error validating %s: %s\n", base, err) |
| 146 | return nil, err |
| 147 | } |
| 148 | |
| 149 | if err := e.Validate(conf); err != nil { |
| 150 | fmt.Fprintf(stderr, "error validating %s: %s\n", base, err) |
| 151 | return nil, err |
| 152 | } |
| 153 | |
| 154 | // Comment on why these two methods exist |
| 155 | if conf.Cloud.Project != "" && e.Remote && !e.NoRemote { |
| 156 | return remoteGenerate(ctx, configPath, conf, dir, stderr) |
| 157 | } |
| 158 | |
| 159 | g := &generator{ |
| 160 | dir: dir, |
| 161 | output: map[string]string{}, |
| 162 | } |
| 163 | |
| 164 | if err := processQuerySets(ctx, g, conf, dir, o); err != nil { |
| 165 | return nil, err |
| 166 | } |
| 167 | |
| 168 | return g.output, nil |
| 169 | } |
| 170 | |
| 171 | type generator struct { |
| 172 | m sync.Mutex |