/
root.go
67 lines (54 loc) · 1.5 KB
/
root.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
package cmd
import (
"fmt"
"os"
config "github.com/hasanhakkaev/gitlab-runner-cleaner/internal/config"
"github.com/hasanhakkaev/gitlab-runner-cleaner/internal/gitlab"
"github.com/olekukonko/tablewriter"
)
// Execute is the entry point for the cleaner command
func Execute() {
cfg, err := config.Load()
if err != nil {
fmt.Println(err)
}
runners, err := gitlab.GetRunners(cfg.RunnerStatus, 1)
if err != nil {
fmt.Println(err)
}
if runners == nil {
fmt.Println("No runners found")
os.Exit(0)
}
fmt.Printf("Runners found:%d\n", len(runners))
fmt.Printf("RunnerStatus: %s\n", cfg.RunnerStatus)
fmt.Printf("DryRun: %v\n", cfg.DryRun)
if cfg.DryRun {
fmt.Println("Dry run enabled.. Printing runners to be deleted")
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Name", "Status"})
for _, runner := range runners {
runnerInfo := []string{
fmt.Sprintf("%d", runner.ID), runner.Description, runner.Status}
table.Append(runnerInfo)
}
table.Render()
} else {
fmt.Println("Dry run disabled.. Deleting runners..")
table := tablewriter.NewWriter(os.Stdout)
table.SetHeader([]string{"ID", "Name", "Status"})
for _, runner := range runners {
runnerInfo := []string{
fmt.Sprintf("%d", runner.ID), runner.Description, runner.Status}
table.Append(runnerInfo)
}
table.Render()
for _, runner := range runners {
err := gitlab.DeleteRunner(runner.ID)
if err != nil {
fmt.Println(err)
}
}
fmt.Println("Runners have been deleted!")
}
}