| 170 | } |
| 171 | |
| 172 | func getConfigPath(stderr io.Writer, f *pflag.Flag) (string, string) { |
| 173 | if f != nil && f.Changed { |
| 174 | file := f.Value.String() |
| 175 | if file == "" { |
| 176 | fmt.Fprintln(stderr, "error parsing config: file argument is empty") |
| 177 | os.Exit(1) |
| 178 | } |
| 179 | abspath, err := filepath.Abs(file) |
| 180 | if err != nil { |
| 181 | fmt.Fprintf(stderr, "error parsing config: absolute file path lookup failed: %s\n", err) |
| 182 | os.Exit(1) |
| 183 | } |
| 184 | return filepath.Dir(abspath), filepath.Base(abspath) |
| 185 | } else { |
| 186 | wd, err := os.Getwd() |
| 187 | if err != nil { |
| 188 | fmt.Fprintln(stderr, "error parsing sqlc.json: file does not exist") |
| 189 | os.Exit(1) |
| 190 | } |
| 191 | return wd, "" |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | var genCmd = &cobra.Command{ |
| 196 | Use: "generate", |