forked from plouc/go-gitlab-client
/
add_project_var.go
43 lines (34 loc) · 917 Bytes
/
add_project_var.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
package cmd
import (
"github.com/fatih/color"
out "github.com/plouc/go-gitlab-client/cli/output"
"github.com/spf13/cobra"
)
func init() {
addCmd.AddCommand(addProjectVarCmd)
}
var addProjectVarCmd = &cobra.Command{
Use: resourceCmd("project-var", "project"),
Aliases: []string{"pv"},
Short: "Create a new project variable",
RunE: func(cmd *cobra.Command, args []string) error {
ids, err := config.aliasIdsOrArgs(currentAlias, "project", args)
if err != nil {
return err
}
color.Yellow("Creating variable for project (project id: %s)…", ids["project_id"])
variable, err := promptVariable()
if err != nil {
return err
}
loader.Start()
createdVariable, meta, err := client.AddProjectVariable(ids["project_id"], variable)
loader.Stop()
if err != nil {
return err
}
out.Variable(output, outputFormat, createdVariable)
printMeta(meta, false)
return nil
},
}