Prechádzať zdrojové kódy

Mkdir if not exists (#1659)

Co-authored-by: anqiansong <anqiansong@bytedance.com>
anqiansong 3 rokov pred
rodič
commit
448029aa4b
1 zmenil súbory, kde vykonal 16 pridanie a 6 odobranie
  1. 16 6
      tools/goctl/rpc/cli/zrpc.go

+ 16 - 6
tools/goctl/rpc/cli/zrpc.go

@@ -20,11 +20,6 @@ var (
 	errMultiInput        = errors.New("ZRPC: only one source is expected")
 	errMultiInput        = errors.New("ZRPC: only one source is expected")
 )
 )
 
 
-const (
-	optImport         = "import"
-	optSourceRelative = "source_relative"
-)
-
 // ZRPC generates grpc code directly by protoc and generates
 // ZRPC generates grpc code directly by protoc and generates
 // zrpc code by goctl.
 // zrpc code by goctl.
 func ZRPC(c *cli.Context) error {
 func ZRPC(c *cli.Context) error {
@@ -61,7 +56,22 @@ func ZRPC(c *cli.Context) error {
 	if len(zrpcOut) == 0 {
 	if len(zrpcOut) == 0 {
 		return errInvalidZrpcOutput
 		return errInvalidZrpcOutput
 	}
 	}
-
+	goOutAbs, err := filepath.Abs(goOut)
+	if err != nil {
+		return err
+	}
+	grpcOutAbs, err := filepath.Abs(grpcOut)
+	if err != nil {
+		return err
+	}
+	err = pathx.MkdirIfNotExist(goOutAbs)
+	if err != nil {
+		return err
+	}
+	err = pathx.MkdirIfNotExist(grpcOutAbs)
+	if err != nil {
+		return err
+	}
 	if len(remote) > 0 {
 	if len(remote) > 0 {
 		repo, _ := util.CloneIntoGitHome(remote, branch)
 		repo, _ := util.CloneIntoGitHome(remote, branch)
 		if len(repo) > 0 {
 		if len(repo) > 0 {