forked from plouc/go-gitlab-client
/
rm_project_star_cmd.go
56 lines (45 loc) · 1.15 KB
/
rm_project_star_cmd.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
package cmd
import (
"fmt"
"github.com/fatih/color"
out "github.com/plouc/go-gitlab-client/cli/output"
"github.com/spf13/cobra"
)
func init() {
rmCmd.AddCommand(rmProjectStarCmd)
}
var rmProjectStarCmd = &cobra.Command{
Use: resourceCmd("project-star", "project"),
Aliases: []string{"ps"},
Short: "Unstars a given project",
RunE: func(cmd *cobra.Command, args []string) error {
ids, err := config.aliasIdsOrArgs(currentAlias, "project", args)
if err != nil {
return err
}
color.Yellow("Unstaring project (project id: %s)…", ids["project_id"])
confirmed := confirmAction(
fmt.Sprintf("Are you sure you want to unstar project %s?", ids["project_id"]),
"aborted project star removal",
autoConfirmRemoval,
)
if !confirmed {
return nil
}
loader.Start()
project, meta, err := client.UnstarProject(ids["project_id"])
loader.Stop()
if err != nil {
fmt.Println(err.Error())
return err
}
if meta.StatusCode == 304 {
color.Red("\n You didn't stared project %s!", ids["project_id"])
}
if project != nil {
out.Project(output, outputFormat, project, false)
}
printMeta(meta, false)
return nil
},
}