-
Notifications
You must be signed in to change notification settings - Fork 56
/
batch_preview.go
68 lines (51 loc) · 1.42 KB
/
batch_preview.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package main
import (
"context"
"flag"
"fmt"
"github.com/sourcegraph/src-cli/internal/cmderrors"
)
func init() {
usage := `
'src batch preview' executes the steps in a batch spec and uploads it to a
Sourcegraph instance, ready to be previewed and applied.
Usage:
src batch preview [command options] [-f FILE]
src batch preview [command options] FILE
Examples:
$ src batch preview -f batch.spec.yaml
$ src batch preview batch.spec.yaml
`
flagSet := flag.NewFlagSet("preview", flag.ExitOnError)
flags := newBatchExecuteFlags(flagSet, batchDefaultCacheDir(), batchDefaultTempDirPrefix())
handler := func(args []string) error {
if err := flagSet.Parse(args); err != nil {
return err
}
file, err := getBatchSpecFile(flagSet, &flags.file)
if err != nil {
return err
}
ctx, cancel := contextCancelOnInterrupt(context.Background())
defer cancel()
if err = executeBatchSpec(ctx, executeBatchSpecOpts{
flags: flags,
client: cfg.apiClient(flags.api, flagSet.Output()),
file: file,
// Do not apply the uploaded batch spec
applyBatchSpec: false,
}); err != nil {
return cmderrors.ExitCode(1, nil)
}
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)
},
})
}