• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / cli / 8043579157

23 Feb 2024 11:24AM UTC coverage: 58.859% (-0.005%) from 58.864%
8043579157

Pull #1986

github

felixgabler
fix: resolve openai key as env variable
Pull Request #1986: feat: enable Supabase AI during local development

2 of 2 new or added lines in 2 files covered. (100.0%)

15 existing lines in 3 files now uncovered.

6192 of 10520 relevant lines covered (58.86%)

689.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

39.13
/cmd/gen.go
1
package cmd
2

3
import (
4
        "errors"
5

6
        env "github.com/Netflix/go-env"
7
        "github.com/spf13/afero"
8
        "github.com/spf13/cobra"
9
        "github.com/supabase/cli/internal/gen/keys"
10
        "github.com/supabase/cli/internal/gen/types/typescript"
11
        "github.com/supabase/cli/internal/utils"
12
        "github.com/supabase/cli/internal/utils/flags"
13
)
14

15
var (
16
        genCmd = &cobra.Command{
17
                GroupID: groupManagementAPI,
18
                Use:     "gen",
19
                Short:   "Run code generation tools",
20
        }
21

22
        keyNames  keys.CustomName
23
        keyOutput = utils.EnumFlag{
24
                Allowed: []string{
25
                        utils.OutputEnv,
26
                        utils.OutputJson,
27
                        utils.OutputToml,
28
                        utils.OutputYaml,
29
                },
30
                Value: utils.OutputEnv,
31
        }
32

33
        genKeysCmd = &cobra.Command{
34
                Use:   "keys",
35
                Short: "Generate keys for preview branch",
36
                PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
37
                        es, err := env.EnvironToEnvSet(override)
38
                        if err != nil {
×
39
                                return err
×
40
                        }
×
41
                        if err := env.Unmarshal(es, &keyNames); err != nil {
×
42
                                return err
×
43
                        }
×
44
                        return cmd.Root().PersistentPreRunE(cmd, args)
×
UNCOV
45
                },
×
46
                RunE: func(cmd *cobra.Command, args []string) error {
×
47
                        return keys.Run(cmd.Context(), flags.ProjectRef, keyOutput.Value, keyNames, afero.NewOsFs())
×
48
                },
UNCOV
49
        }
×
UNCOV
50

×
UNCOV
51
        genTypesCmd = &cobra.Command{
×
52
                Use:   "types",
53
                Short: "Generate types from Postgres schema",
54
        }
55

56
        postgrestV9Compat bool
57

58
        genTypesTypescriptCmd = &cobra.Command{
59
                Use:   "typescript",
60
                Short: "Generate types for TypeScript",
61
                PreRunE: func(cmd *cobra.Command, args []string) error {
62
                        if postgrestV9Compat && !cmd.Flags().Changed("db-url") {
63
                                return errors.New("--postgrest-v9-compat can only be used together with --db-url.")
64
                        }
×
65
                        return nil
×
UNCOV
66
                },
×
67
                RunE: func(cmd *cobra.Command, args []string) error {
×
68
                        ctx := cmd.Context()
×
69
                        if flags.DbConfig.Host == "" {
70
                                // If no flag is specified, prompt for project id.
×
71
                                if err := flags.ParseProjectRef(ctx, afero.NewMemMapFs()); errors.Is(err, utils.ErrNotLinked) {
×
72
                                        return errors.New("Must specify one of --local, --linked, --project-id, or --db-url")
×
73
                                } else if err != nil {
×
74
                                        return err
×
75
                                }
×
UNCOV
76
                        }
×
77
                        return typescript.Run(ctx, flags.ProjectRef, flags.DbConfig, schema, postgrestV9Compat, afero.NewOsFs())
×
UNCOV
78
                },
×
79
                Example: `  supabase gen types typescript --local
UNCOV
80
  supabase gen types typescript --linked
×
81
  supabase gen types typescript --project-id abc-def-123 --schema public --schema private
82
  supabase gen types typescript --db-url 'postgresql://...' --schema public --schema auth`,
83
        }
84
)
85

86
func init() {
87
        genFlags := genTypesTypescriptCmd.Flags()
88
        genFlags.Bool("local", false, "Generate types from the local dev database.")
89
        genFlags.Bool("linked", false, "Generate types from the linked project.")
1✔
90
        genFlags.String("db-url", "", "Generate types from a database url.")
1✔
91
        genFlags.StringVar(&flags.ProjectRef, "project-id", "", "Generate types from a project ID.")
1✔
92
        genTypesTypescriptCmd.MarkFlagsMutuallyExclusive("local", "linked", "project-id", "db-url")
1✔
93
        genFlags.StringSliceVarP(&schema, "schema", "s", []string{}, "Comma separated list of schema to include.")
1✔
94
        genFlags.BoolVar(&postgrestV9Compat, "postgrest-v9-compat", false, "Generate types compatible with PostgREST v9 and below. Only use together with --db-url.")
1✔
95
        genTypesCmd.AddCommand(genTypesTypescriptCmd)
1✔
96
        genCmd.AddCommand(genTypesCmd)
1✔
97
        keyFlags := genKeysCmd.Flags()
1✔
98
        keyFlags.StringVar(&flags.ProjectRef, "project-ref", "", "Project ref of the Supabase project.")
1✔
99
        keyFlags.VarP(&keyOutput, "output", "o", "Output format of key variables.")
1✔
100
        keyFlags.StringSliceVar(&override, "override-name", []string{}, "Override specific variable names.")
1✔
101
        genCmd.AddCommand(genKeysCmd)
1✔
102
        rootCmd.AddCommand(genCmd)
1✔
103
}
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc