瀏覽代碼

feat(cli): improve error handling for missing plugin dir

bergquist 9 年之前
父節點
當前提交
f5bb2b11e5
共有 2 個文件被更改,包括 10 次插入1 次删除
  1. 1 0
      pkg/cmd/grafana-cli/commands/commands.go
  2. 9 1
      pkg/cmd/grafana-cli/commands/install_command.go

+ 1 - 0
pkg/cmd/grafana-cli/commands/commands.go

@@ -11,6 +11,7 @@ func runCommand(command func(commandLine CommandLine) error) func(context *cli.C
 
 		cmd := &contextCommandLine{context}
 		if err := command(cmd); err != nil {
+			log.Error("\nError: ")
 			log.Errorf("%s\n\n", err)
 
 			cmd.ShowHelp()

+ 9 - 1
pkg/cmd/grafana-cli/commands/install_command.go

@@ -28,7 +28,15 @@ func validateInput(c CommandLine, pluginFolder string) error {
 	}
 
 	fileInfo, err := os.Stat(pluginDir)
-	if err != nil && !fileInfo.IsDir() {
+	if err != nil {
+		if err = os.MkdirAll(pluginDir, os.ModePerm); err != nil {
+			return errors.New("path is not a directory")
+		}
+
+		return nil
+	}
+
+	if !fileInfo.IsDir() {
 		return errors.New("path is not a directory")
 	}