forked from vmware-archive/fly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_pipeline.go
53 lines (42 loc) · 1.87 KB
/
set_pipeline.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 commands
import (
"github.com/concourse/atc"
"github.com/concourse/fly/commands/internal/flaghelpers"
"github.com/concourse/fly/commands/internal/setpipelinehelpers"
"github.com/concourse/fly/rc"
)
type SetPipelineCommand struct {
SkipInteractive bool `short:"n" long:"non-interactive" description:"Skips interactions, uses default values"`
Pipeline flaghelpers.PipelineFlag `short:"p" long:"pipeline" required:"true" description:"Pipeline to configure"`
Config atc.PathFlag `short:"c" long:"config" required:"true" description:"Pipeline configuration file"`
Var []flaghelpers.VariablePairFlag `short:"v" long:"var" value-name:"[NAME=STRING]" description:"Specify a string value to set for a variable in the pipeline"`
YAMLVar []flaghelpers.YAMLVariablePairFlag `short:"y" long:"yaml-var" value-name:"[NAME=YAML]" description:"Specify a YAML value to set for a variable in the pipeline"`
VarsFrom []atc.PathFlag `short:"l" long:"load-vars-from" description:"Variable flag that can be used for filling in template values in configuration from a YAML file"`
}
func (command *SetPipelineCommand) Validate() error {
return command.Pipeline.Validate()
}
func (command *SetPipelineCommand) Execute(args []string) error {
err := command.Validate()
if err != nil {
return err
}
configPath := command.Config
templateVariablesFiles := command.VarsFrom
pipelineName := string(command.Pipeline)
target, err := rc.LoadTarget(Fly.Target, Fly.Verbose)
if err != nil {
return err
}
err = target.Validate()
if err != nil {
return err
}
atcConfig := setpipelinehelpers.ATCConfig{
Team: target.Team(),
PipelineName: pipelineName,
Target: target.Client().URL(),
SkipInteraction: command.SkipInteractive,
}
return atcConfig.Set(configPath, command.Var, command.YAMLVar, templateVariablesFiles)
}