-
Notifications
You must be signed in to change notification settings - Fork 927
/
entc.go
40 lines (34 loc) · 849 Bytes
/
entc.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Copyright 2019-present Facebook Inc. All rights reserved.
// This source code is licensed under the Apache 2.0 license found
// in the LICENSE file in the root directory of this source tree.
package main
import (
"bytes"
"log"
"os"
"path/filepath"
"entgo.io/ent/cmd/internal/base"
"entgo.io/ent/entc/gen"
"github.com/spf13/cobra"
)
func main() {
log.SetFlags(0)
cmd := &cobra.Command{Use: "entc"}
cmd.AddCommand(
base.InitCmd(),
base.DescribeCmd(),
base.GenerateCmd(migrate),
)
_ = cmd.Execute()
}
func migrate(c *gen.Config) {
var (
target = filepath.Join(c.Target, "generate.go")
oldCmd = []byte("entgo.io/ent/cmd/entc")
)
buf, err := os.ReadFile(target)
if err != nil || !bytes.Contains(buf, oldCmd) {
return
}
_ = os.WriteFile(target, bytes.ReplaceAll(buf, oldCmd, []byte("entgo.io/ent/cmd/ent")), 0644)
}