-
Notifications
You must be signed in to change notification settings - Fork 3.1k
/
lint.go
53 lines (45 loc) · 1.29 KB
/
lint.go
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
package template
import (
"fmt"
"os"
"github.com/argoproj/pkg/errors"
"github.com/spf13/cobra"
"github.com/argoproj/argo-workflows/v3/cmd/argo/commands/client"
"github.com/argoproj/argo-workflows/v3/cmd/argo/lint"
)
func NewLintCommand() *cobra.Command {
var (
strict bool
format string
)
command := &cobra.Command{
Use: "lint (DIRECTORY | FILE1 FILE2 FILE3...)",
Short: "validate a file or directory of workflow template manifests",
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
cmd.HelpFunc()(cmd, args)
os.Exit(1)
}
ctx, apiClient := client.NewAPIClient()
fmtr, err := lint.GetFormatter(format)
errors.CheckError(err)
res, err := lint.Lint(ctx, &lint.LintOptions{
ServiceClients: lint.ServiceClients{
WorkflowTemplatesClient: apiClient.NewWorkflowTemplateServiceClient(),
},
Files: args,
Strict: strict,
DefaultNamespace: client.Namespace(),
Formatter: fmtr,
})
errors.CheckError(err)
fmt.Print(res.Msg())
if !res.Success {
os.Exit(1)
}
},
}
command.Flags().StringVar(&format, "format", "pretty", "Linting results output format. One of: pretty|simple")
command.Flags().BoolVar(&strict, "strict", true, "perform strict workflow validation")
return command
}