diff --git a/cmd/ent/ent.go b/cmd/ent/ent.go index 97fbe5f9f3..9b04583d70 100644 --- a/cmd/ent/ent.go +++ b/cmd/ent/ent.go @@ -16,9 +16,10 @@ func main() { log.SetFlags(0) cmd := &cobra.Command{Use: "ent"} cmd.AddCommand( - base.InitCmd(), + base.NewCmd(), base.DescribeCmd(), base.GenerateCmd(), + base.InitCmd(), ) _ = cmd.Execute() } diff --git a/cmd/entc/entc.go b/cmd/entc/entc.go index 434ac8f4ed..38b4e5bab5 100644 --- a/cmd/entc/entc.go +++ b/cmd/entc/entc.go @@ -20,9 +20,10 @@ func main() { log.SetFlags(0) cmd := &cobra.Command{Use: "entc"} cmd.AddCommand( - base.InitCmd(), + base.NewCmd(), base.DescribeCmd(), base.GenerateCmd(migrate), + base.InitCmd(), ) _ = cmd.Execute() } diff --git a/cmd/internal/base/base.go b/cmd/internal/base/base.go index 55fd4fcaf4..36af078910 100644 --- a/cmd/internal/base/base.go +++ b/cmd/internal/base/base.go @@ -64,14 +64,28 @@ func (IDType) String() string { // InitCmd returns the init command for ent/c packages. func InitCmd() *cobra.Command { + c := NewCmd() + c.Use = "init [flags] [schemas]" + c.Short = "initialize an environment with zero or more schemas" + c.Example = examples( + "ent init Example", + "ent init --target entv1/schema User Group", + "ent init --template ./path/to/file.tmpl User", + ) + c.Deprecated = "use `ent new` instead" + return c +} + +// NewCmd returns the new command for ent/c packages. +func NewCmd() *cobra.Command { var target, tmplPath string cmd := &cobra.Command{ - Use: "init [flags] [schemas]", - Short: "initialize an environment with zero or more schemas", + Use: "new [flags] [schemas]", + Short: "new an environment with zero or more schemas", Example: examples( - "ent init Example", - "ent init --target entv1/schema User Group", - "ent init --template ./path/to/file.tmpl User", + "ent new Example", + "ent new --target entv1/schema User Group", + "ent new --template ./path/to/file.tmpl User", ), Args: func(_ *cobra.Command, names []string) error { for _, name := range names { @@ -92,10 +106,10 @@ func InitCmd() *cobra.Command { tmpl, err = template.New("schema").Parse(defaultTemplate) } if err != nil { - log.Fatalln(fmt.Errorf("ent/init: could not parse template %w", err)) + log.Fatalln(fmt.Errorf("ent/new: could not parse template %w", err)) } - if err := initEnv(target, names, tmpl); err != nil { - log.Fatalln(fmt.Errorf("ent/init: %w", err)) + if err := newEnv(target, names, tmpl); err != nil { + log.Fatalln(fmt.Errorf("ent/new: %w", err)) } }, } @@ -189,17 +203,17 @@ func GenerateCmd(postRun ...func(*gen.Config)) *cobra.Command { return cmd } -// initEnv initialize an environment for ent codegen. -func initEnv(target string, names []string, tmpl *template.Template) error { +// newEnv create an new environment for ent codegen. +func newEnv(target string, names []string, tmpl *template.Template) error { if err := createDir(target); err != nil { return fmt.Errorf("create dir %s: %w", target, err) } for _, name := range names { if err := gen.ValidSchemaName(name); err != nil { - return fmt.Errorf("init schema %s: %w", name, err) + return fmt.Errorf("new schema %s: %w", name, err) } if fileExists(target, name) { - return fmt.Errorf("init schema %s: already exists", name) + return fmt.Errorf("new schema %s: already exists", name) } b := bytes.NewBuffer(nil) if err := tmpl.Execute(b, name); err != nil { diff --git a/doc/md/code-gen.md b/doc/md/code-gen.md index f87d5967f1..2688992bbf 100644 --- a/doc/md/code-gen.md +++ b/doc/md/code-gen.md @@ -17,7 +17,7 @@ go get -d entgo.io/ent/cmd/ent In order to generate one or more schema templates, run `ent init` as follows: ```bash -go run -mod=mod entgo.io/ent/cmd/ent init User Pet +go run -mod=mod entgo.io/ent/cmd/ent new User Pet ``` `init` will create the 2 schemas (`user.go` and `pet.go`) under the `ent/schema` directory. diff --git a/doc/md/getting-started.mdx b/doc/md/getting-started.mdx index dc59bc8c4c..e9a987f561 100644 --- a/doc/md/getting-started.mdx +++ b/doc/md/getting-started.mdx @@ -32,7 +32,7 @@ go mod init entdemo Go to the root directory of your project, and run: ```console -go run -mod=mod entgo.io/ent/cmd/ent init User +go run -mod=mod entgo.io/ent/cmd/ent new User ``` The command above will generate the schema for `User` under `entdemo/ent/schema/` directory: @@ -264,7 +264,7 @@ Let's create 2 additional entities named `Car` and `Group` with a few fields. We to generate the initial schemas: ```console -go run -mod=mod entgo.io/ent/cmd/ent init Car Group +go run -mod=mod entgo.io/ent/cmd/ent new Car Group ``` And then we add the rest of the fields manually: diff --git a/doc/md/schema-def.md b/doc/md/schema-def.md index 9e6f7c3d71..4bd9c86740 100644 --- a/doc/md/schema-def.md +++ b/doc/md/schema-def.md @@ -55,7 +55,7 @@ Entity schemas are usually stored inside `ent/schema` directory under the root directory of your project, and can be generated by `entc` as follows: ```console -go run -mod=mod entgo.io/ent/cmd/ent init User Group +go run -mod=mod entgo.io/ent/cmd/ent new User Group ``` :::note diff --git a/doc/md/traversals.md b/doc/md/traversals.md index ac83834bd3..dcc62d65d5 100644 --- a/doc/md/traversals.md +++ b/doc/md/traversals.md @@ -11,7 +11,7 @@ For the purpose of the example, we'll generate the following graph: The first step is to generate the 3 schemas: `Pet`, `User`, `Group`. ```console -go run -mod=mod entgo.io/ent/cmd/ent init Pet User Group +go run -mod=mod entgo.io/ent/cmd/ent new Pet User Group ``` Add the necessary fields and edges for the schemas: diff --git a/doc/md/tutorial-grpc-setting-up.md b/doc/md/tutorial-grpc-setting-up.md index 1cd6a2786c..9a69c9277f 100644 --- a/doc/md/tutorial-grpc-setting-up.md +++ b/doc/md/tutorial-grpc-setting-up.md @@ -15,7 +15,7 @@ go mod init ent-grpc-example Next, we use `go run` to invoke the ent code generator to initialize a schema: ```console -go run -mod=mod entgo.io/ent/cmd/ent init User +go run -mod=mod entgo.io/ent/cmd/ent new User ``` Our directory should now look like: diff --git a/doc/md/tutorial-setup.md b/doc/md/tutorial-setup.md index 0d00067bcd..114790a5d0 100644 --- a/doc/md/tutorial-setup.md +++ b/doc/md/tutorial-setup.md @@ -29,7 +29,7 @@ go get -d entgo.io/ent/cmd/ent ``` ```console -go run -mod=mod entgo.io/ent/cmd/ent init Todo +go run -mod=mod entgo.io/ent/cmd/ent new Todo ``` After installing Ent and running `ent init`, your project directory should look like this: @@ -49,7 +49,7 @@ entity schemas. ## Code Generation -When we ran `ent init Todo` above, a schema named `Todo` was created in the `todo.go` file under the`todo/ent/schema/` directory: +When we ran `ent new Todo` above, a schema named `Todo` was created in the `todo.go` file under the`todo/ent/schema/` directory: ```go package schema diff --git a/doc/website/blog/2021-03-18-generating-a-grpc-server-with-ent.md b/doc/website/blog/2021-03-18-generating-a-grpc-server-with-ent.md index 3f4c004adc..2c6c5b85b3 100644 --- a/doc/website/blog/2021-03-18-generating-a-grpc-server-with-ent.md +++ b/doc/website/blog/2021-03-18-generating-a-grpc-server-with-ent.md @@ -29,7 +29,7 @@ go mod init ent-grpc-example Next we use `go run` to invoke the ent code generator to initialize a schema: ```console -go run -mod=mod entgo.io/ent/cmd/ent init User +go run -mod=mod entgo.io/ent/cmd/ent new User ``` Our directory should now look like: diff --git a/doc/website/blog/2021-07-29-generate-a-fully-working-go-crud-http-api-with-ent.md b/doc/website/blog/2021-07-29-generate-a-fully-working-go-crud-http-api-with-ent.md index 0cf3cd0ef6..989ceb0bf5 100644 --- a/doc/website/blog/2021-07-29-generate-a-fully-working-go-crud-http-api-with-ent.md +++ b/doc/website/blog/2021-07-29-generate-a-fully-working-go-crud-http-api-with-ent.md @@ -41,7 +41,7 @@ go mod init elk-example Invoke the ent code generator and create two schemas: User, Pet: ```shell -go run -mod=mod entgo.io/ent/cmd/ent init Pet User +go run -mod=mod entgo.io/ent/cmd/ent new Pet User ``` Your project should now look like this: diff --git a/doc/website/blog/2021-08-26-visualizing-your-data-graph-using-entviz.md b/doc/website/blog/2021-08-26-visualizing-your-data-graph-using-entviz.md index fe165b0f4c..cf24a7ddc6 100644 --- a/doc/website/blog/2021-08-26-visualizing-your-data-graph-using-entviz.md +++ b/doc/website/blog/2021-08-26-visualizing-your-data-graph-using-entviz.md @@ -84,7 +84,7 @@ Open the html file with your favorite browser to see the visualization Next, let's add another entity named Post, and see how our visualization changes: ```bash -ent init Post +ent new Post ``` ```go title="ent/schema/post.go" // Fields of the Post. diff --git a/doc/website/blog/2021-09-10-openapi-generator.md b/doc/website/blog/2021-09-10-openapi-generator.md index e46cc49b7c..5a3e7426fa 100644 --- a/doc/website/blog/2021-09-10-openapi-generator.md +++ b/doc/website/blog/2021-09-10-openapi-generator.md @@ -75,7 +75,7 @@ over to the [Setup Tutorial](https://entgo.io/docs/tutorial-setup/). The first step on our way to the OAS file is to create an Ent schema graph: ```shell -go run -mod=mod entgo.io/ent/cmd/ent init Fridge Compartment Item +go run -mod=mod entgo.io/ent/cmd/ent new Fridge Compartment Item ``` To demonstrate `elk`'s OAS generation capabilities, we will build together an example application. Suppose I have diff --git a/doc/website/blog/2021-10-11-generating-ent-schemas-from-existing-sql-databases.md b/doc/website/blog/2021-10-11-generating-ent-schemas-from-existing-sql-databases.md index 3591468e75..2b1335c02f 100644 --- a/doc/website/blog/2021-10-11-generating-ent-schemas-from-existing-sql-databases.md +++ b/doc/website/blog/2021-10-11-generating-ent-schemas-from-existing-sql-databases.md @@ -125,7 +125,7 @@ go mod init entimport-example Run Ent Init: ```shell -go run -mod=mod entgo.io/ent/cmd/ent init +go run -mod=mod entgo.io/ent/cmd/ent new ``` The project should look like this: diff --git a/doc/website/blog/2021-11-1-sync-to-external-data-systems-using-hooks.md b/doc/website/blog/2021-11-1-sync-to-external-data-systems-using-hooks.md index 5c7640d66e..a71055c29a 100644 --- a/doc/website/blog/2021-11-1-sync-to-external-data-systems-using-hooks.md +++ b/doc/website/blog/2021-11-1-sync-to-external-data-systems-using-hooks.md @@ -34,7 +34,7 @@ In our example, we are going to create a simple `User` schema with 2 immutable s `"avatar_url"`. Let's run the `ent init` command for creating a skeleton schema for our `User`: ```shell -go run entgo.io/ent/cmd/ent init User +go run entgo.io/ent/cmd/ent new User ``` Then, add the `name` and the `avatar_url` fields and run `go generate` to generate the assets. diff --git a/doc/website/blog/2022-01-04-serverless-graphql-using-aws.md b/doc/website/blog/2022-01-04-serverless-graphql-using-aws.md index 9e85d04fee..9652c6198c 100644 --- a/doc/website/blog/2022-01-04-serverless-graphql-using-aws.md +++ b/doc/website/blog/2022-01-04-serverless-graphql-using-aws.md @@ -166,7 +166,7 @@ go mod init entgo-aws-appsync Third, we create the `Todo` schema while pulling in the ent dependencies: ```console -go run -mod=mod entgo.io/ent/cmd/ent init Todo +go run -mod=mod entgo.io/ent/cmd/ent new Todo ``` and add the `title` field: diff --git a/doc/website/blog/2022-05-09-versioned-migrations-sum-file.md b/doc/website/blog/2022-05-09-versioned-migrations-sum-file.md index 9588523906..bb813645b7 100644 --- a/doc/website/blog/2022-05-09-versioned-migrations-sum-file.md +++ b/doc/website/blog/2022-05-09-versioned-migrations-sum-file.md @@ -94,7 +94,7 @@ mkdir ent-sum-file cd ent-sum-file go mod init ent-sum-file go install entgo.io/ent/cmd/ent@master -go run entgo.io/ent/cmd/ent init User +go run entgo.io/ent/cmd/ent new User sed -i -E 's|^//go(.*)$|//go\1 --feature sql/versioned-migration|' ent/generate.go go generate ./... docker run --rm --name atlas-sum --detach --env MYSQL_ROOT_PASSWORD=pass --env MYSQL_DATABASE=ent -p 3306:3306 mysql diff --git a/examples/README.md b/examples/README.md index 1f2ee3d70a..619ebd2325 100644 --- a/examples/README.md +++ b/examples/README.md @@ -22,7 +22,7 @@ For the purpose of the example, we'll generate the following graph: The first step is to generate the 3 schemas: `Pet`, `User`, `Group`. ```console -ent init Pet User Group +ent new Pet User Group ``` Add the necessary fields and edges for the schemas: