-
Notifications
You must be signed in to change notification settings - Fork 195
Expand file tree
/
Copy pathvalidate.go
More file actions
82 lines (66 loc) · 2.03 KB
/
Copy pathvalidate.go
File metadata and controls
82 lines (66 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package apps
import (
"errors"
"fmt"
"os"
"github.com/databricks/cli/libs/apps/validation"
"github.com/databricks/cli/libs/cmdio"
"github.com/spf13/cobra"
)
func newValidateCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "validate",
Short: "Validate a Databricks App project",
Long: `Validate a Databricks App project by running build, typecheck, and lint checks.
This command detects the project type and runs the appropriate validation:
- Node.js projects (package.json): runs npm install, build, typecheck, lint, and tests
Examples:
# Validate the current directory
databricks apps validate
# Validate a specific directory
databricks apps validate --path ./my-app
# Run a quick validation without tests
databricks apps validate --skip-tests`,
RunE: func(cmd *cobra.Command, args []string) error {
return runValidate(cmd)
},
}
cmd.Flags().String("path", "", "Path to the project directory (defaults to current directory)")
cmd.Flags().Bool("skip-tests", false, "Skip running tests for faster validation")
return cmd
}
func runValidate(cmd *cobra.Command) error {
ctx := cmd.Context()
// Get project path
projectPath, _ := cmd.Flags().GetString("path")
if projectPath == "" {
var err error
projectPath, err = os.Getwd()
if err != nil {
return fmt.Errorf("failed to get working directory: %w", err)
}
}
// Get validation options
skipTests, _ := cmd.Flags().GetBool("skip-tests")
opts := validation.ValidateOptions{
SkipTests: skipTests,
}
// Get validator for project type
validator := validation.GetProjectValidator(projectPath)
if validator == nil {
return errors.New("no supported project type detected (looking for package.json)")
}
// Run validation
result, err := validator.Validate(ctx, projectPath, opts)
if err != nil {
return fmt.Errorf("validation error: %w", err)
}
if !result.Success {
if result.Details != nil {
cmdio.LogString(ctx, result.Details.Error())
}
return errors.New("validation failed")
}
cmdio.LogString(ctx, "✅ "+result.Message)
return nil
}