mirror of
https://github.com/ent/ent.git
synced 2026-05-22 09:31:45 +03:00
* cmd: rename init to new Signed-off-by: Giau. Tran Minh <hello@giautm.dev> * doc: update guide to use new command Signed-off-by: Giau. Tran Minh <hello@giautm.dev> --------- Signed-off-by: Giau. Tran Minh <hello@giautm.dev>
42 lines
866 B
Go
42 lines
866 B
Go
// 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.NewCmd(),
|
|
base.DescribeCmd(),
|
|
base.GenerateCmd(migrate),
|
|
base.InitCmd(),
|
|
)
|
|
_ = 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)
|
|
}
|