From 2ccf15a048a6d722d5643a434940dfacefbbccf3 Mon Sep 17 00:00:00 2001 From: Cluas Date: Tue, 13 Apr 2021 14:03:20 +0800 Subject: [PATCH] proto/add: avoid panic when using non-hierarchical path (#829) --- cmd/kratos/internal/proto/add/add.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/kratos/internal/proto/add/add.go b/cmd/kratos/internal/proto/add/add.go index 4caafe932..c658aba27 100644 --- a/cmd/kratos/internal/proto/add/add.go +++ b/cmd/kratos/internal/proto/add/add.go @@ -21,6 +21,10 @@ func run(cmd *cobra.Command, args []string) { // kratos add helloworld/v1/helloworld.proto input := args[0] n := strings.LastIndex(input, "/") + if n == -1 { + fmt.Println("The proto path needs to be hierarchical.") + return + } path := input[:n] fileName := input[n+1:] pkgName := strings.ReplaceAll(path, "/", ".")