forked from sourcegraph/src-cli
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbatch_validate.go
More file actions
99 lines (77 loc) · 2.2 KB
/
batch_validate.go
File metadata and controls
99 lines (77 loc) · 2.2 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"context"
"flag"
"fmt"
"github.com/sourcegraph/sourcegraph/lib/output"
"github.com/sourcegraph/src-cli/internal/api"
"github.com/sourcegraph/src-cli/internal/batches/service"
"github.com/sourcegraph/src-cli/internal/batches/ui"
"github.com/sourcegraph/src-cli/internal/cmderrors"
)
func init() {
usage := `
'src batch validate' validates the given batch spec.
Usage:
src batch validate [-f] FILE
Examples:
$ src batch validate batch.spec.yaml
$ src batch validate -f batch.spec.yaml
`
flagSet := flag.NewFlagSet("validate", flag.ExitOnError)
apiFlags := api.NewFlags(flagSet)
fileFlag := flagSet.String("f", "", "The batch spec file to read, or - to read from standard input.")
var (
allowUnsupported bool
allowIgnored bool
)
flagSet.BoolVar(
&allowUnsupported, "allow-unsupported", false,
"Allow unsupported code hosts.",
)
flagSet.BoolVar(
&allowIgnored, "force-override-ignore", false,
"Do not ignore repositories that have a .batchignore file.",
)
handler := func(args []string) error {
ctx := context.Background()
if err := flagSet.Parse(args); err != nil {
return err
}
if len(flagSet.Args()) != 0 {
return cmderrors.Usage("additional arguments not allowed")
}
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
ui := &ui.TUI{Out: out}
svc := service.New(&service.Opts{
Client: cfg.apiClient(apiFlags, flagSet.Output()),
})
ffs, err := svc.DetermineFeatureFlags(ctx)
if err != nil {
return err
}
if err := validateSourcegraphVersionConstraint(ctx, ffs); err != nil {
ui.ExecutionError(err)
return err
}
file, err := getBatchSpecFile(flagSet, fileFlag)
if err != nil {
return err
}
if _, _, _, err := parseBatchSpec(ctx, file, svc); err != nil {
ui.ParsingBatchSpecFailure(err)
return err
}
out.WriteLine(output.Line("\u2705", output.StyleSuccess, "Batch spec successfully validated."))
return nil
}
batchCommands = append(batchCommands, &command{
flagSet: flagSet,
handler: handler,
usageFunc: func() {
fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src batch %s':\n", flagSet.Name())
flagSet.PrintDefaults()
fmt.Println(usage)
},
})
}