cmd/internal/base: add build tags flag to schema dump command (#4339)

This commit is contained in:
Jannik Clausen
2025-02-24 12:46:24 +01:00
committed by GitHub
parent 428604afd7
commit addae7fc6f

View File

@@ -214,7 +214,7 @@ func SchemaCmd() *cobra.Command {
var ( var (
cfg gen.Config cfg gen.Config
dlct, version string dlct, version string
features []string features, buildTags []string
cmd = &cobra.Command{ cmd = &cobra.Command{
Use: "schema [flags] path", Use: "schema [flags] path",
Short: "dump the DDL for the schema directory", Short: "dump the DDL for the schema directory",
@@ -225,10 +225,14 @@ func SchemaCmd() *cobra.Command {
), ),
Args: cobra.ExactArgs(1), Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, path []string) { Run: func(cmd *cobra.Command, path []string) {
// Ensure features are set. for _, o := range []entc.Option{
if err := entc.FeatureNames(features...)(&cfg); err != nil { entc.FeatureNames(features...),
entc.BuildTags(buildTags...),
} {
if err := o(&cfg); err != nil {
log.Fatalln(err) log.Fatalln(err)
} }
}
// If the target directory is not inferred from // If the target directory is not inferred from
// the schema path, resolve its package path. // the schema path, resolve its package path.
if cfg.Target != "" { if cfg.Target != "" {
@@ -261,6 +265,7 @@ func SchemaCmd() *cobra.Command {
cmd.Flags().StringVar(&dlct, "dialect", "", "database dialect to use") cmd.Flags().StringVar(&dlct, "dialect", "", "database dialect to use")
cmd.Flags().StringVar(&version, "version", "", "database version to assume") cmd.Flags().StringVar(&version, "version", "", "database version to assume")
cmd.Flags().StringSliceVarP(&features, "feature", "", nil, "extend codegen with additional features") cmd.Flags().StringSliceVarP(&features, "feature", "", nil, "extend codegen with additional features")
cmd.Flags().StringSliceVarP(&buildTags, "build-tags", "", nil, "go build tags to use when loading the schema graph")
cobra.CheckErr(cmd.MarkFlagRequired("dialect")) cobra.CheckErr(cmd.MarkFlagRequired("dialect"))
return cmd return cmd
} }