123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816 |
- package main
- import (
- "fmt"
- "os"
- "runtime"
- "github.com/logrusorgru/aurora"
- "github.com/urfave/cli"
- "github.com/zeromicro/go-zero/core/load"
- "github.com/zeromicro/go-zero/core/logx"
- "github.com/zeromicro/go-zero/tools/goctl/api/apigen"
- "github.com/zeromicro/go-zero/tools/goctl/api/dartgen"
- "github.com/zeromicro/go-zero/tools/goctl/api/docgen"
- "github.com/zeromicro/go-zero/tools/goctl/api/format"
- "github.com/zeromicro/go-zero/tools/goctl/api/gogen"
- "github.com/zeromicro/go-zero/tools/goctl/api/javagen"
- "github.com/zeromicro/go-zero/tools/goctl/api/ktgen"
- "github.com/zeromicro/go-zero/tools/goctl/api/new"
- "github.com/zeromicro/go-zero/tools/goctl/api/tsgen"
- "github.com/zeromicro/go-zero/tools/goctl/api/validate"
- "github.com/zeromicro/go-zero/tools/goctl/bug"
- "github.com/zeromicro/go-zero/tools/goctl/docker"
- "github.com/zeromicro/go-zero/tools/goctl/internal/errorx"
- "github.com/zeromicro/go-zero/tools/goctl/internal/version"
- "github.com/zeromicro/go-zero/tools/goctl/kube"
- "github.com/zeromicro/go-zero/tools/goctl/migrate"
- "github.com/zeromicro/go-zero/tools/goctl/model/mongo"
- model "github.com/zeromicro/go-zero/tools/goctl/model/sql/command"
- "github.com/zeromicro/go-zero/tools/goctl/plugin"
- rpc "github.com/zeromicro/go-zero/tools/goctl/rpc/cli"
- "github.com/zeromicro/go-zero/tools/goctl/tpl"
- "github.com/zeromicro/go-zero/tools/goctl/upgrade"
- )
- const codeFailure = 1
- var commands = []cli.Command{
- {
- Name: "bug",
- Usage: "report a bug",
- Action: bug.Action,
- },
- {
- Name: "upgrade",
- Usage: "upgrade goctl to latest version",
- Action: upgrade.Upgrade,
- },
- {
- Name: "migrate",
- Usage: "migrate from tal-tech to zeromicro",
- Description: "migrate is a transition command to help users migrate their projects from tal-tech to zeromicro version",
- Action: migrate.Migrate,
- Flags: []cli.Flag{
- cli.BoolFlag{
- Name: "verbose, v",
- Usage: "verbose enables extra logging",
- },
- cli.StringFlag{
- Name: "version",
- Usage: "the target release version of github.com/zeromicro/go-zero to migrate",
- },
- },
- },
- {
- Name: "api",
- Usage: "generate api related files",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "o",
- Usage: "the output api file",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: apigen.ApiCommand,
- Subcommands: []cli.Command{
- {
- Name: "new",
- Usage: "fast create api service",
- Action: new.CreateServiceCommand,
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/blob/master/tools/goctl/config/readme.md]",
- },
- },
- },
- {
- Name: "format",
- Usage: "format api files",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the format target dir",
- },
- cli.BoolFlag{
- Name: "iu",
- Usage: "ignore update",
- },
- cli.BoolFlag{
- Name: "stdin",
- Usage: "use stdin to input api doc content, press \"ctrl + d\" to send EOF",
- },
- },
- Action: format.GoFormatApi,
- },
- {
- Name: "validate",
- Usage: "validate api file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "api",
- Usage: "validate target api file",
- },
- },
- Action: validate.GoValidateApi,
- },
- {
- Name: "doc",
- Usage: "generate doc files",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "o",
- Required: false,
- Usage: "the output markdown directory",
- },
- },
- Action: docgen.DocCommand,
- },
- {
- Name: "go",
- Usage: "generate go files for provided api in yaml file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "api",
- Usage: "the api file",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: gogen.GoCommand,
- },
- {
- Name: "java",
- Usage: "generate java files for provided api in api file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "api",
- Usage: "the api file",
- },
- },
- Action: javagen.JavaCommand,
- },
- {
- Name: "ts",
- Usage: "generate ts files for provided api in api file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "api",
- Usage: "the api file",
- },
- cli.StringFlag{
- Name: "webapi",
- Usage: "the web api file path",
- },
- cli.StringFlag{
- Name: "caller",
- Usage: "the web api caller",
- },
- cli.BoolFlag{
- Name: "unwrap",
- Usage: "unwrap the webapi caller for import",
- },
- },
- Action: tsgen.TsCommand,
- },
- {
- Name: "dart",
- Usage: "generate dart files for provided api in api file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "api",
- Usage: "the api file",
- },
- },
- Action: dartgen.DartCommand,
- },
- {
- Name: "kt",
- Usage: "generate kotlin code for provided api file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "dir",
- Usage: "the target directory",
- },
- cli.StringFlag{
- Name: "api",
- Usage: "the api file",
- },
- cli.StringFlag{
- Name: "pkg",
- Usage: "define package name for kotlin file",
- },
- },
- Action: ktgen.KtCommand,
- },
- {
- Name: "plugin",
- Usage: "custom file generator",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "plugin, p",
- Usage: "the plugin file",
- },
- cli.StringFlag{
- Name: "dir",
- Usage: "the target directory",
- },
- cli.StringFlag{
- Name: "api",
- Usage: "the api file",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- },
- Action: plugin.PluginCommand,
- },
- },
- },
- {
- Name: "docker",
- Usage: "generate Dockerfile",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "go",
- Usage: "the file that contains main function",
- },
- cli.IntFlag{
- Name: "port",
- Usage: "the port to expose, default none",
- Value: 0,
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- cli.StringFlag{
- Name: "version",
- Usage: "the goctl builder golang image version",
- },
- },
- Action: docker.DockerCommand,
- },
- {
- Name: "kube",
- Usage: "generate kubernetes files",
- Subcommands: []cli.Command{
- {
- Name: "deploy",
- Usage: "generate deployment yaml file",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "name",
- Usage: "the name of deployment",
- Required: true,
- },
- cli.StringFlag{
- Name: "namespace",
- Usage: "the namespace of deployment",
- Required: true,
- },
- cli.StringFlag{
- Name: "image",
- Usage: "the docker image of deployment",
- Required: true,
- },
- cli.StringFlag{
- Name: "secret",
- Usage: "the secret to image pull from registry",
- },
- cli.IntFlag{
- Name: "requestCpu",
- Usage: "the request cpu to deploy",
- Value: 500,
- },
- cli.IntFlag{
- Name: "requestMem",
- Usage: "the request memory to deploy",
- Value: 512,
- },
- cli.IntFlag{
- Name: "limitCpu",
- Usage: "the limit cpu to deploy",
- Value: 1000,
- },
- cli.IntFlag{
- Name: "limitMem",
- Usage: "the limit memory to deploy",
- Value: 1024,
- },
- cli.StringFlag{
- Name: "o",
- Usage: "the output yaml file",
- Required: true,
- },
- cli.IntFlag{
- Name: "replicas",
- Usage: "the number of replicas to deploy",
- Value: 3,
- },
- cli.IntFlag{
- Name: "revisions",
- Usage: "the number of revision history to limit",
- Value: 5,
- },
- cli.IntFlag{
- Name: "port",
- Usage: "the port of the deployment to listen on pod",
- Required: true,
- },
- cli.IntFlag{
- Name: "nodePort",
- Usage: "the nodePort of the deployment to expose",
- Value: 0,
- },
- cli.IntFlag{
- Name: "minReplicas",
- Usage: "the min replicas to deploy",
- Value: 3,
- },
- cli.IntFlag{
- Name: "maxReplicas",
- Usage: "the max replicas of deploy",
- Value: 10,
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: kube.DeploymentCommand,
- },
- },
- },
- {
- Name: "rpc",
- Usage: "generate rpc code",
- Subcommands: []cli.Command{
- {
- Name: "new",
- Usage: `generate rpc demo service`,
- Description: aurora.Yellow(`deprecated: zrpc code generation use "goctl rpc protoc" instead, for the details see "goctl rpc protoc --help"`).String(),
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.BoolFlag{
- Name: "idea",
- Usage: "whether the command execution environment is from idea plugin. [optional]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: rpc.RPCNew,
- },
- {
- Name: "template",
- Usage: `generate proto template`,
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "out, o",
- Usage: "the target path of proto",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time," +
- " if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: rpc.RPCTemplate,
- },
- {
- Name: "protoc",
- Usage: "generate grpc code",
- UsageText: `example: goctl rpc protoc xx.proto --go_out=./pb --go-grpc=./pb --zrpc_out=.`,
- Description: "for details, see https://go-zero.dev/cn/goctl-rpc.html",
- Action: rpc.ZRPC,
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "go_out",
- Hidden: true,
- },
- cli.StringFlag{
- Name: "go-grpc_out",
- Hidden: true,
- },
- cli.StringFlag{
- Name: "go_opt",
- Hidden: true,
- },
- cli.StringFlag{
- Name: "go-grpc_opt",
- Hidden: true,
- },
- cli.StringFlag{
- Name: "zrpc_out",
- Usage: "the zrpc output directory",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- },
- {
- Name: "proto",
- Usage: `generate rpc from proto`,
- Description: aurora.Yellow(`deprecated: zrpc code generation use "goctl rpc protoc" instead, for the details see "goctl rpc protoc --help"`).String(),
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "src, s",
- Usage: "the file path of the proto source file",
- },
- cli.StringSliceFlag{
- Name: "proto_path, I",
- Usage: `native command of protoc, specify the directory in which to search for imports. [optional]`,
- },
- cli.StringSliceFlag{
- Name: "go_opt",
- Usage: `native command of protoc-gen-go, specify the mapping from proto to go, eg --go_opt=proto_import=go_package_import. [optional]`,
- },
- cli.StringFlag{
- Name: "dir, d",
- Usage: `the target path of the code`,
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.BoolFlag{
- Name: "idea",
- Usage: "whether the command execution environment is from idea plugin. [optional]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: rpc.RPC,
- },
- },
- },
- {
- Name: "model",
- Usage: "generate model code",
- Subcommands: []cli.Command{
- {
- Name: "mysql",
- Usage: `generate mysql model`,
- Subcommands: []cli.Command{
- {
- Name: "ddl",
- Usage: `generate mysql model from ddl`,
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "src, s",
- Usage: "the path or path globbing patterns of the ddl",
- },
- cli.StringFlag{
- Name: "dir, d",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.BoolFlag{
- Name: "cache, c",
- Usage: "generate code with cache [optional]",
- },
- cli.BoolFlag{
- Name: "idea",
- Usage: "for idea plugin [optional]",
- },
- cli.StringFlag{
- Name: "database, db",
- Usage: "the name of database [optional]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: model.MysqlDDL,
- },
- {
- Name: "datasource",
- Usage: `generate model from datasource`,
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "url",
- Usage: `the data source of database,like "root:password@tcp(127.0.0.1:3306)/database"`,
- },
- cli.StringFlag{
- Name: "table, t",
- Usage: `the table or table globbing patterns in the database`,
- },
- cli.BoolFlag{
- Name: "cache, c",
- Usage: "generate code with cache [optional]",
- },
- cli.StringFlag{
- Name: "dir, d",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.BoolFlag{
- Name: "idea",
- Usage: "for idea plugin [optional]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: model.MySqlDataSource,
- },
- },
- },
- {
- Name: "pg",
- Usage: `generate postgresql model`,
- Subcommands: []cli.Command{
- {
- Name: "datasource",
- Usage: `generate model from datasource`,
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "url",
- Usage: `the data source of database,like "postgres://root:password@127.0.0.1:54332/database?sslmode=disable"`,
- },
- cli.StringFlag{
- Name: "table, t",
- Usage: `the table or table globbing patterns in the database`,
- },
- cli.StringFlag{
- Name: "schema, s",
- Usage: `the table schema, default is [public]`,
- },
- cli.BoolFlag{
- Name: "cache, c",
- Usage: "generate code with cache [optional]",
- },
- cli.StringFlag{
- Name: "dir, d",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.BoolFlag{
- Name: "idea",
- Usage: "for idea plugin [optional]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: model.PostgreSqlDataSource,
- },
- },
- },
- {
- Name: "mongo",
- Usage: `generate mongo model`,
- Flags: []cli.Flag{
- cli.StringSliceFlag{
- Name: "type, t",
- Usage: "specified model type name",
- },
- cli.BoolFlag{
- Name: "cache, c",
- Usage: "generate code with cache [optional]",
- },
- cli.StringFlag{
- Name: "dir, d",
- Usage: "the target dir",
- },
- cli.StringFlag{
- Name: "style",
- Usage: "the file naming format, see [https://github.com/zeromicro/go-zero/tree/master/tools/goctl/config/readme.md]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template, --home and --remote cannot be set at the same time," +
- " if they are, --remote has higher priority",
- },
- cli.StringFlag{
- Name: "remote",
- Usage: "the remote git repo of the template, --home and --remote cannot be set at the same time, " +
- "if they are, --remote has higher priority\n\tThe git repo directory must be consistent with the " +
- "https://github.com/zeromicro/go-zero-template directory structure",
- },
- },
- Action: mongo.Action,
- },
- },
- },
- {
- Name: "template",
- Usage: "template operation",
- Subcommands: []cli.Command{
- {
- Name: "init",
- Usage: "initialize the all templates(force update)",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template",
- },
- },
- Action: tpl.GenTemplates,
- },
- {
- Name: "clean",
- Usage: "clean the all cache templates",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template",
- },
- },
- Action: tpl.CleanTemplates,
- },
- {
- Name: "update",
- Usage: "update template of the target category to the latest",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "category,c",
- Usage: "the category of template, enum [api,rpc,model,docker,kube]",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template",
- },
- },
- Action: tpl.UpdateTemplates,
- },
- {
- Name: "revert",
- Usage: "revert the target template to the latest",
- Flags: []cli.Flag{
- cli.StringFlag{
- Name: "category,c",
- Usage: "the category of template, enum [api,rpc,model,docker,kube]",
- },
- cli.StringFlag{
- Name: "name,n",
- Usage: "the target file name of template",
- },
- cli.StringFlag{
- Name: "home",
- Usage: "the goctl home path of the template",
- },
- },
- Action: tpl.RevertTemplates,
- },
- },
- },
- }
- func main() {
- logx.Disable()
- load.Disable()
- app := cli.NewApp()
- app.Usage = "a cli tool to generate code"
- app.Version = fmt.Sprintf("%s %s/%s", version.BuildVersion, runtime.GOOS, runtime.GOARCH)
- app.Commands = commands
- // cli already print error messages
- if err := app.Run(os.Args); err != nil {
- fmt.Println(aurora.Red(errorx.Wrap(err).Error()))
- os.Exit(codeFailure)
- }
- }
|