-
Notifications
You must be signed in to change notification settings - Fork 76
Expand file tree
/
Copy pathbatch_apply.go
More file actions
77 lines (58 loc) · 1.65 KB
/
Copy pathbatch_apply.go
File metadata and controls
77 lines (58 loc) · 1.65 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
package main
import (
"context"
"flag"
"fmt"
"github.com/sourcegraph/sourcegraph/lib/output"
"github.com/sourcegraph/src-cli/internal/batches/ui"
"github.com/sourcegraph/src-cli/internal/cmderrors"
)
func init() {
usage := `
'src batch apply' is used to apply a batch spec on a Sourcegraph instance,
creating or updating the described batch change if necessary.
Usage:
src batch apply -f FILE [command options]
Examples:
$ src batch apply -f batch.spec.yaml
$ src batch apply -f batch.spec.yaml -namespace myorg
`
flagSet := flag.NewFlagSet("apply", flag.ExitOnError)
flags := newBatchExecuteFlags(flagSet, batchDefaultCacheDir(), batchDefaultTempDirPrefix())
handler := func(args []string) error {
if err := flagSet.Parse(args); err != nil {
return err
}
if len(flagSet.Args()) != 0 {
return cmderrors.Usage("additional arguments not allowed")
}
ctx, cancel := contextCancelOnInterrupt(context.Background())
defer cancel()
var execUI ui.ExecUI
if flags.textOnly {
execUI = &ui.JSONLines{}
} else {
out := output.NewOutput(flagSet.Output(), output.OutputOpts{Verbose: *verbose})
execUI = &ui.TUI{Out: out}
}
err := executeBatchSpec(ctx, executeBatchSpecOpts{
flags: flags,
client: cfg.apiClient(flags.api, flagSet.Output()),
applyBatchSpec: true,
ui: execUI,
})
if 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)
},
})
}